From 57ff07592a693e7e114ac5a6a103b852c7e3efe4 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Tue, 8 Oct 2019 19:37:07 +0100 Subject: [PATCH] [AFV] CInputManager stores icon indexes instead of QPixmap instances The GUI converts icon indexes to QPixmap indexes when needed. This fixes the context unittest that was broken by audio context changes. --- src/blackcore/actionbind.cpp | 4 ++-- src/blackcore/actionbind.h | 6 +++--- src/blackcore/inputmanager.cpp | 2 +- src/blackcore/inputmanager.h | 6 +++--- .../components/settingshotkeycomponent.h | 2 +- src/blackgui/guiactionbind.cpp | 10 ++++++++-- src/blackgui/models/actionitem.cpp | 6 ++++++ src/blackgui/models/actionitem.h | 4 ++++ src/blackgui/models/actionmodel.cpp | 4 ++-- src/blackmisc/input/actionhotkeydefs.cpp | 20 +++++++++---------- src/blackmisc/input/actionhotkeydefs.h | 12 +++++------ src/swiftguistandard/swiftguistd.h | 2 +- src/swiftguistandard/swiftguistdmenus.cpp | 2 +- 13 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/blackcore/actionbind.cpp b/src/blackcore/actionbind.cpp index a1de0e162..dc4be0c9a 100644 --- a/src/blackcore/actionbind.cpp +++ b/src/blackcore/actionbind.cpp @@ -10,13 +10,13 @@ namespace BlackCore { - CActionBind::CActionBind(const QString &action, const QPixmap &icon, QObject *parent) + CActionBind::CActionBind(const QString &action, BlackMisc::CIcons::IconIndex icon, QObject *parent) : QObject(parent) { CActionBind::registerAction(action, icon); } - QString CActionBind::registerAction(const QString &action, const QPixmap &icon) + QString CActionBind::registerAction(const QString &action, BlackMisc::CIcons::IconIndex icon) { if (!sApp || sApp->isShuttingDown()) { return {}; } if (sApp->getApplicationInfo().isUnitTest()) { return {}; } diff --git a/src/blackcore/actionbind.h b/src/blackcore/actionbind.h index b1b5c4537..1e42dc0a9 100644 --- a/src/blackcore/actionbind.h +++ b/src/blackcore/actionbind.h @@ -31,7 +31,7 @@ namespace BlackCore //! Constructor template - CActionBind(const QString &action, const QPixmap &icon, Receiver *receiver, + CActionBind(const QString &action, BlackMisc::CIcons::IconIndex icon, Receiver *receiver, MembFunc slot = nullptr, const std::function &deleteCallback = {}, QObject *parent = nullptr) : @@ -48,7 +48,7 @@ namespace BlackCore } //! Signature just to set an icon for an action - CActionBind(const QString &action, const QPixmap &icon, QObject *parent = nullptr); + CActionBind(const QString &action, BlackMisc::CIcons::IconIndex icon, QObject *parent = nullptr); //! Not copyable //! @{ @@ -75,7 +75,7 @@ namespace BlackCore static QString normalizeAction(const QString &action); //! Register action - static QString registerAction(const QString &action, const QPixmap &icon); + static QString registerAction(const QString &action, BlackMisc::CIcons::IconIndex icon); int m_index = -1; //!< action index (unique) std::function m_deleteCallback; //!< called when deleted diff --git a/src/blackcore/inputmanager.cpp b/src/blackcore/inputmanager.cpp index 63bc61fea..fc6872b23 100644 --- a/src/blackcore/inputmanager.cpp +++ b/src/blackcore/inputmanager.cpp @@ -30,7 +30,7 @@ namespace BlackCore reloadHotkeySettings(); } - void CInputManager::registerAction(const QString &action, const QPixmap &icon) + void CInputManager::registerAction(const QString &action, BlackMisc::CIcons::IconIndex icon) { if (!m_availableActions.contains(action)) { diff --git a/src/blackcore/inputmanager.h b/src/blackcore/inputmanager.h index aaff459a7..cf4fa625a 100644 --- a/src/blackcore/inputmanager.h +++ b/src/blackcore/inputmanager.h @@ -42,7 +42,7 @@ namespace BlackCore CInputManager(QObject *parent = nullptr); //! Register new action - void registerAction(const QString &action, const QPixmap &icon = BlackMisc::CIcons::empty16()); + void registerAction(const QString &action, BlackMisc::CIcons::IconIndex icon = BlackMisc::CIcons::StandardIconEmpty16); //! Register remote actions void registerRemoteActions(const QStringList &actions); @@ -79,7 +79,7 @@ namespace BlackCore QStringList allAvailableActions() const { return m_availableActions.keys(); } //! All actions and their icons (if any) - QMap allAvailableActionsAndIcons() const { return m_availableActions; } + QMap allAvailableActionsAndIcons() const { return m_availableActions; } //! Enable event forwarding to core void setForwarding(bool enabled) { m_actionRelayingEnabled = enabled; } @@ -138,7 +138,7 @@ namespace BlackCore std::unique_ptr m_keyboard; //!< keyboard std::unique_ptr m_joystick; //!< joystick - QMap m_availableActions; + QMap m_availableActions; QHash m_configuredActions; QSet m_activeActions; QVector m_boundActions; diff --git a/src/blackgui/components/settingshotkeycomponent.h b/src/blackgui/components/settingshotkeycomponent.h index f2d9beb98..457c031d6 100644 --- a/src/blackgui/components/settingshotkeycomponent.h +++ b/src/blackgui/components/settingshotkeycomponent.h @@ -64,7 +64,7 @@ namespace BlackGui QScopedPointer ui; Models::CActionHotkeyListModel m_model; //!< hotkeys model BlackMisc::CSetting m_actionHotkeys { this, &CSettingsHotkeyComponent::reloadHotkeysFromSettings }; - BlackCore::CActionBind m_action { "/Test/Message", BlackMisc::CIcons::wrench16(), this, &CSettingsHotkeyComponent::hotkeySlot }; + BlackCore::CActionBind m_action { "/Test/Message", BlackMisc::CIcons::StandardIconWrench16, this, &CSettingsHotkeyComponent::hotkeySlot }; }; /** diff --git a/src/blackgui/guiactionbind.cpp b/src/blackgui/guiactionbind.cpp index b08b4b503..c2be4b60d 100644 --- a/src/blackgui/guiactionbind.cpp +++ b/src/blackgui/guiactionbind.cpp @@ -49,7 +49,10 @@ namespace BlackGui const bool hasIcon = !action->icon().isNull(); CGuiActionBindHandler *bindHandler = new CGuiActionBindHandler(action); - CActionBinding actionBinding(CActionBinding::create(pathNew, hasIcon ? action->icon().pixmap(CIcons::empty16().size()) : CIcons::empty16(), bindHandler, &CGuiActionBindHandler::boundFunction, [bindHandler]() { CGuiActionBindHandler::actionBindWasDestroyed(bindHandler); })); + // MS 2019-10-08 [AFV integration] CActionBind constructor needs an icon index, not a QPixmap + //CActionBinding actionBinding(CActionBinding::create(pathNew, hasIcon ? action->icon().pixmap(CIcons::empty16().size()) : CIcons::empty16(), bindHandler, &CGuiActionBindHandler::boundFunction, [bindHandler]() { CGuiActionBindHandler::actionBindWasDestroyed(bindHandler); })); + CActionBinding actionBinding(CActionBinding::create(pathNew, CIcons::StandardIconEmpty16, bindHandler, &CGuiActionBindHandler::boundFunction, [bindHandler]() { CGuiActionBindHandler::actionBindWasDestroyed(bindHandler); })); + Q_UNUSED(hasIcon) bindHandler->m_index = actionBinding->getIndex(); boundActions.append(actionBinding); // takes ownership } @@ -64,7 +67,10 @@ namespace BlackGui CGuiActionBindHandler::appendPath(path, button->text()).remove('&'); // remove E&xit key codes CGuiActionBindHandler *bindHandler = new CGuiActionBindHandler(button); const bool hasIcon = !button->icon().isNull(); - CActionBinding actionBinding(CActionBinding::create(pathNew, hasIcon ? button->icon().pixmap(CIcons::empty16().size()) : CIcons::empty16(), bindHandler, &CGuiActionBindHandler::boundFunction, [bindHandler]() { CGuiActionBindHandler::actionBindWasDestroyed(bindHandler); })); + // MS 2019-10-08 [AFV integration] CActionBind constructor needs an icon index, not a QPixmap + //CActionBinding actionBinding(CActionBinding::create(pathNew, hasIcon ? button->icon().pixmap(CIcons::empty16().size()) : CIcons::empty16(), bindHandler, &CGuiActionBindHandler::boundFunction, [bindHandler]() { CGuiActionBindHandler::actionBindWasDestroyed(bindHandler); })); + CActionBinding actionBinding(CActionBinding::create(pathNew, CIcons::StandardIconEmpty16, bindHandler, &CGuiActionBindHandler::boundFunction, [bindHandler]() { CGuiActionBindHandler::actionBindWasDestroyed(bindHandler); })); + Q_UNUSED(hasIcon) bindHandler->m_index = actionBinding->getIndex(); return actionBinding; } diff --git a/src/blackgui/models/actionitem.cpp b/src/blackgui/models/actionitem.cpp index f47c0b9a8..67566544b 100644 --- a/src/blackgui/models/actionitem.cpp +++ b/src/blackgui/models/actionitem.cpp @@ -9,6 +9,8 @@ #include "blackgui/models/actionitem.h" #include +using namespace BlackMisc; + namespace BlackGui { namespace Models @@ -21,6 +23,10 @@ namespace BlackGui m_action(action), m_actionName(name), m_icon(icon), m_parentItem(parentItem) { } + CActionItem::CActionItem(const QString &action, const QString &name, CIcons::IconIndex icon, CActionItem *parentItem) : + m_action(action), m_actionName(name), m_icon(CIcons::pixmapByIndex(icon)), m_parentItem(parentItem) + { } + CActionItem::~CActionItem() { qDeleteAll(m_childItems); diff --git a/src/blackgui/models/actionitem.h b/src/blackgui/models/actionitem.h index d0f40c940..e3a3858d6 100644 --- a/src/blackgui/models/actionitem.h +++ b/src/blackgui/models/actionitem.h @@ -11,6 +11,7 @@ #ifndef BLACKGUI_MODELS_ACTIONITEM_H #define BLACKGUI_MODELS_ACTIONITEM_H +#include "blackmisc/icons.h" #include #include #include @@ -29,6 +30,9 @@ namespace BlackGui //! Constructor CActionItem(const QString &action, const QString &name, const QPixmap &icon, CActionItem *parentItem = nullptr); + //! Constructor + CActionItem(const QString &action, const QString &name, BlackMisc::CIcons::IconIndex icon, CActionItem *parentItem = nullptr); + //! Destructor ~CActionItem(); diff --git a/src/blackgui/models/actionmodel.cpp b/src/blackgui/models/actionmodel.cpp index b5f578978..c2143da39 100644 --- a/src/blackgui/models/actionmodel.cpp +++ b/src/blackgui/models/actionmodel.cpp @@ -103,7 +103,7 @@ namespace BlackGui m_rootItem.reset(new CActionItem(QString(), QString())); Q_ASSERT_X(sApp && sApp->getInputManager(), Q_FUNC_INFO, "Missing input manager"); - const QMap availableActionsAndIcons = sApp->getInputManager()->allAvailableActionsAndIcons(); + const QMap availableActionsAndIcons = sApp->getInputManager()->allAvailableActionsAndIcons(); QStringList keys = availableActionsAndIcons.keys(); keys.sort(); for (const QString &actionPath : as_const(keys)) @@ -118,7 +118,7 @@ namespace BlackGui if (child == nullptr) { const bool isAction = currentPath == actionPath; // action istelf, or just a node? - const QPixmap icon = isAction ? availableActionsAndIcons[actionPath] : CIcons::empty16(); + const BlackMisc::CIcons::IconIndex icon = isAction ? availableActionsAndIcons[actionPath] : CIcons::StandardIconEmpty16; child = new CActionItem(isAction ? actionPath : "", token, icon, parentItem); parentItem->appendChild(child); } diff --git a/src/blackmisc/input/actionhotkeydefs.cpp b/src/blackmisc/input/actionhotkeydefs.cpp index f5b8acfbb..5e31fe395 100644 --- a/src/blackmisc/input/actionhotkeydefs.cpp +++ b/src/blackmisc/input/actionhotkeydefs.cpp @@ -18,9 +18,9 @@ namespace BlackMisc return s; } - const QPixmap &pttHotkeyIcon() + CIcons::IconIndex pttHotkeyIcon() { - return CIcons::radio16(); + return CIcons::StandardIconRadio16; } const QString &pttCom1HotkeyAction() @@ -35,14 +35,14 @@ namespace BlackMisc return s; } - const QPixmap &audioVolumeDecreaseHotkeyIcon() + CIcons::IconIndex audioVolumeDecreaseHotkeyIcon() { - return CIcons::volumeLow16(); + return CIcons::StandardIconVolumeLow16; } - const QPixmap &audioVolumeIncreaseHotkeyIcon() + CIcons::IconIndex audioVolumeIncreaseHotkeyIcon() { - return CIcons::volumeHigh16(); + return CIcons::StandardIconVolumeHigh16; } const QString &audioVolumeDecreaseHotkeyAction() @@ -57,14 +57,14 @@ namespace BlackMisc return s; } - const QPixmap &toggleXPDRStateHotkeyIcon() + CIcons::IconIndex toggleXPDRStateHotkeyIcon() { - return CIcons::radio16(); + return CIcons::StandardIconRadio16; } - const QPixmap &toggleXPDRIdentHotkeyIcon() + CIcons::IconIndex toggleXPDRIdentHotkeyIcon() { - return CIcons::radio16(); + return CIcons::StandardIconRadio16; } const QString &toggleXPDRStateHotkeyAction() diff --git a/src/blackmisc/input/actionhotkeydefs.h b/src/blackmisc/input/actionhotkeydefs.h index 089c5fa6b..7b472cb86 100644 --- a/src/blackmisc/input/actionhotkeydefs.h +++ b/src/blackmisc/input/actionhotkeydefs.h @@ -11,7 +11,7 @@ #ifndef BLACKMISC_INPUT_ACTIONHOTKEYDEFS_H #define BLACKMISC_INPUT_ACTIONHOTKEYDEFS_H -#include "blackmisc/icon.h" +#include "blackmisc/icons.h" #include "blackmisc/blackmiscexport.h" #include @@ -30,7 +30,7 @@ namespace BlackMisc BLACKMISC_EXPORT const QString &pttCom2HotkeyAction(); //! PTT key - BLACKMISC_EXPORT const QPixmap &pttHotkeyIcon(); + BLACKMISC_EXPORT BlackMisc::CIcons::IconIndex pttHotkeyIcon(); //! Audio volume + key BLACKMISC_EXPORT const QString &audioVolumeIncreaseHotkeyAction(); @@ -39,22 +39,22 @@ namespace BlackMisc BLACKMISC_EXPORT const QString &audioVolumeDecreaseHotkeyAction(); //! Audio icon volume + - BLACKMISC_EXPORT const QPixmap &audioVolumeIncreaseHotkeyIcon(); + BLACKMISC_EXPORT BlackMisc::CIcons::IconIndex audioVolumeIncreaseHotkeyIcon(); //! Audio icon volume - - BLACKMISC_EXPORT const QPixmap &audioVolumeDecreaseHotkeyIcon(); + BLACKMISC_EXPORT BlackMisc::CIcons::IconIndex audioVolumeDecreaseHotkeyIcon(); //! XPDR state BLACKMISC_EXPORT const QString &toggleXPDRStateHotkeyAction(); //! XPDR state - BLACKMISC_EXPORT const QPixmap &toggleXPDRStateHotkeyIcon(); + BLACKMISC_EXPORT BlackMisc::CIcons::IconIndex toggleXPDRStateHotkeyIcon(); //! XPDR state BLACKMISC_EXPORT const QString &toggleXPDRIdentHotkeyAction(); //! XPDR ident - BLACKMISC_EXPORT const QPixmap &toggleXPDRIdentHotkeyIcon(); + BLACKMISC_EXPORT BlackMisc::CIcons::IconIndex toggleXPDRIdentHotkeyIcon(); } // ns } // ns diff --git a/src/swiftguistandard/swiftguistd.h b/src/swiftguistandard/swiftguistd.h index f08cfbe6f..45546e45f 100644 --- a/src/swiftguistandard/swiftguistd.h +++ b/src/swiftguistandard/swiftguistd.h @@ -122,7 +122,7 @@ private: QScopedPointer m_mapDialog; //!< map dialog QScopedPointer m_validationDialog; //!< aircraft model validation dialog BlackMisc::CData m_lastAutoPublish { this }; - BlackCore::CActionBind m_actionPtt { BlackMisc::Input::pttHotkeyAction(), BlackMisc::CIcons::radio16(), this, &SwiftGuiStd::onPttChanged }; + BlackCore::CActionBind m_actionPtt { BlackMisc::Input::pttHotkeyAction(), BlackMisc::CIcons::StandardIconRadio16, this, &SwiftGuiStd::onPttChanged }; BlackCore::CActionBindings m_menuHotkeyHandlers; BlackGui::CManagedStatusBar m_statusBar; BlackMisc::CLogSubscriber m_logSubscriber { this, &SwiftGuiStd::displayStatusMessageInGui }; diff --git a/src/swiftguistandard/swiftguistdmenus.cpp b/src/swiftguistandard/swiftguistdmenus.cpp index fc812edef..9086c82aa 100644 --- a/src/swiftguistandard/swiftguistdmenus.cpp +++ b/src/swiftguistandard/swiftguistdmenus.cpp @@ -167,7 +167,7 @@ void SwiftGuiStd::initMenus() // for hotkeys const QString swift(CGuiActionBindHandler::pathSwiftPilotClient()); - static const CActionBind swiftRoot(swift, CIcons::swift16()); // inserts action for root folder + static const CActionBind swiftRoot(swift, CIcons::Swift16); // inserts action for root folder Q_UNUSED(swiftRoot) m_menuHotkeyHandlers.append(CGuiActionBindHandler::bindMenu(ui->menu_InfoAreas, swift + "Info areas")); m_menuHotkeyHandlers.append(CGuiActionBindHandler::bindMenu(ui->menu_File, swift + "File"));