1 
2 //
3 // This source file is part of appleseed.
4 // Visit https://appleseedhq.net/ for additional information and resources.
5 //
6 // This software is released under the MIT license.
7 //
8 // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
9 // Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 // THE SOFTWARE.
28 //
29 
30 // Interface header.
31 #include "entityeditorwindow.h"
32 
33 // UI definition header.
34 #include "ui_entityeditorwindow.h"
35 
36 // appleseed.studio headers.
37 #include "utility/miscellaneous.h"
38 
39 // Qt headers.
40 #include <QDialogButtonBox>
41 #include <QShortcut>
42 #include <QString>
43 #include <Qt>
44 
45 // Standard headers.
46 #include <utility>
47 
48 using namespace foundation;
49 using namespace renderer;
50 using namespace std;
51 
52 namespace appleseed {
53 namespace studio {
54 
EntityEditorWindow(QWidget * parent,const string & window_title,const Project & project,ParamArray & settings,unique_ptr<EntityEditor::IFormFactory> form_factory,unique_ptr<EntityEditor::IEntityBrowser> entity_browser,unique_ptr<CustomEntityUI> custom_entity_ui,const Dictionary & values)55 EntityEditorWindow::EntityEditorWindow(
56     QWidget*                                    parent,
57     const string&                               window_title,
58     const Project&                              project,
59     ParamArray&                                 settings,
60     unique_ptr<EntityEditor::IFormFactory>      form_factory,
61     unique_ptr<EntityEditor::IEntityBrowser>    entity_browser,
62     unique_ptr<CustomEntityUI>                  custom_entity_ui,
63     const Dictionary&                           values)
64   : WindowBase(parent, "entity_editor_window")
65   , m_ui(new Ui::EntityEditorWindow())
66 {
67     m_ui->setupUi(this);
68 
69     setWindowTitle(QString::fromStdString(window_title));
70     setWindowFlags(Qt::Tool);
71     setAttribute(Qt::WA_DeleteOnClose);
72 
73     m_entity_editor.reset(
74         new EntityEditor(
75             m_ui->scrollarea_contents,
76             project,
77             settings,
78             std::move(form_factory),
79             std::move(entity_browser),
80             std::move(custom_entity_ui),
81             values));
82 
83     m_initial_values = m_entity_editor->get_values();
84 
85     create_connections();
86 
87     WindowBase::load_settings();
88 }
89 
~EntityEditorWindow()90 EntityEditorWindow::~EntityEditorWindow()
91 {
92     delete m_ui;
93 }
94 
create_connections()95 void EntityEditorWindow::create_connections()
96 {
97     connect(
98         m_entity_editor.get(), SIGNAL(signal_applied(foundation::Dictionary)),
99         SIGNAL(signal_applied(foundation::Dictionary)));
100 
101     connect(m_ui->buttonbox, SIGNAL(accepted()), SLOT(slot_accept()));
102     connect(m_ui->buttonbox, SIGNAL(rejected()), SLOT(slot_cancel()));
103 
104     connect(
105         create_window_local_shortcut(this, QKeySequence("Ctrl+Return")), SIGNAL(activated()),
106         SLOT(slot_accept()));
107     connect(
108         create_window_local_shortcut(this, QKeySequence("Ctrl+Enter")), SIGNAL(activated()),
109         SLOT(slot_accept()));
110 
111     connect(
112         create_window_local_shortcut(this, QKeySequence(Qt::Key_Escape)), SIGNAL(activated()),
113         SLOT(slot_cancel()));
114 }
115 
slot_accept()116 void EntityEditorWindow::slot_accept()
117 {
118     emit signal_accepted(m_entity_editor->get_values());
119 
120     close();
121 }
122 
slot_cancel()123 void EntityEditorWindow::slot_cancel()
124 {
125     if (m_initial_values != m_entity_editor->get_values())
126         emit signal_canceled(m_initial_values);
127 
128     close();
129 }
130 
131 }   // namespace studio
132 }   // namespace appleseed
133