mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
[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.
This commit is contained in:
@@ -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 {}; }
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace BlackCore
|
||||
|
||||
//! Constructor
|
||||
template <typename Receiver>
|
||||
CActionBind(const QString &action, const QPixmap &icon, Receiver *receiver,
|
||||
CActionBind(const QString &action, BlackMisc::CIcons::IconIndex icon, Receiver *receiver,
|
||||
MembFunc<Receiver> slot = nullptr,
|
||||
const std::function<void()> &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<void()> m_deleteCallback; //!< called when deleted
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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<QString, QPixmap> allAvailableActionsAndIcons() const { return m_availableActions; }
|
||||
QMap<QString, BlackMisc::CIcons::IconIndex> 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<BlackInput::IKeyboard> m_keyboard; //!< keyboard
|
||||
std::unique_ptr<BlackInput::IJoystick> m_joystick; //!< joystick
|
||||
|
||||
QMap<QString, QPixmap> m_availableActions;
|
||||
QMap<QString, BlackMisc::CIcons::IconIndex> m_availableActions;
|
||||
QHash<BlackMisc::Input::CHotkeyCombination, QString> m_configuredActions;
|
||||
QSet<QString> m_activeActions;
|
||||
QVector<BindInfo> m_boundActions;
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace BlackGui
|
||||
QScopedPointer<Ui::CSettingsHotkeyComponent> ui;
|
||||
Models::CActionHotkeyListModel m_model; //!< hotkeys model
|
||||
BlackMisc::CSetting<BlackCore::Application::TActionHotkeys> 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 };
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "blackgui/models/actionitem.h"
|
||||
#include <QtAlgorithms>
|
||||
|
||||
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);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#ifndef BLACKGUI_MODELS_ACTIONITEM_H
|
||||
#define BLACKGUI_MODELS_ACTIONITEM_H
|
||||
|
||||
#include "blackmisc/icons.h"
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QPixmap>
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<QString, QPixmap> availableActionsAndIcons = sApp->getInputManager()->allAvailableActionsAndIcons();
|
||||
const QMap<QString, BlackMisc::CIcons::IconIndex> 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);
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 <QString>
|
||||
@@ -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
|
||||
|
||||
@@ -122,7 +122,7 @@ private:
|
||||
QScopedPointer<BlackGui::Components::CAfvMapDialog> m_mapDialog; //!< map dialog
|
||||
QScopedPointer<BlackGui::Components::CAircraftModelSetValidationDialog> m_validationDialog; //!< aircraft model validation dialog
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TLastAutoPublish> 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 };
|
||||
|
||||
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user