bool ContainerWidget::raiseSectionContent(const SectionContent::RefPtr& sc)
{
	// Search SC in sections
	for (int i = 0; i < _sections.count(); ++i)
	{
		SectionWidget* sw = _sections.at(i);
		int index = sw->indexOfContent(sc);
		if (index < 0)
			continue;
		sw->setCurrentIndex(index);
		return true;
	}

	// Search SC in floatings
	for (int i = 0; i < _floatings.size(); ++i)
	{
		FloatingWidget* fw = _floatings.at(i);
		if (fw->content()->uid() != sc->uid())
			continue;
		fw->setVisible(true);
		fw->raise();
		return true;
	}

	// Search SC in hidden
	if (_hiddenSectionContents.contains(sc->uid()))
		return showSectionContent(sc);

	qFatal("Unable to hide SectionContent, don't know this one 8-/");
	return false;
}
void
ApplicationWindowSerialization::initialize(bool mainWindow,
                                           SerializableWindow* widget)
{
    isMainWindow = mainWindow;
    widget->getMtSafePosition(x, y);
    widget->getMtSafeWindowSize(w, h);

    if (mainWindow) {
        Gui* gui = dynamic_cast<Gui*>(widget);
        assert(gui);
        if (gui) {
            QWidget* centralWidget = gui->getCentralWidget();
            Splitter* isSplitter = dynamic_cast<Splitter*>(centralWidget);
            TabWidget* isTabWidget = dynamic_cast<TabWidget*>(centralWidget);

            assert(isSplitter || isTabWidget);

            if (isSplitter) {
                child_asSplitter = new SplitterSerialization;
                child_asSplitter->initialize(isSplitter);
            } else if (isTabWidget) {
                child_asPane = new PaneLayout;
                child_asPane->initialize(isTabWidget);
            }
        }
    } else {
        FloatingWidget* isFloating = dynamic_cast<FloatingWidget*>(widget);
        assert(isFloating);
        if (isFloating) {
            QWidget* embedded = isFloating->getEmbeddedWidget();
            Splitter* isSplitter = dynamic_cast<Splitter*>(embedded);
            TabWidget* isTabWidget = dynamic_cast<TabWidget*>(embedded);
            DockablePanel* isPanel = dynamic_cast<DockablePanel*>(embedded);
            assert(isSplitter || isTabWidget || isPanel);

            if (isSplitter) {
                child_asSplitter = new SplitterSerialization;
                child_asSplitter->initialize(isSplitter);
            } else if (isTabWidget) {
                child_asPane = new PaneLayout;
                child_asPane->initialize(isTabWidget);
            } else if (isPanel) {
                ///A named knob holder is a knob holder which has a unique name.
                NamedKnobHolder* isNamedHolder = dynamic_cast<NamedKnobHolder*>( isPanel->getHolder() );
                if (isNamedHolder) {
                    child_asDockablePanel = isNamedHolder->getScriptName_mt_safe();
                } else {
                    ///This must be the project settings panel
                    child_asDockablePanel = kNatronProjectSettingsPanelSerializationName;
                }
            }
        }
    }
} // initialize
bool ContainerWidget::showSectionContent(const SectionContent::RefPtr& sc)
{
	// Search SC in floatings
	for (int i = 0; i < _floatings.count(); ++i)
	{
		FloatingWidget* fw = _floatings.at(i);
		const bool found = fw->content()->uid() == sc->uid();
		if (!found)
			continue;
		fw->setVisible(true);
		fw->_titleWidget->setVisible(true);
		fw->_contentWidget->setVisible(true);
		emit sectionContentVisibilityChanged(sc, true);
		return true;
	}

	// Search SC in hidden sections
	// Try to show them in the last position, otherwise simply append
	// it to the first section (or create a new section?)
	if (_hiddenSectionContents.contains(sc->uid()))
	{
		const HiddenSectionItem hsi = _hiddenSectionContents.take(sc->uid());
		hsi.data.titleWidget->setVisible(true);
		hsi.data.contentWidget->setVisible(true);
		SectionWidget* sw = NULL;
		if (hsi.preferredSectionId > 0 && (sw = SWLookupMapById(this).value(hsi.preferredSectionId)) != NULL)
		{
			sw->addContent(hsi.data, true);
			emit sectionContentVisibilityChanged(sc, true);
			return true;
		}
		else if (_sections.size() > 0 && (sw = _sections.first()) != NULL)
		{
			sw->addContent(hsi.data, true);
			emit sectionContentVisibilityChanged(sc, true);
			return true;
		}
		else
		{
			sw = newSectionWidget();
			addSection(sw);
			sw->addContent(hsi.data, true);
			emit sectionContentVisibilityChanged(sc, true);
			return true;
		}
	}

	// Already visible?
	// TODO
	qWarning("Unable to show SectionContent, don't know where 8-/ (already visible?)");
	return false;
}
Example #4
0
void TabWidget::floatPane(QPoint* position){
    QMutexLocker l(&_tabWidgetStateMutex);
    _isFloating = true;
    
    FloatingWidget* floatingW = new FloatingWidget(_gui);
    setVisible(false);
    setParent(0);
    floatingW->setWidget(size(),this);
    
    if (position) {
        floatingW->move(*position);
    }
    
}
bool ContainerWidget::removeSectionContent(const SectionContent::RefPtr& sc)
{
	// Hide the content.
	// The hideSectionContent() automatically deletes no longer required SectionWidget objects.
	if (!hideSectionContent(sc))
		return false;

	// Begin of ugly work arround.
	// TODO The hideSectionContent() method should take care of deleting FloatingWidgets and SectionWidgets,
	// but only cares about SectionWidgets right now. So we need to check whether it was a FloatingWidget
	// and delete it.
	bool found = false;
	for (int i = 0; i < _floatings.count(); ++i)
	{
		FloatingWidget* fw = _floatings.at(i);
		InternalContentData data;
		if (!(found = fw->takeContent(data)))
			continue;
		_floatings.removeAll(fw);
		delete fw;
		delete data.titleWidget;
		delete data.contentWidget;
		break;
	} // End of ugly work arround.

	// Get from hidden contents and delete associated internal stuff.
	if (!_hiddenSectionContents.contains(sc->uid()))
	{
		qFatal("Something went wrong... The content should have been there :-/");
		return false;
	}

	// Delete internal objects.
	HiddenSectionItem hsi = _hiddenSectionContents.take(sc->uid());
	delete hsi.data.titleWidget;
	delete hsi.data.contentWidget;

	// Hide the custom widgets of SectionContent.
	// ... should we? ...

	return true;
}
Example #6
0
void
Gui::restoreLayout(bool wipePrevious,
                   bool enableOldProjectCompatibility,
                   const GuiLayoutSerialization & layoutSerialization)
{
    ///Wipe the current layout
    if (wipePrevious) {
        wipeLayout();
    }

    ///For older projects prior to the layout change, just set default layout.
    if (enableOldProjectCompatibility) {
        createDefaultLayout1();
    } else {
        std::list<ApplicationWindowSerialization*> floatingDockablePanels;
        QDesktopWidget* desktop = QApplication::desktop();
        QRect screen = desktop->screenGeometry();

        ///now restore the gui layout
        for (std::list<ApplicationWindowSerialization*>::const_iterator it = layoutSerialization._windows.begin();
             it != layoutSerialization._windows.end(); ++it) {
            QWidget* mainWidget = 0;

            ///The window contains only a pane (for the main window it also contains the toolbar)
            if ( (*it)->child_asPane ) {
                TabWidget* centralWidget = new TabWidget(this);
                registerPane(centralWidget);
                restoreTabWidget(centralWidget, *(*it)->child_asPane);
                mainWidget = centralWidget;
            }
            ///The window contains a splitter as central widget
            else if ( (*it)->child_asSplitter ) {
                Splitter* centralWidget = new Splitter(this);
                restoreSplitterRecursive(this, centralWidget, *(*it)->child_asSplitter);
                mainWidget = centralWidget;
            }
            ///The child is a dockable panel, restore it later
            else if ( !(*it)->child_asDockablePanel.empty() ) {
                assert(!(*it)->isMainWindow);
                floatingDockablePanels.push_back(*it);
                continue;
            }

            assert(mainWidget);
            if (!mainWidget) {
                continue;
            }
            QWidget* window;
            if ( (*it)->isMainWindow ) {
                // mainWidget->setParent(_imp->_leftRightSplitter);
                _imp->_leftRightSplitter->addWidget_mt_safe(mainWidget);
                window = this;
            } else {
                FloatingWidget* floatingWindow = new FloatingWidget(this, this);
                floatingWindow->setWidget(mainWidget);
                registerFloatingWindow(floatingWindow);
                window = floatingWindow;
            }

            ///Restore geometry
            int w = std::min( (*it)->w, screen.width() );
            int h = std::min( (*it)->h, screen.height() );
            window->resize(w, h);
            // If the screen size changed, make sure at least 50x50 pixels of the window are visible
            int x = boost::algorithm::clamp( (*it)->x, screen.left(), screen.right() - 50 );
            int y = boost::algorithm::clamp( (*it)->y, screen.top(), screen.bottom() - 50 );
            window->move( QPoint(x, y) );
        }

        for (std::list<ApplicationWindowSerialization*>::iterator it = floatingDockablePanels.begin();
             it != floatingDockablePanels.end(); ++it) {
            ///Find the node associated to the floating panel if any and float it
            assert( !(*it)->child_asDockablePanel.empty() );
            if ( (*it)->child_asDockablePanel == kNatronProjectSettingsPanelSerializationName ) {
                _imp->_projectGui->getPanel()->floatPanel();
            } else {
                ///Find a node with the dockable panel name
                const NodesGuiList & nodes = getNodeGraph()->getAllActiveNodes();
                DockablePanel* panel = 0;
                for (NodesGuiList::const_iterator it2 = nodes.begin(); it2 != nodes.end(); ++it2) {
                    if ( (*it2)->getNode()->getScriptName() == (*it)->child_asDockablePanel ) {
                        (*it2)->ensurePanelCreated();
                        NodeSettingsPanel* nodeSettings = (*it2)->getSettingPanel();
                        if (nodeSettings) {
                            nodeSettings->floatPanel();
                            panel = nodeSettings;
                        }
                        break;
                    }
                }
                if (panel) {
                    FloatingWidget* fWindow = 0;
                    QWidget* w = panel->parentWidget();
                    while (!fWindow && w) {
                        fWindow = dynamic_cast<FloatingWidget*>(w);
                        w = w->parentWidget();
                    }

                    assert(fWindow);
                    fWindow->move( QPoint( (*it)->x, (*it)->y ) );
                    fWindow->resize( std::min( (*it)->w, screen.width() ), std::min( (*it)->h, screen.height() ) );
                }
            }
        }
    }
} // restoreLayout
Example #7
0
void
Gui::wipeLayout()
{

    std::list<TabWidgetI*> panesCpy = getApp()->getTabWidgetsSerialization();
    getApp()->clearTabWidgets();
    std::list<SerializableWindow*> floatingWidgets = getApp()->getFloatingWindowsSerialization();

    FloatingWidget* projectFW = _imp->_projectGui->getPanel()->getFloatingWindow();
    for (std::list<SerializableWindow*>::const_iterator it = floatingWidgets.begin(); it != floatingWidgets.end(); ++it) {
        if (!projectFW || (*it) != projectFW) {
            FloatingWidget* isFloating = dynamic_cast<FloatingWidget*>(*it);
            if (isFloating) {
                isFloating->deleteLater();
            }
        }
    }
    getApp()->clearFloatingWindows();

    // Re-add the project window
    if (projectFW) {
        getApp()->registerFloatingWindow(projectFW);
    }



    for (std::list<TabWidgetI*>::iterator it = panesCpy.begin(); it != panesCpy.end(); ++it) {
        TabWidget* pane = dynamic_cast<TabWidget*>(*it);
        if (!pane) {
            continue;
        }
        ///Conserve tabs by removing them from the tab widgets. This way they will not be deleted.
        while ( pane->count() > 0 ) {
            pane->removeTab(0, false);
        }
        //(*it)->setParent(NULL);
        pane->deleteLater();
    }

    std::list<SplitterI*> splittersCpy = getApp()->getSplittersSerialization();
    getApp()->clearSplitters();
    for (std::list<SplitterI*>::iterator it = splittersCpy.begin(); it != splittersCpy.end(); ++it) {
        if (_imp->_leftRightSplitter != *it) {
            Splitter* isSplitter = dynamic_cast<Splitter*>(*it);
            if (!isSplitter) {
                continue;
            }
            while ( isSplitter->count() > 0 ) {
                isSplitter->widget(0)->setParent(NULL);
            }
            //(*it)->setParent(NULL);
            isSplitter->deleteLater();
        }
    }


    Splitter *newSplitter = new Splitter(Qt::Horizontal,this, _imp->_centralWidget);
    newSplitter->addWidget(_imp->_toolBox);
    newSplitter->setObjectName_mt_safe( _imp->_leftRightSplitter->objectName_mt_safe() );
    _imp->_mainLayout->removeWidget(_imp->_leftRightSplitter);
    getApp()->unregisterSplitter(_imp->_leftRightSplitter);
    _imp->_leftRightSplitter->deleteLater();
    _imp->_leftRightSplitter = newSplitter;
    _imp->_leftRightSplitter->setChildrenCollapsible(false);
    _imp->_mainLayout->addWidget(newSplitter);

    getApp()->registerSplitter(newSplitter);

    // Re-create new menu actions
    createMenuActions();
 
} // Gui::wipeLayout