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;
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)
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); }
101 &CHotkeyDialog::changeSelectedAction);
103 &CHotkeyDialog::changeApplicableMachine);
108 &CHotkeyDialog::combinationSelectionChanged);
110 &CHotkeyDialog::combinationSelectionFinished);
121 &CKeySelectionBox::updateSelectedIndex);
130 void CKeySelectionBox::updateSelectedIndex(
int index)
138 if (!
sGui) {
return; }
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)
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 auto *ksb =
new CKeySelectionBox(ui->qf_Advanced);
206 for (
const CKeyboardKey &supportedKey : allSupportedKeys)
209 if (select && supportedKey == keyboardKey) { currentIndex = ksb->count() - 1; }
212 ksb->setSelectedIndex(currentIndex);
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 auto *ksb =
new CKeySelectionBox(ui->qf_Advanced);
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();
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()
340 void CHotkeyDialog::advancedKeyChanged(
int oldIndex,
int newIndex)
342 const CKeySelectionBox *ksb = qobject_cast<CKeySelectionBox *>(
sender());
347 auto oldKey = ksb->itemData(oldIndex).value<
CKeyboardKey>();
348 auto newKey = ksb->itemData(newIndex).value<
CKeyboardKey>();
352 else { combination.replaceKey(oldKey, newKey); }
364 else { combination.replaceButton(oldButton, newButton); }
372 void CHotkeyDialog::selectAction()
378 for (
const QString &token : tokens)
381 const QModelIndexList indexList =
383 if (indexList.isEmpty()) {
return; }
384 parentIndex = indexList.first();
385 ui->tv_Actions->expand(parentIndex);
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.
~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.
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const const
void setCurrentIndex(int index)
void currentIndexChanged(int index)
QModelIndexList indexes() const const
virtual void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
virtual QLayoutItem * takeAt(int index)=0
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QObject * sender() const const
bool isEmpty() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
WindowContextHelpButtonHint
bool canConvert() const const
QVariant fromValue(T &&value)