From 6f61d323c203536124d41ad345268614a73e7dd3 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 9 Aug 2016 01:53:35 +0200 Subject: [PATCH] refs #720, improved menu action * show info when DB is not available * allow to grey out menus (better as hiding them) --- src/blackgui/menus/menuaction.cpp | 14 ++++++++++++-- src/blackgui/menus/menuaction.h | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/blackgui/menus/menuaction.cpp b/src/blackgui/menus/menuaction.cpp index 513dcc98c..ea8edc676 100644 --- a/src/blackgui/menus/menuaction.cpp +++ b/src/blackgui/menus/menuaction.cpp @@ -8,6 +8,8 @@ */ #include "blackgui/menus/menuaction.h" +#include "blackgui/guiapplication.h" +#include "blackcore/webdataservices.h" #include "blackmisc/icons.h" #include "blackmisc/slot.h" #include "blackmisc/verify.h" @@ -20,6 +22,7 @@ #include using namespace BlackMisc; +using namespace BlackGui; namespace BlackGui { @@ -75,6 +78,12 @@ namespace BlackGui return this->m_icon.pixmap(this->m_icon.actualSize(QSize(16, 16))); } + void CMenuAction::setEnabled(bool enabled) + { + Q_ASSERT_X(this->m_action, Q_FUNC_INFO, "No action"); + this->m_action->setEnabled(enabled); + } + QString CMenuAction::getLastPathPart() const { if (this->m_path.contains('/')) @@ -377,7 +386,9 @@ namespace BlackGui CMenuAction CMenuActions::addMenuStash() { if (this->containsMenu(CMenuAction::pathStash())) { return CMenuAction(); } - return this->addMenu(CIcons::appDbStash16(), "Stash tools", CMenuAction::pathStash()); + const bool canConnectDb = sGui->getWebDataServices()->canConnectSwiftDb(); + const QString txt(canConnectDb ? "Stash tools" : "Stash tools (Warning: no DB!)"); + return this->addMenu(CIcons::appDbStash16(), txt, CMenuAction::pathStash()); } CMenuAction CMenuActions::addMenuStashEditor() @@ -445,6 +456,5 @@ namespace BlackGui const int i = currentPath.lastIndexOf('/'); return currentPath.left(i); } - } // ns } // ns diff --git a/src/blackgui/menus/menuaction.h b/src/blackgui/menus/menuaction.h index 1f08386f8..7c203846a 100644 --- a/src/blackgui/menus/menuaction.h +++ b/src/blackgui/menus/menuaction.h @@ -99,6 +99,9 @@ namespace BlackGui //! Has icon? bool hasIcon() const { return !m_icon.isNull(); } + //! Set enabled / disabled (allows to gray out) + void setEnabled(bool enabled); + //! Conversion operator QAction *() const { return this->m_action; }