8 #include <QItemSelection>
9 #include <QItemSelectionModel>
11 #include <QLayoutItem>
13 #include <QModelIndex>
14 #include <QModelIndexList>
15 #include <QPushButton>
17 #include <QStringList>
24 #include "ui_hotkeydialog.h"
38 using namespace swift::misc::input;
45 : QDialog(parent), ui(new Ui::
CHotkeyDialog), m_actionHotkey(actionHotkey), m_actionModel(this)
47 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
50 ui->qf_Advanced->hide();
52 ui->pb_AdvancedMode->setIcon(CIcons::arrowMediumSouth16());
53 ui->tv_Actions->setModel(&m_actionModel);
59 ui->pb_SelectedHotkey->setText(combination.
toQString());
62 else { ui->pb_SelectedHotkey->setToolTip(
"Press to select an new combination..."); }
70 registeredApplications.
push_back(appIdentifier);
74 machineIdentifiers.
push_back(registeredApplications);
80 for (
const CIdentifier &app : machineIdentifiersUnique)
82 ui->cb_Identifier->addItem(app.getMachineName(), QVariant::fromValue(app));
85 index = ui->cb_Identifier->count() - 1;
89 if (index < 0 && ui->cb_Identifier->count() > 0)
92 ui->cb_Identifier->setCurrentIndex(0);
94 else if (index != ui->cb_Identifier->currentIndex()) { ui->cb_Identifier->setCurrentIndex(index); }
96 connect(ui->pb_AdvancedMode, &QPushButton::clicked,
this, &CHotkeyDialog::advancedModeChanged);
97 connect(ui->pb_SelectedHotkey, &QPushButton::clicked,
this, &CHotkeyDialog::captureHotkey);
99 connect(ui->pb_Cancel, &QPushButton::clicked,
this, &CHotkeyDialog::reject);
100 connect(ui->tv_Actions->selectionModel(), &QItemSelectionModel::selectionChanged,
this,
101 &CHotkeyDialog::changeSelectedAction);
102 connect(ui->cb_Identifier, qOverload<int>(&QComboBox::currentIndexChanged),
this,
103 &CHotkeyDialog::changeApplicableMachine);
108 &CHotkeyDialog::combinationSelectionChanged);
110 &CHotkeyDialog::combinationSelectionFinished);
120 connect(
this, qOverload<int>(&CKeySelectionBox::currentIndexChanged),
this,
121 &CKeySelectionBox::updateSelectedIndex);
127 setCurrentIndex(m_oldIndex);
130 void CKeySelectionBox::updateSelectedIndex(
int index)
138 if (!
sGui) {
return; }
141 this->setStyleSheet(s);
148 editDialog.setWindowModality(Qt::WindowModal);
153 void CHotkeyDialog::advancedModeChanged()
156 if (!ui->qf_Advanced->isVisible())
158 setupAdvancedFrame();
159 ui->qf_Advanced->show();
160 ui->pb_AdvancedMode->setIcon(CIcons::arrowMediumNorth16());
164 ui->pb_AdvancedMode->setIcon(CIcons::arrowMediumSouth16());
165 ui->qf_Advanced->hide();
166 ui->gb_Hotkey->resize(0, 0);
170 void CHotkeyDialog::captureHotkey()
173 ui->pb_SelectedHotkey->setText(
"Press any key/button...");
174 ui->pb_SelectedHotkey->setToolTip({});
178 void CHotkeyDialog::combinationSelectionChanged(
const CHotkeyCombination &combination)
180 ui->pb_SelectedHotkey->setText(combination.
toQString());
184 void CHotkeyDialog::combinationSelectionFinished(
const CHotkeyCombination &combination)
190 void CHotkeyDialog::changeSelectedAction(
const QItemSelection &selected,
const QItemSelection &deselected)
193 if (selected.indexes().isEmpty()) {
return; }
194 const auto index = selected.indexes().first();
195 m_actionHotkey.
setAction(index.data(CActionModel::ActionRole).toString());
198 CKeySelectionBox *CHotkeyDialog::addSelectionBox(
const CKeyboardKeyList &allSupportedKeys,
201 int currentIndex = 0;
202 const bool select = !keyboardKey.
isUnknown();
204 CKeySelectionBox *ksb =
new CKeySelectionBox(ui->qf_Advanced);
205 ksb->addItem(noKeyButton(), QVariant::fromValue(
CKeyboardKey()));
206 for (
const CKeyboardKey &supportedKey : allSupportedKeys)
208 ksb->addItem(supportedKey.toQString(), QVariant::fromValue(supportedKey));
209 if (select && supportedKey == keyboardKey) { currentIndex = ksb->count() - 1; }
212 ksb->setSelectedIndex(currentIndex);
213 ksb->addItem(noKeyButton(), QVariant::fromValue(
CKeyboardKey()));
215 ui->qf_Advanced->layout()->addWidget(ksb);
216 const int position = ui->qf_Advanced->layout()->count() - 1;
217 ksb->setProperty(
"position", position);
223 CKeySelectionBox *CHotkeyDialog::addSelectionBox(
const CJoystickButtonList &allAvailableButtons,
226 int currentIndex = -1;
228 CKeySelectionBox *ksb =
new CKeySelectionBox(ui->qf_Advanced);
232 ksb->addItem(availableButton.toQString(), QVariant::fromValue(availableButton));
233 if (availableButton == joystickButton)
235 currentIndex = ksb->count() - 1;
240 ksb->setSelectedIndex(currentIndex);
241 ksb->addItem(noKeyButton(),
244 ui->qf_Advanced->layout()->addWidget(ksb);
245 const int position = ui->qf_Advanced->layout()->count() - 1;
246 ksb->setProperty(
"position", position);
252 void CHotkeyDialog::changeApplicableMachine(
int index)
255 const QVariant userData = ui->cb_Identifier->currentData();
274 if (m_actionHotkey.
getAction().isEmpty())
283 void CHotkeyDialog::synchronize()
285 synchronizeSimpleSelection();
286 synchronizeAdvancedSelection();
289 void CHotkeyDialog::synchronizeSimpleSelection()
292 ui->pb_SelectedHotkey->setText(combination.
toQString());
296 void CHotkeyDialog::synchronizeAdvancedSelection()
298 if (ui->qf_Advanced->isVisible()) { setupAdvancedFrame(); }
301 void CHotkeyDialog::setupAdvancedFrame()
304 this->clearAdvancedFrame();
305 const CKeyboardKeyList allSupportedKeys = CKeyboardKeyList::allSupportedKeys();
313 this->addSelectionBox(allSupportedKeys, keyboardKey);
320 this->addSelectionBox(allAvailableButtons, joystickButton);
325 if (c < 2) { this->addSelectionBox(allSupportedKeys); }
328 void CHotkeyDialog::clearAdvancedFrame()
330 QLayout *layout = ui->qf_Advanced->layout();
333 while ((child = layout->takeAt(0)) !=
nullptr)
335 if (child->widget()) child->widget()->deleteLater();
340 void CHotkeyDialog::advancedKeyChanged(
int oldIndex,
int newIndex)
342 const CKeySelectionBox *ksb = qobject_cast<CKeySelectionBox *>(sender());
352 else { combination.replaceKey(oldKey, newKey); }
364 else { combination.replaceButton(oldButton, newButton); }
372 void CHotkeyDialog::selectAction()
374 if (m_actionHotkey.
getAction().isEmpty()) {
return; }
375 const QStringList tokens = m_actionHotkey.
getAction().split(
"/", Qt::SkipEmptyParts);
376 QModelIndex parentIndex = QModelIndex();
378 for (
const QString &token : tokens)
380 const QModelIndex startIndex = m_actionModel.
index(0, 0, parentIndex);
381 const QModelIndexList indexList =
382 m_actionModel.match(startIndex, Qt::DisplayRole, QVariant::fromValue(token));
383 if (indexList.isEmpty()) {
return; }
384 parentIndex = indexList.first();
385 ui->tv_Actions->expand(parentIndex);
388 QItemSelectionModel *selectionModel = ui->tv_Actions->selectionModel();
389 selectionModel->select(parentIndex, QItemSelectionModel::Select);
392 const QString &CHotkeyDialog::noKeyButton()
394 static const QString k =
"[none]";
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
CInputManager * getInputManager() const
The input manager, if available.
const context::IContextApplication * getIContextApplication() const
Direct access to contexts if a CCoreFacade has been initialized.
bool isShuttingDown() const
Is application shutting down?
virtual misc::CIdentifier getApplicationIdentifier() const =0
Identifier of application, remote side if distributed.
virtual misc::CIdentifierList getRegisteredApplications() const =0
All registered applications.
const CStyleSheetUtility & getStyleSheetUtility() const
Style sheet handling.
static const QString & fileNameStandardWidget()
File name for standard widgets.
QString styles(const QStringList &fileNames) const
Multiple styles concatenated.
static const QString & fileNameFonts()
File name fonts.qss.
void initStyleSheet()
Init style sheet.
swift::misc::input::CActionHotkey getSelectedActionHotkey() const
Get hotkey selected by user.
static swift::misc::input::CActionHotkey getActionHotkey(const swift::misc::input::CActionHotkey &initial, const swift::misc::CIdentifierList &identifiers, QWidget *parent=nullptr)
Runs the hotkey dialog and returns the result.
virtual ~CHotkeyDialog()
Destructor.
CKeySelectionBox(QWidget *parent=nullptr)
Constructor.
void keySelectionChanged(int oldIndex, int newIndex)
User has changed the selection.
void setSelectedIndex(int index)
Set key with index as selected.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Value object encapsulating information identifying a component of a modular distributed swift process...
const QString & getMachineName() const
Machine name.
bool hasSameMachineName(const CIdentifier &other) const
Check if the other identifier has the same machine name.
Value object encapsulating a list of object identifiers.
CIdentifierList getMachinesUnique() const
Get a list of identifiers reduced to maximum one per machine. If there is more than one per machine,...
Class for emitting a log message.
Derived & validationWarning(const char16_t(&format)[N])
Set the severity to warning, providing a format string, and adding the validation category.
void push_back(const T &value)
Appends an element at the end of the sequence.
QString toQString(bool i18n=false) const
Cast as QString.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Models to be used with views, mainly QTableView.
Free functions in swift::misc.