#946 Fixed enabled state for tile window toolbar button

This commit is contained in:
Magne Sjaastad
2016-11-03 09:59:41 +01:00
parent 7f293a5257
commit f65559af38
4 changed files with 157 additions and 84 deletions

View File

@@ -24,6 +24,7 @@
#include <QAction> #include <QAction>
#include <QApplication> #include <QApplication>
#include "RiaApplication.h"
CAF_CMD_SOURCE_INIT(RicTileWindowsFeature, "RicTileWindowsFeature"); CAF_CMD_SOURCE_INIT(RicTileWindowsFeature, "RicTileWindowsFeature");
@@ -32,18 +33,11 @@ CAF_CMD_SOURCE_INIT(RicTileWindowsFeature, "RicTileWindowsFeature");
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicTileWindowsFeature::isCommandEnabled() bool RicTileWindowsFeature::isCommandEnabled()
{ {
QWidget* topLevelWidget = QApplication::activeWindow(); RiuMainWindow* mainWindow = RiuMainWindow::instance();
RiuMainWindow* mainWindow = dynamic_cast<RiuMainWindow*>(topLevelWidget);
RiuMainPlotWindow* mainPlotWindow = dynamic_cast<RiuMainPlotWindow*>(topLevelWidget);
if (mainWindow) if (mainWindow)
{ {
return mainWindow->isAnyMdiSubWindowVisible(); return mainWindow->isAnyMdiSubWindowVisible();
} }
else if (mainPlotWindow)
{
return mainPlotWindow->isAnyMdiSubWindowVisible();
}
return false; return false;
} }
@@ -53,18 +47,11 @@ bool RicTileWindowsFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicTileWindowsFeature::onActionTriggered(bool isChecked) void RicTileWindowsFeature::onActionTriggered(bool isChecked)
{ {
QWidget* topLevelWidget = QApplication::activeWindow(); RiuMainWindow* mainWindow = RiuMainWindow::instance();
RiuMainWindow* mainWindow = dynamic_cast<RiuMainWindow*>(topLevelWidget);
RiuMainPlotWindow* mainPlotWindow = dynamic_cast<RiuMainPlotWindow*>(topLevelWidget);
if (mainWindow) if (mainWindow)
{ {
mainWindow->tileWindows(); mainWindow->tileWindows();
} }
else if (mainPlotWindow)
{
mainPlotWindow->tileWindows();
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -75,3 +62,42 @@ void RicTileWindowsFeature::setupActionLook(QAction* actionToSetup)
actionToSetup->setText("Tile Windows"); actionToSetup->setText("Tile Windows");
actionToSetup->setIcon(QIcon(":/TileWindows24x24.png")); 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"));
}

View File

@@ -36,4 +36,17 @@ protected:
virtual void setupActionLook( QAction* actionToSetup ); 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);
};

View File

@@ -97,6 +97,8 @@ void RiuMainPlotWindow::initializeGuiNewProjectLoaded()
{ {
setPdmRoot(RiaApplication::instance()->project()); setPdmRoot(RiaApplication::instance()->project());
restoreTreeViewState(); restoreTreeViewState();
refreshToolbars();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -208,6 +210,42 @@ void RiuMainPlotWindow::createMenus()
helpMenu->addAction(cmdFeatureMgr->action("RicHelpOpenUsersGuideFeature")); 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(); caf::CmdFeatureManager* cmdFeatureMgr = caf::CmdFeatureManager::instance();
CVF_ASSERT(cmdFeatureMgr); CVF_ASSERT(cmdFeatureMgr);
{ QStringList toolbarNames;
QToolBar* toolbar = addToolBar(tr("Standard")); toolbarNames << "Standard" << "Window Management" << "View Snapshots" << "View";
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"));
}
for (QString toolbarName : toolbarNames)
{ {
QToolBar* toolbar = addToolBar(tr("Window Management")); QToolBar* toolbar = addToolBar(toolbarName);
toolbar->setObjectName(toolbar->windowTitle()); toolbar->setObjectName(toolbar->windowTitle());
toolbar->addAction(cmdFeatureMgr->action("RicShowMainWindowFeature"));
toolbar->addAction(cmdFeatureMgr->action("RicTileWindowsFeature"));
}
{ QStringList toolbarCommands = toolbarCommandIds(toolbarName);
QToolBar* toolbar = addToolBar(tr("View Snapshots")); for (QString s : toolbarCommands)
toolbar->setObjectName(toolbar->windowTitle()); {
toolbar->addAction(cmdFeatureMgr->action("RicSnapshotViewToClipboardFeature")); toolbar->addAction(cmdFeatureMgr->action(s));
toolbar->addAction(cmdFeatureMgr->action("RicSnapshotViewToFileFeature")); }
toolbar->addAction(cmdFeatureMgr->action("RicSnapshotAllPlotsToFileFeature"));
}
{
QToolBar* toolbar = addToolBar(tr("View"));
toolbar->setObjectName(toolbar->windowTitle());
toolbar->addAction(cmdFeatureMgr->action("RicViewZoomAllFeature"));
} }
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuMainPlotWindow::refreshToolbars()
{
QStringList allToolbarCommandNames = toolbarCommandIds();
caf::CmdFeatureManager::instance()->refreshEnabledState(allToolbarCommandNames);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainPlotWindow::createDockPanels() void RiuMainPlotWindow::createDockPanels()
{ {
{ {
@@ -343,6 +373,8 @@ void RiuMainPlotWindow::removeViewer(QWidget* viewer)
m_blockSlotSubWindowActivated = true; m_blockSlotSubWindowActivated = true;
m_mdiArea->removeSubWindow(findMdiSubWindow(viewer)); m_mdiArea->removeSubWindow(findMdiSubWindow(viewer));
m_blockSlotSubWindowActivated = false; m_blockSlotSubWindowActivated = false;
refreshToolbars();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -404,6 +436,8 @@ void RiuMainPlotWindow::addViewer(QWidget* viewer, const RimMdiWindowGeometry& w
{ {
subWin->showMaximized(); subWin->showMaximized();
} }
refreshToolbars();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -506,7 +540,7 @@ void RiuMainPlotWindow::slotBuildWindowActions()
QAction* closeAllSubWindowsAction = new QAction("Close All Windows", this); QAction* closeAllSubWindowsAction = new QAction("Close All Windows", this);
connect(closeAllSubWindowsAction, SIGNAL(triggered()), m_mdiArea, SLOT(closeAllSubWindows())); 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(cascadeWindowsAction);
m_windowMenu->addAction(closeAllSubWindowsAction); m_windowMenu->addAction(closeAllSubWindowsAction);
} }

View File

@@ -52,71 +52,71 @@ class RiuMainPlotWindow : public RiuMainWindowBase
public: public:
RiuMainPlotWindow(); RiuMainPlotWindow();
virtual QString mainWindowName() { return "RiuMainPlotWindow"; } virtual QString mainWindowName() { return "RiuMainPlotWindow"; }
void initializeGuiNewProjectLoaded(); void initializeGuiNewProjectLoaded();
void cleanupGuiBeforeProjectClose(); void cleanupGuiBeforeProjectClose();
void removeViewer( QWidget* viewer ); void removeViewer( QWidget* viewer );
void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry); void addViewer(QWidget* viewer, const RimMdiWindowGeometry& windowsGeometry);
void setActiveViewer(QWidget* subWindow); void setActiveViewer(QWidget* subWindow);
caf::PdmUiTreeView* projectTreeView() { return m_projectTreeView;} 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 windowGeometryForViewer(QWidget* viewer);
RimMdiWindowGeometry windowGeometryForWidget(QWidget* widget); RimMdiWindowGeometry windowGeometryForWidget(QWidget* widget);
void tileWindows(); void tileWindows();
bool isAnyMdiSubWindowVisible(); bool isAnyMdiSubWindowVisible();
QMdiSubWindow* findMdiSubWindow(QWidget* viewer); QMdiSubWindow* findMdiSubWindow(QWidget* viewer);
QList<QMdiSubWindow*> subWindowList(QMdiArea::WindowOrder order); QList<QMdiSubWindow*> subWindowList(QMdiArea::WindowOrder order);
protected: protected:
virtual void closeEvent(QCloseEvent* event); virtual void closeEvent(QCloseEvent* event);
private: private:
void createActions(); void setPdmRoot(caf::PdmObject* pdmRoot);
void createMenus();
void createToolBars();
void createDockPanels();
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: 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; QMdiArea* m_mdiArea;
RiuViewer* m_mainViewer; RiuViewer* m_mainViewer;
QMenu* m_windowMenu; QMenu* m_windowMenu;
caf::PdmUiTreeView* m_projectTreeView;
// 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;
std::unique_ptr<caf::PdmUiDragDropInterface> m_dragDropInterface; std::unique_ptr<caf::PdmUiDragDropInterface> m_dragDropInterface;