diff --git a/ApplicationCode/Commands/ApplicationCommands/RicTileWindowsFeature.cpp b/ApplicationCode/Commands/ApplicationCommands/RicTileWindowsFeature.cpp index ee740141bf..d46689ecaf 100644 --- a/ApplicationCode/Commands/ApplicationCommands/RicTileWindowsFeature.cpp +++ b/ApplicationCode/Commands/ApplicationCommands/RicTileWindowsFeature.cpp @@ -24,6 +24,7 @@ #include #include +#include "RiaApplication.h" CAF_CMD_SOURCE_INIT(RicTileWindowsFeature, "RicTileWindowsFeature"); @@ -32,18 +33,11 @@ CAF_CMD_SOURCE_INIT(RicTileWindowsFeature, "RicTileWindowsFeature"); //-------------------------------------------------------------------------------------------------- bool RicTileWindowsFeature::isCommandEnabled() { - QWidget* topLevelWidget = QApplication::activeWindow(); - - RiuMainWindow* mainWindow = dynamic_cast(topLevelWidget); - RiuMainPlotWindow* mainPlotWindow = dynamic_cast(topLevelWidget); + RiuMainWindow* mainWindow = RiuMainWindow::instance(); if (mainWindow) { return mainWindow->isAnyMdiSubWindowVisible(); } - else if (mainPlotWindow) - { - return mainPlotWindow->isAnyMdiSubWindowVisible(); - } return false; } @@ -53,18 +47,11 @@ bool RicTileWindowsFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicTileWindowsFeature::onActionTriggered(bool isChecked) { - QWidget* topLevelWidget = QApplication::activeWindow(); - - RiuMainWindow* mainWindow = dynamic_cast(topLevelWidget); - RiuMainPlotWindow* mainPlotWindow = dynamic_cast(topLevelWidget); + RiuMainWindow* mainWindow = RiuMainWindow::instance(); if (mainWindow) { mainWindow->tileWindows(); } - else if (mainPlotWindow) - { - mainPlotWindow->tileWindows(); - } } //-------------------------------------------------------------------------------------------------- @@ -75,3 +62,42 @@ void RicTileWindowsFeature::setupActionLook(QAction* actionToSetup) actionToSetup->setText("Tile Windows"); actionToSetup->setIcon(QIcon(":/TileWindows24x24.png")); } + + + +CAF_CMD_SOURCE_INIT(RicTilePlotWindowsFeature, "RicTilePlotWindowsFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicTilePlotWindowsFeature::isCommandEnabled() +{ + RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow(); + if (mainPlotWindow) + { + return mainPlotWindow->isAnyMdiSubWindowVisible(); + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicTilePlotWindowsFeature::onActionTriggered(bool isChecked) +{ + RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow(); + if (mainPlotWindow) + { + mainPlotWindow->tileWindows(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicTilePlotWindowsFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Tile Windows"); + actionToSetup->setIcon(QIcon(":/TileWindows24x24.png")); +} diff --git a/ApplicationCode/Commands/ApplicationCommands/RicTileWindowsFeature.h b/ApplicationCode/Commands/ApplicationCommands/RicTileWindowsFeature.h index add1e130db..c1f587f7d8 100644 --- a/ApplicationCode/Commands/ApplicationCommands/RicTileWindowsFeature.h +++ b/ApplicationCode/Commands/ApplicationCommands/RicTileWindowsFeature.h @@ -36,4 +36,17 @@ protected: virtual void setupActionLook( QAction* actionToSetup ); }; +//================================================================================================== +/// +//================================================================================================== +class RicTilePlotWindowsFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + // Overrides + virtual bool isCommandEnabled(); + virtual void onActionTriggered(bool isChecked); + virtual void setupActionLook(QAction* actionToSetup); +}; diff --git a/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp b/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp index 2e27dfac02..6d5f930c4c 100644 --- a/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainPlotWindow.cpp @@ -97,6 +97,8 @@ void RiuMainPlotWindow::initializeGuiNewProjectLoaded() { setPdmRoot(RiaApplication::instance()->project()); restoreTreeViewState(); + + refreshToolbars(); } //-------------------------------------------------------------------------------------------------- @@ -208,6 +210,42 @@ void RiuMainPlotWindow::createMenus() helpMenu->addAction(cmdFeatureMgr->action("RicHelpOpenUsersGuideFeature")); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QStringList RiuMainPlotWindow::toolbarCommandIds(const QString& toolbarName) +{ + QStringList commandIds; + + if (toolbarName.isEmpty() || toolbarName == "Standard") + { + commandIds << "RicImportEclipseCaseFeature"; + commandIds << "RicImportInputEclipseCaseFeature"; + commandIds << "RicImportSummaryCaseFeature"; + commandIds << "RicOpenProjectFeature"; + commandIds << "RicSaveProjectFeature"; + } + + if (toolbarName.isEmpty() || toolbarName == "Window Management") + { + commandIds << "RicShowMainWindowFeature"; + commandIds << "RicTilePlotWindowsFeature"; + } + + if (toolbarName.isEmpty() || toolbarName == "View Snapshots") + { + commandIds << "RicSnapshotViewToClipboardFeature"; + commandIds << "RicSnapshotViewToFileFeature"; + commandIds << "RicSnapshotAllPlotsToFileFeature"; + } + + if (toolbarName.isEmpty() || toolbarName == "View") + { + commandIds << "RicViewZoomAllFeature"; + } + + return commandIds; +} //-------------------------------------------------------------------------------------------------- /// @@ -217,43 +255,35 @@ void RiuMainPlotWindow::createToolBars() caf::CmdFeatureManager* cmdFeatureMgr = caf::CmdFeatureManager::instance(); CVF_ASSERT(cmdFeatureMgr); - { - QToolBar* toolbar = addToolBar(tr("Standard")); - toolbar->setObjectName(toolbar->windowTitle()); - toolbar->addAction(cmdFeatureMgr->action("RicImportEclipseCaseFeature")); - toolbar->addAction(cmdFeatureMgr->action("RicImportInputEclipseCaseFeature")); - toolbar->addAction(cmdFeatureMgr->action("RicImportSummaryCaseFeature")); - toolbar->addAction(cmdFeatureMgr->action("RicOpenProjectFeature")); - toolbar->addAction(cmdFeatureMgr->action("RicSaveProjectFeature")); - } + QStringList toolbarNames; + toolbarNames << "Standard" << "Window Management" << "View Snapshots" << "View"; + for (QString toolbarName : toolbarNames) { - QToolBar* toolbar = addToolBar(tr("Window Management")); + QToolBar* toolbar = addToolBar(toolbarName); toolbar->setObjectName(toolbar->windowTitle()); - toolbar->addAction(cmdFeatureMgr->action("RicShowMainWindowFeature")); - toolbar->addAction(cmdFeatureMgr->action("RicTileWindowsFeature")); - } - { - QToolBar* toolbar = addToolBar(tr("View Snapshots")); - toolbar->setObjectName(toolbar->windowTitle()); - toolbar->addAction(cmdFeatureMgr->action("RicSnapshotViewToClipboardFeature")); - toolbar->addAction(cmdFeatureMgr->action("RicSnapshotViewToFileFeature")); - toolbar->addAction(cmdFeatureMgr->action("RicSnapshotAllPlotsToFileFeature")); - } - - { - QToolBar* toolbar = addToolBar(tr("View")); - toolbar->setObjectName(toolbar->windowTitle()); - toolbar->addAction(cmdFeatureMgr->action("RicViewZoomAllFeature")); + QStringList toolbarCommands = toolbarCommandIds(toolbarName); + for (QString s : toolbarCommands) + { + toolbar->addAction(cmdFeatureMgr->action(s)); + } } } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- +void RiuMainPlotWindow::refreshToolbars() +{ + QStringList allToolbarCommandNames = toolbarCommandIds(); + caf::CmdFeatureManager::instance()->refreshEnabledState(allToolbarCommandNames); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- void RiuMainPlotWindow::createDockPanels() { { @@ -343,6 +373,8 @@ void RiuMainPlotWindow::removeViewer(QWidget* viewer) m_blockSlotSubWindowActivated = true; m_mdiArea->removeSubWindow(findMdiSubWindow(viewer)); m_blockSlotSubWindowActivated = false; + + refreshToolbars(); } //-------------------------------------------------------------------------------------------------- @@ -404,6 +436,8 @@ void RiuMainPlotWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& w { subWin->showMaximized(); } + + refreshToolbars(); } //-------------------------------------------------------------------------------------------------- @@ -506,7 +540,7 @@ void RiuMainPlotWindow::slotBuildWindowActions() QAction* closeAllSubWindowsAction = new QAction("Close All Windows", this); connect(closeAllSubWindowsAction, SIGNAL(triggered()), m_mdiArea, SLOT(closeAllSubWindows())); - m_windowMenu->addAction(caf::CmdFeatureManager::instance()->action("RicTileWindowsFeature")); + m_windowMenu->addAction(caf::CmdFeatureManager::instance()->action("RicTilePlotWindowsFeature")); m_windowMenu->addAction(cascadeWindowsAction); m_windowMenu->addAction(closeAllSubWindowsAction); } diff --git a/ApplicationCode/UserInterface/RiuMainPlotWindow.h b/ApplicationCode/UserInterface/RiuMainPlotWindow.h index 1035b0697e..77f3fd2a89 100644 --- a/ApplicationCode/UserInterface/RiuMainPlotWindow.h +++ b/ApplicationCode/UserInterface/RiuMainPlotWindow.h @@ -52,71 +52,71 @@ class RiuMainPlotWindow : public RiuMainWindowBase public: RiuMainPlotWindow(); - virtual QString mainWindowName() { return "RiuMainPlotWindow"; } + virtual QString mainWindowName() { return "RiuMainPlotWindow"; } - void initializeGuiNewProjectLoaded(); - void cleanupGuiBeforeProjectClose(); + void initializeGuiNewProjectLoaded(); + void cleanupGuiBeforeProjectClose(); - void removeViewer( QWidget* viewer ); - void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry); - void setActiveViewer(QWidget* subWindow); + void removeViewer( QWidget* viewer ); + void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry); + void setActiveViewer(QWidget* subWindow); caf::PdmUiTreeView* projectTreeView() { return m_projectTreeView;} - void hideAllDockWindows(); + void hideAllDockWindows(); - void selectAsCurrentItem(caf::PdmObject* object); + void selectAsCurrentItem(caf::PdmObject* object); - void setDefaultWindowSize(); + void setDefaultWindowSize(); - void setExpanded(const caf::PdmUiItem* uiItem, bool expanded); + void setExpanded(const caf::PdmUiItem* uiItem, bool expanded); - RimMdiWindowGeometry windowGeometryForViewer(QWidget* viewer); - RimMdiWindowGeometry windowGeometryForWidget(QWidget* widget); + RimMdiWindowGeometry windowGeometryForViewer(QWidget* viewer); + RimMdiWindowGeometry windowGeometryForWidget(QWidget* widget); - void tileWindows(); - bool isAnyMdiSubWindowVisible(); - QMdiSubWindow* findMdiSubWindow(QWidget* viewer); + void tileWindows(); + bool isAnyMdiSubWindowVisible(); + QMdiSubWindow* findMdiSubWindow(QWidget* viewer); QList subWindowList(QMdiArea::WindowOrder order); protected: - virtual void closeEvent(QCloseEvent* event); + virtual void closeEvent(QCloseEvent* event); private: - void createActions(); - void createMenus(); - void createToolBars(); - void createDockPanels(); + void setPdmRoot(caf::PdmObject* pdmRoot); - void restoreTreeViewState(); + void createActions(); + void createMenus(); + void createToolBars(); + void createDockPanels(); + + void restoreTreeViewState(); + + void refreshToolbars(); + + static QStringList toolbarCommandIds(const QString& toolbarName = ""); + + +private slots: + + friend class RiuMdiSubWindow; + + void slotBuildWindowActions(); + + void slotSubWindowActivated(QMdiSubWindow* subWindow); + + void selectedObjectsChanged(); + void customMenuRequested(const QPoint& pos); private: - QByteArray m_initialDockAndToolbarLayout; // Initial dock window and toolbar layout, used to reset GUI + QByteArray m_initialDockAndToolbarLayout; // Initial dock window and toolbar layout, used to reset GUI -private: QMdiArea* m_mdiArea; RiuViewer* m_mainViewer; QMenu* m_windowMenu; - -// Menu and action slots -private slots: - - friend class RiuMdiSubWindow; - - void slotBuildWindowActions(); - - void slotSubWindowActivated(QMdiSubWindow* subWindow); - - void selectedObjectsChanged(); - void customMenuRequested(const QPoint& pos); - -public: - void setPdmRoot(caf::PdmObject* pdmRoot); - -private: - caf::PdmUiTreeView* m_projectTreeView; + caf::PdmUiTreeView* m_projectTreeView; std::unique_ptr m_dragDropInterface;