void KnobGuiFile::createWidget(QHBoxLayout* layout) { KnobGuiPtr knobUI = getKnobGui(); if (!knobUI) { return; } Gui* gui = knobUI->getGui(); if (!gui) { return; } GuiAppInstancePtr app = gui->getApp(); if (!app) { return; } KnobFilePtr knob = _knob.lock(); if (!knob) { return; } EffectInstancePtr holderIsEffect = toEffectInstance( knob->getHolder() ); if ( holderIsEffect && holderIsEffect->isReader() && (knob->getName() == kOfxImageEffectFileParamName) ) { TimeLinePtr timeline = app->getTimeLine(); QObject::connect( timeline.get(), SIGNAL(frameChanged(SequenceTime,int)), this, SLOT(onTimelineFrameChanged(SequenceTime,int)) ); }
ViewerTab::~ViewerTab() { Gui* gui = getGui(); if (gui) { NodeGraph* graph = 0; ViewerNodePtr internalNode = getInternalNode(); ViewerInstancePtr viewerNode = internalNode ? internalNode->getInternalViewerNode() : ViewerInstancePtr(); if (viewerNode) { NodeCollectionPtr collection = viewerNode->getNode()->getGroup(); if (collection) { NodeGroupPtr isGrp = toNodeGroup(collection); if (isGrp) { NodeGraphI* graph_i = isGrp->getNodeGraph(); if (graph_i) { graph = dynamic_cast<NodeGraph*>(graph_i); assert(graph); } } else { graph = gui->getNodeGraph(); } } internalNode->invalidateUiContext(); } else { graph = gui->getNodeGraph(); } assert(graph); GuiAppInstancePtr app = gui->getApp(); if ( app && !app->isClosing() && graph && (graph->getLastSelectedViewer() == this) ) { graph->setLastSelectedViewer(0); } } _imp->nodesContext.clear(); }
void ViewerTab::setInfoBarAndViewerResolution(const RectI& rect, const RectD& canonicalRect, double par, int texIndex) { std::string formatName, infoBarName; Gui* gui = getGui(); if (!gui) { return; } GuiAppInstancePtr app = gui->getApp(); if (!app) { return; } if (!app->getProject()->getFormatNameFromRect(rect, par, &formatName)) { formatName = makeUpFormatName(rect, par); infoBarName = formatName; } else { // If the format has a name, for the info bar also add the resolution std::stringstream ss; ss << formatName; ss << ' '; ss << rect.width(); ss << 'x'; ss << rect.height(); infoBarName = ss.str(); } _imp->infoWidget[texIndex]->setResolution(QString::fromUtf8(infoBarName.c_str())); _imp->viewer->setFormat(formatName, canonicalRect, par, texIndex); }
AppInstancePtr Gui::openProjectInternal(const std::string & absoluteFileName, bool attemptToLoadAutosave) { QFileInfo file( QString::fromUtf8( absoluteFileName.c_str() ) ); if ( !file.exists() ) { return AppInstancePtr(); } QString fileUnPathed = file.fileName(); QString path = file.path() + QLatin1Char('/'); int openedProject = appPTR->isProjectAlreadyOpened(absoluteFileName); if (openedProject != -1) { AppInstancePtr instance = appPTR->getAppInstance(openedProject); if (instance) { GuiAppInstancePtr guiApp = toGuiAppInstance(instance); if (guiApp) { guiApp->getGui()->activateWindow(); return instance; } } } AppInstancePtr ret; ProjectPtr project = getApp()->getProject(); ///if the current graph has no value, just load the project in the same window if ( project->isGraphWorthLess() ) { bool ok = project->loadProject( path, fileUnPathed, false, attemptToLoadAutosave); if (ok) { ret = _imp->_appInstance.lock(); } } else { CLArgs cl; AppInstancePtr newApp = appPTR->newAppInstance(cl, false); bool ok = newApp->getProject()->loadProject( path, fileUnPathed, false, attemptToLoadAutosave); if (ok) { ret = newApp; } } QSettings settings; QStringList recentFiles = settings.value( QString::fromUtf8("recentFileList") ).toStringList(); recentFiles.removeAll( QString::fromUtf8( absoluteFileName.c_str() ) ); recentFiles.prepend( QString::fromUtf8( absoluteFileName.c_str() ) ); while (recentFiles.size() > NATRON_MAX_RECENT_FILES) { recentFiles.removeLast(); } settings.setValue(QString::fromUtf8("recentFileList"), recentFiles); appPTR->updateAllRecentFileMenus(); return ret; } // Gui::openProjectInternal
void GuiApplicationManagerPrivate::addStandardKeybind(const std::string & grouping, const std::string & id, const std::string & description, QKeySequence::StandardKey key, const Qt::KeyboardModifiers & fallbackmodifiers, Qt::Key fallbacksymbol) { QString groupingStr = QString::fromUtf8( grouping.c_str() ); QString idStr = QString::fromUtf8( id.c_str() ); AppShortcuts::iterator foundGroup = _actionShortcuts.find(groupingStr); if ( foundGroup != _actionShortcuts.end() ) { GroupShortcuts::iterator foundAction = foundGroup->second.find(idStr); if ( foundAction != foundGroup->second.end() ) { return; } } Qt::KeyboardModifiers modifiers; Qt::Key symbol; extractKeySequence(QKeySequence(key), modifiers, symbol); if (symbol == (Qt::Key)0) { symbol = fallbacksymbol; modifiers = fallbackmodifiers; } KeyBoundAction* kA = new KeyBoundAction; kA->grouping = groupingStr; kA->description = QString::fromUtf8( description.c_str() ); kA->defaultModifiers.push_back(modifiers); kA->modifiers.push_back(modifiers); kA->defaultShortcut.push_back(symbol); kA->currentShortcut.push_back(symbol); if ( foundGroup != _actionShortcuts.end() ) { foundGroup->second.insert( std::make_pair(idStr, kA) ); } else { GroupShortcuts group; group.insert( std::make_pair(idStr, kA) ); _actionShortcuts.insert( std::make_pair(groupingStr, group) ); } GuiAppInstancePtr app = toGuiAppInstance( _publicInterface->getTopLevelInstance() ); if (app) { app->getGui()->addShortcut(kA); } }
void GuiApplicationManagerPrivate::addKeybindInternal(const QString & grouping, const QString & id, const QString & description, const std::list<Qt::KeyboardModifiers>& modifiersList, const std::list<Qt::Key>& symbolsList, const Qt::KeyboardModifiers& modifiersMask) { AppShortcuts::iterator foundGroup = _actionShortcuts.find(grouping); if ( foundGroup != _actionShortcuts.end() ) { GroupShortcuts::iterator foundAction = foundGroup->second.find(id); if ( foundAction != foundGroup->second.end() ) { return; } } KeyBoundAction* kA = new KeyBoundAction; kA->grouping = grouping; kA->description = description; assert( modifiersList.size() == symbolsList.size() ); std::list<Qt::KeyboardModifiers>::const_iterator mit = modifiersList.begin(); for (std::list<Qt::Key>::const_iterator it = symbolsList.begin(); it != symbolsList.end(); ++it, ++mit) { if ( (*it) != (Qt::Key)0 ) { kA->defaultModifiers.push_back(*mit); kA->modifiers.push_back(*mit); kA->defaultShortcut.push_back(*it); kA->currentShortcut.push_back(*it); } } kA->ignoreMask = modifiersMask; kA->actionID = id; if ( foundGroup != _actionShortcuts.end() ) { foundGroup->second.insert( std::make_pair(id, kA) ); } else { GroupShortcuts group; group.insert( std::make_pair(id, kA) ); _actionShortcuts.insert( std::make_pair(grouping, group) ); } GuiAppInstancePtr app = toGuiAppInstance( _publicInterface->getTopLevelInstance() ); if (app) { app->getGui()->addShortcut(kA); } }
void ToolButton::onTriggered() { GuiAppInstancePtr app = _imp->_app.lock(); if (!app) { return; } NodeCollectionPtr group = app->getGui()->getLastSelectedNodeCollection(); assert(group); CreateNodeArgs args(_imp->_id.toStdString(), group); args.setProperty<int>(kCreateNodeArgsPropPluginVersion, _imp->_major, 0); args.setProperty<int>(kCreateNodeArgsPropPluginVersion, _imp->_minor, 1); app->createNode(args); }
void GuiApplicationManagerPrivate::addMouseShortcut(const std::string & grouping, const std::string & id, const std::string & description, const Qt::KeyboardModifiers & modifiers, Qt::MouseButton button) { QString groupingStr = QString::fromUtf8( grouping.c_str() ); QString idStr = QString::fromUtf8( id.c_str() ); AppShortcuts::iterator foundGroup = _actionShortcuts.find(groupingStr); if ( foundGroup != _actionShortcuts.end() ) { GroupShortcuts::iterator foundAction = foundGroup->second.find(idStr); if ( foundAction != foundGroup->second.end() ) { return; } } MouseAction* mA = new MouseAction; mA->grouping = groupingStr; mA->description = QString::fromUtf8( description.c_str() ); mA->defaultModifiers.push_back(modifiers); mA->actionID = idStr; if ( modifiers & (Qt::AltModifier | Qt::MetaModifier) ) { qDebug() << "Warning: mouse shortcut " << groupingStr << '/' << description.c_str() << '(' << idStr << ')' << " uses the Alt or Meta modifier, which is reserved for three-button mouse emulation. Fix this ASAP."; } mA->modifiers.push_back(modifiers); mA->button = button; ///Mouse shortcuts are not editable. mA->editable = false; if ( foundGroup != _actionShortcuts.end() ) { foundGroup->second.insert( std::make_pair(idStr, mA) ); } else { GroupShortcuts group; group.insert( std::make_pair(idStr, mA) ); _actionShortcuts.insert( std::make_pair(groupingStr, group) ); } GuiAppInstancePtr app = toGuiAppInstance( _publicInterface->getTopLevelInstance() ); if (app) { app->getGui()->addShortcut(mA); } }
void ViewerTab::onTimeLineTimeChanged(SequenceTime time, int reason) { Gui* gui = getGui(); if (!gui) { return; } ViewerNodePtr node = _imp->viewerNode.lock(); ViewerInstancePtr viewerNode = node->getInternalViewerNode(); if ((TimelineChangeReasonEnum)reason != eTimelineChangeReasonPlaybackSeek) { node->getCurrentFrameKnob()->setValue(time, ViewSetSpec::current(), DimIdx(0), eValueChangedReasonPluginEdited); } GuiAppInstancePtr app = gui->getApp(); if ( app && _imp->timeLineGui->getTimeline() != app->getTimeLine() ) { viewerNode->renderCurrentFrame(true); } }
NATRON_NAMESPACE_ENTER ViewerTab::ViewerTab(const std::string& scriptName, const std::list<NodeGuiPtr> & existingNodesContext, const std::list<NodeGuiPtr>& activePluginsContext, Gui* gui, const NodeGuiPtr& node_ui, QWidget* parent) : QWidget(parent) , PanelWidget(scriptName, this, gui) , _imp( new ViewerTabPrivate(this, node_ui) ) { ViewerNodePtr node = node_ui->getNode()->isEffectViewerNode(); installEventFilter(this); setMouseTracking(true); NodePtr internalNode = node->getNode(); QObject::connect( internalNode.get(), SIGNAL(scriptNameChanged(QString)), this, SLOT(onInternalNodeScriptNameChanged(QString)) ); QObject::connect( internalNode.get(), SIGNAL(labelChanged(QString,QString)), this, SLOT(onInternalNodeLabelChanged(QString,QString)) ); QObject::connect( node.get(), SIGNAL(internalViewerCreated()), this, SLOT(onInternalViewerCreated())); _imp->mainLayout = new QVBoxLayout(this); setLayout(_imp->mainLayout); _imp->mainLayout->setSpacing(0); _imp->mainLayout->setContentsMargins(0, 0, 0, 0); QFontMetrics fm(font(), 0); _imp->viewerContainer = new QWidget(this); _imp->viewerLayout = new QHBoxLayout(_imp->viewerContainer); _imp->viewerLayout->setContentsMargins(0, 0, 0, 0); _imp->viewerLayout->setSpacing(0); _imp->viewerSubContainer = new QWidget(_imp->viewerContainer); _imp->viewerSubContainerLayout = new QVBoxLayout(_imp->viewerSubContainer); _imp->viewerSubContainerLayout->setContentsMargins(0, 0, 0, 0); _imp->viewerSubContainerLayout->setSpacing(1); // Info bars QString inputNames[2] = { QString::fromUtf8("A:"), QString::fromUtf8("B:") }; bool infobarvisible = node->isInfoBarVisible(); for (int i = 0; i < 2; ++i) { _imp->infoWidget[i] = new InfoViewerWidget(inputNames[i], this); } // Viewer _imp->viewer = new ViewerGL(this); GuiAppInstancePtr app = gui->getApp(); // Init viewer to project format { Format projectFormat; app->getProject()->getProjectDefaultFormat(&projectFormat); RectD canonicalFormat = projectFormat.toCanonicalFormat(); for (int i = 0; i < 2; ++i) { _imp->viewer->setInfoViewer(_imp->infoWidget[i], i); _imp->viewer->setRegionOfDefinition(canonicalFormat, projectFormat.getPixelAspectRatio(), i); setInfoBarAndViewerResolution(projectFormat, canonicalFormat, projectFormat.getPixelAspectRatio(), i); } _imp->viewer->resetWipeControls(); } _imp->viewerSubContainerLayout->addWidget(_imp->viewer); for (int i = 0; i < 2; ++i) { _imp->viewerSubContainerLayout->addWidget(_imp->infoWidget[i]); _imp->viewer->setInfoViewer(_imp->infoWidget[i], i); if (i == 1 || !infobarvisible) { _imp->infoWidget[i]->hide(); } } manageSlotsForInfoWidget(0, true); _imp->viewerLayout->addWidget(_imp->viewerSubContainer); _imp->mainLayout->addWidget(_imp->viewerContainer); TimeLinePtr timeline = app->getTimeLine(); _imp->timeLineGui = new TimeLineGui(node, timeline, getGui(), this); QObject::connect( _imp->timeLineGui, SIGNAL(boundariesChanged(SequenceTime,SequenceTime)), this, SLOT(onTimelineBoundariesChanged(SequenceTime,SequenceTime)) ); QObject::connect( app->getProject().get(), SIGNAL(frameRangeChanged(int,int)), _imp->timeLineGui, SLOT(onProjectFrameRangeChanged(int,int)) ); _imp->timeLineGui->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); if (!node->isTimelineVisible()) { _imp->timeLineGui->hide(); } //Add some spacing because the timeline might be black as the info _imp->mainLayout->addSpacing( TO_DPIY(5) ); _imp->mainLayout->addWidget(_imp->timeLineGui); double leftBound, rightBound; leftBound = node->getPlaybackInPointKnob()->getValue(); rightBound = node->getPlaybackOutPointKnob()->getValue(); TimeValue projectLeft, projectRight; app->getProject()->getFrameRange(&projectLeft, &projectRight); _imp->timeLineGui->setBoundaries(leftBound, rightBound); onTimelineBoundariesChanged(leftBound, rightBound); _imp->timeLineGui->setFrameRangeEdited(projectLeft != leftBound || projectRight != rightBound);; manageTimelineSlot(false, timeline); QObject::connect( node.get(), SIGNAL(renderStatsAvailable(int,double,RenderStatsMap)), this, SLOT(onRenderStatsAvailable(int,double,RenderStatsMap)) ); QObject::connect( _imp->viewer, SIGNAL(zoomChanged(int)), this, SLOT(updateZoomComboBox(int)) ); QObject::connect( node.get(), SIGNAL(viewerDisconnected()), this, SLOT(disconnectViewer()) ); createNodeViewerInterface(node_ui); setPluginViewerInterface(node_ui); for (std::list<NodeGuiPtr>::const_iterator it = existingNodesContext.begin(); it != existingNodesContext.end(); ++it) { ViewerNodePtr isViewerNode = (*it)->getNode()->isEffectViewerNode(); // For viewers, create the viewer interface separately if (!isViewerNode) { createNodeViewerInterface(*it); } } for (std::list<NodeGuiPtr>::const_iterator it = activePluginsContext.begin(); it != activePluginsContext.end(); ++it) { ViewerNodePtr isViewerNode = (*it)->getNode()->isEffectViewerNode(); // For viewers, create the viewer interface separately if (!isViewerNode) { setPluginViewerInterface(*it); } } setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); _imp->viewerNode.lock()->setUiContext( getViewer() ); QTimer::singleShot( 25, _imp->timeLineGui, SLOT(recenterOnBounds()) ); //Refresh the viewport lock state const std::list<ViewerTab*>& viewers = getGui()->getViewersList(); if ( !viewers.empty() ) { ViewerTab* other = viewers.front(); if ( other->getInternalNode()->isViewersSynchroEnabled() ) { double left, bottom, factor, par; other->getViewer()->getProjection(&left, &bottom, &factor, &par); _imp->viewer->setProjection(left, bottom, factor, par); node->setViewersSynchroEnabled(true); } } _imp->cachedFramesThread.reset(new CachedFramesThread(this)); _imp->cachedFramesThread->start(); }