forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGui05.cpp
404 lines (327 loc) · 12.3 KB
/
Gui05.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/* ***** BEGIN LICENSE BLOCK *****
* This file is part of Natron <https://natrongithub.github.io/>,
* (C) 2018-2021 The Natron developers
* (C) 2013-2018 INRIA and Alexandre Gauthier-Foichat
*
* Natron is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Natron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Natron. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
* ***** END LICENSE BLOCK ***** */
// ***** BEGIN PYTHON BLOCK *****
// from <https://docs.python.org/3/c-api/intro.html#include-files>:
// "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
#include <Python.h>
// ***** END PYTHON BLOCK *****
#include "Gui.h"
#include <cassert>
#include <stdexcept>
#include <QtCore/QCoreApplication>
#include <QtCore/QThread>
#include <QtCore/QTimer>
#include <QHBoxLayout>
#include <QGraphicsScene>
#include <QUndoGroup>
#ifdef DEBUG
#include "Global/FloatingPointExceptions.h"
#endif
#include "Engine/Node.h"
#include "Engine/NodeGroup.h"
#include "Engine/NodeSerialization.h"
#include "Engine/Project.h"
#include "Engine/TimeLine.h"
#include "Engine/CreateNodeArgs.h"
#include "Gui/AboutWindow.h"
#include "Gui/AutoHideToolBar.h"
#include "Gui/DockablePanel.h"
#include "Gui/CurveEditor.h"
#include "Gui/CurveWidget.h"
#include "Gui/FloatingWidget.h"
#include "Gui/GuiAppInstance.h"
#include "Gui/GuiPrivate.h"
#include "Gui/Histogram.h"
#include "Gui/NodeGraph.h"
#include "Gui/ProgressPanel.h"
#include "Gui/ProjectGui.h"
#include "Gui/GuiApplicationManager.h"
#include "Gui/Splitter.h"
#include "Gui/TabWidget.h"
#include "Gui/ViewerTab.h"
NATRON_NAMESPACE_ENTER
void
Gui::setupUi()
{
onProjectNameChanged(QString(), false);
setMouseTracking(true);
installEventFilter(this);
assert( !isFullScreen() );
//Gui::loadStyleSheet();
///Restores position, size of the main window as well as whether it was fullscreen or not.
_imp->restoreGuiGeometry();
_imp->_undoStacksGroup = new QUndoGroup;
QObject::connect( _imp->_undoStacksGroup, SIGNAL(activeStackChanged(QUndoStack*)), this, SLOT(onCurrentUndoStackChanged(QUndoStack*)) );
createMenuActions();
/*CENTRAL AREA*/
//======================
_imp->_centralWidget = new QWidget(this);
setCentralWidget(_imp->_centralWidget);
_imp->_mainLayout = new QHBoxLayout(_imp->_centralWidget);
_imp->_mainLayout->setContentsMargins(0, 0, 0, 0);
_imp->_centralWidget->setLayout(_imp->_mainLayout);
_imp->_leftRightSplitter = new Splitter(_imp->_centralWidget);
_imp->_leftRightSplitter->setChildrenCollapsible(false);
_imp->_leftRightSplitter->setObjectName( QString::fromUtf8(kMainSplitterObjectName) );
_imp->_splitters.push_back(_imp->_leftRightSplitter);
_imp->_leftRightSplitter->setOrientation(Qt::Horizontal);
_imp->_leftRightSplitter->setContentsMargins(0, 0, 0, 0);
_imp->_toolBox = new AutoHideToolBar(this, _imp->_leftRightSplitter);
_imp->_toolBox->setToolButtonStyle(Qt::ToolButtonIconOnly);
_imp->_toolBox->setOrientation(Qt::Vertical);
_imp->_toolBox->setMaximumWidth( TO_DPIX(NATRON_TOOL_BUTTON_SIZE) );
if (_imp->leftToolBarDisplayedOnHoverOnly) {
_imp->refreshLeftToolBarVisibility( mapFromGlobal( QCursor::pos() ) );
}
_imp->_leftRightSplitter->addWidget(_imp->_toolBox);
_imp->_mainLayout->addWidget(_imp->_leftRightSplitter);
_imp->createNodeGraphGui();
_imp->createCurveEditorGui();
_imp->createDopeSheetGui();
_imp->createScriptEditorGui();
_imp->createProgressPanelGui();
///Must be absolutely called once _nodeGraphArea has been initialized.
_imp->createPropertiesBinGui();
ProjectPtr project = getApp()->getProject();
_imp->_projectGui = new ProjectGui(this);
_imp->_projectGui->create(project,
_imp->_layoutPropertiesBin,
this);
_imp->_errorLog = new LogWindow(0);
_imp->_errorLog->hide();
createDefaultLayoutInternal(false);
initProjectGuiKnobs();
setVisibleProjectSettingsPanel();
_imp->_aboutWindow = new AboutWindow(this);
_imp->_aboutWindow->hide();
//the same action also clears the ofx plugins caches, they are not the same cache but are used to the same end
QObject::connect( project.get(), SIGNAL(projectNameChanged(QString,bool)), this, SLOT(onProjectNameChanged(QString,bool)) );
TimeLinePtr timeline = project->getTimeLine();
QObject::connect( timeline.get(), SIGNAL(frameChanged(SequenceTime,int)), this, SLOT(renderViewersAndRefreshKnobsAfterTimelineTimeChange(SequenceTime,int)) );
QObject::connect( timeline.get(), SIGNAL(frameAboutToChange()), this, SLOT(onTimelineTimeAboutToChange()) );
/*Searches recursively for all child objects of the given object,
and connects matching signals from them to slots of object that follow the following form:
void on_<object name>_<signal name>(<signal parameters>);
Let's assume our object has a child object of type QPushButton with the object name button1.
The slot to catch the button's clicked() signal would be:
void on_button1_clicked();
If object itself has a properly set object name, its own signals are also connected to its respective slots.
*/
QMetaObject::connectSlotsByName(this);
{
#ifdef DEBUG
boost_adaptbx::floating_point::exception_trapping trap(0);
#endif
appPTR->setOFXHostHandle( getApp()->getOfxHostOSHandle() );
}
} // setupUi
void
Gui::onPropertiesScrolled()
{
#ifdef __NATRON_WIN32__
//On Windows Qt 4.8.6 has a bug where the viewport of the scrollarea gets scrolled outside the bounding rect of the QScrollArea and overlaps all widgets inheriting QGLWidget.
//The only thing I could think of was to repaint all GL widgets manually...
{
QMutexLocker k(&_imp->_viewerTabsMutex);
for (std::list<ViewerTab*>::iterator it = _imp->_viewerTabs.begin(); it != _imp->_viewerTabs.end(); ++it) {
(*it)->redrawGLWidgets();
}
}
_imp->_curveEditor->getCurveWidget()->update();
{
QMutexLocker k (&_imp->_histogramsMutex);
for (std::list<Histogram*>::iterator it = _imp->_histograms.begin(); it != _imp->_histograms.end(); ++it) {
(*it)->update();
}
}
#endif
}
void
Gui::updateAboutWindowLibrariesVersion()
{
if (_imp->_aboutWindow) {
_imp->_aboutWindow->updateLibrariesVersions();
}
}
void
Gui::createGroupGui(const NodePtr & group,
const CreateNodeArgs& args)
{
NodeGroupPtr isGrp = boost::dynamic_pointer_cast<NodeGroup>( group->getEffectInstance()->shared_from_this() );
assert(isGrp);
NodeCollectionPtr collection = boost::dynamic_pointer_cast<NodeCollection>(isGrp);
assert(collection);
TabWidget* where = 0;
if (_imp->_lastFocusedGraph) {
TabWidget* isTab = dynamic_cast<TabWidget*>( _imp->_lastFocusedGraph->parentWidget() );
if (isTab) {
where = isTab;
} else {
QMutexLocker k(&_imp->_panesMutex);
assert( !_imp->_panes.empty() );
where = _imp->_panes.front();
}
}
QGraphicsScene* scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
NodeGraph* nodeGraph = new NodeGraph(this, collection, scene, this);
nodeGraph->setObjectName( QString::fromUtf8( group->getLabel().c_str() ) );
_imp->_groups.push_back(nodeGraph);
NodeSerializationPtr serialization = args.getProperty<NodeSerializationPtr>(kCreateNodeArgsPropNodeSerialization);
if ( where && !serialization && !getApp()->isCreatingPythonGroup() ) {
where->appendTab(nodeGraph, nodeGraph);
QTimer::singleShot( 25, nodeGraph, SLOT(centerOnAllNodes()) );
} else {
nodeGraph->setVisible(false);
}
}
void
Gui::addGroupGui(NodeGraph* tab,
TabWidget* where)
{
assert(tab);
assert(where);
{
std::list<NodeGraph*>::iterator it = std::find(_imp->_groups.begin(), _imp->_groups.end(), tab);
if ( it == _imp->_groups.end() ) {
_imp->_groups.push_back(tab);
}
}
where->appendTab(tab, tab);
}
void
Gui::removeGroupGui(NodeGraph* tab,
bool deleteData)
{
tab->hide();
if (_imp->_lastFocusedGraph == tab) {
_imp->_lastFocusedGraph = 0;
}
TabWidget* container = dynamic_cast<TabWidget*>( tab->parentWidget() );
if (container) {
container->removeTab(tab, true);
}
if (deleteData) {
std::list<NodeGraph*>::iterator it = std::find(_imp->_groups.begin(), _imp->_groups.end(), tab);
if ( it != _imp->_groups.end() ) {
_imp->_groups.erase(it);
}
unregisterTab(tab);
tab->deleteLater();
}
}
void
Gui::setLastSelectedGraph(NodeGraph* graph)
{
assert( QThread::currentThread() == qApp->thread() );
_imp->_lastFocusedGraph = graph;
}
NodeGraph*
Gui::getLastSelectedGraph() const
{
assert( QThread::currentThread() == qApp->thread() );
return _imp->_lastFocusedGraph;
}
void
Gui::setActiveViewer(ViewerTab* viewer)
{
assert( QThread::currentThread() == qApp->thread() );
_imp->_activeViewer = viewer;
}
ViewerTab*
Gui::getActiveViewer() const
{
assert( QThread::currentThread() == qApp->thread() );
return _imp->_activeViewer;
}
NodeCollectionPtr
Gui::getLastSelectedNodeCollection() const
{
NodeGraph* graph = 0;
if (_imp->_lastFocusedGraph) {
graph = _imp->_lastFocusedGraph;
} else {
graph = _imp->_nodeGraphArea;
}
NodeCollectionPtr group = graph->getGroup();
assert(group);
return group;
}
void
Gui::wipeLayout()
{
std::list<TabWidget*> panesCpy;
{
QMutexLocker l(&_imp->_panesMutex);
panesCpy = _imp->_panes;
_imp->_panes.clear();
}
std::list<FloatingWidget*> floatingWidgets = getFloatingWindows();
FloatingWidget* projectFW = _imp->_projectGui->getPanel()->getFloatingWindow();
for (std::list<FloatingWidget*>::const_iterator it = floatingWidgets.begin(); it != floatingWidgets.end(); ++it) {
if (!projectFW || (*it) != projectFW) {
(*it)->deleteLater();
}
}
{
QMutexLocker k(&_imp->_floatingWindowMutex);
_imp->_floatingWindows.clear();
// Re-add the project window
if (projectFW) {
_imp->_floatingWindows.push_back(projectFW);
}
}
for (std::list<TabWidget*>::iterator it = panesCpy.begin(); it != panesCpy.end(); ++it) {
///Conserve tabs by removing them from the tab widgets. This way they will not be deleted.
while ( (*it)->count() > 0 ) {
(*it)->removeTab(0, false);
}
//(*it)->setParent(NULL);
(*it)->deleteLater();
}
std::list<Splitter*> splittersCpy;
{
QMutexLocker l(&_imp->_splittersMutex);
splittersCpy = _imp->_splitters;
_imp->_splitters.clear();
}
for (std::list<Splitter*>::iterator it = splittersCpy.begin(); it != splittersCpy.end(); ++it) {
if (_imp->_leftRightSplitter != *it) {
while ( (*it)->count() > 0 ) {
(*it)->widget(0)->setParent(NULL);
}
//(*it)->setParent(NULL);
(*it)->deleteLater();
}
}
Splitter *newSplitter = new Splitter(_imp->_centralWidget);
newSplitter->addWidget(_imp->_toolBox);
newSplitter->setObjectName_mt_safe( _imp->_leftRightSplitter->objectName_mt_safe() );
_imp->_mainLayout->removeWidget(_imp->_leftRightSplitter);
unregisterSplitter(_imp->_leftRightSplitter);
_imp->_leftRightSplitter->deleteLater();
_imp->_leftRightSplitter = newSplitter;
_imp->_leftRightSplitter->setChildrenCollapsible(false);
_imp->_mainLayout->addWidget(newSplitter);
{
QMutexLocker l(&_imp->_splittersMutex);
_imp->_splitters.push_back(newSplitter);
}
} // Gui::wipeLayout
NATRON_NAMESPACE_EXIT