6#include <QAbstractItemModel>
8#include <QItemSelectionModel>
12#include <QModelIndexList>
19#include "ui_settingshotkeycomponent.h"
31using namespace swift::misc::input;
34using namespace swift::core::context;
41 Q_ASSERT_X(sGui, Q_FUNC_INFO,
"Missing sGui");
43 ui->tv_Hotkeys->setModel(&m_model);
51 ui->tv_Hotkeys->selectRow(0);
64 Q_ASSERT_X(sApp && sApp->getInputManager(), Q_FUNC_INFO,
"Missing input manager");
65 sApp->getInputManager()->registerAction(pttHotkeyAction(), pttHotkeyIcon());
68 void CSettingsHotkeyComponent::addEntry()
72 if (selectedActionHotkey.
isValid() && checkAndConfirmConflicts(selectedActionHotkey))
74 addHotkeyToSettings(selectedActionHotkey);
75 const int position = m_model.
rowCount();
87 void CSettingsHotkeyComponent::editEntry()
89 const auto index = ui->tv_Hotkeys->selectionModel()->currentIndex();
95 const auto model = ui->tv_Hotkeys->model();
99 const auto actionHotkey = indexHotkey.
data(CActionHotkeyListModel::ActionHotkeyRole).
value<
CActionHotkey>();
102 if (selectedActionHotkey.isValid() && checkAndConfirmConflicts(selectedActionHotkey, { actionHotkey }))
104 updateHotkeyInSettings(actionHotkey, selectedActionHotkey);
106 CActionHotkeyListModel::ActionHotkeyRole);
109 CLogMessage(
this).debug(u
"%1, edited key: '%2'")
115 void CSettingsHotkeyComponent::removeEntry()
117 const QModelIndexList indexes = ui->tv_Hotkeys->selectionModel()->selectedRows();
118 for (
const auto &index : indexes)
120 const auto actionHotkey = index.
data(CActionHotkeyListModel::ActionHotkeyRole).
value<CActionHotkey>();
121 removeHotkeyFromSettings(actionHotkey);
122 m_model.removeRows(index.
row(), 1, QModelIndex());
127 void CSettingsHotkeyComponent::addHotkeyToSettings(
const CActionHotkey &actionHotkey)
129 CActionHotkeyList actionHotkeyList(m_actionHotkeys.getThreadLocal());
130 actionHotkeyList.push_back(actionHotkey);
131 m_actionHotkeys.set(actionHotkeyList);
134 void CSettingsHotkeyComponent::updateHotkeyInSettings(
const CActionHotkey &oldValue,
const CActionHotkey &newValue)
137 this->removeHotkeyFromSettings(oldValue);
138 this->addHotkeyToSettings(newValue);
145 void CSettingsHotkeyComponent::removeHotkeyFromSettings(
const CActionHotkey &actionHotkey)
147 CActionHotkeyList actionHotkeyList(m_actionHotkeys.getThreadLocal());
148 actionHotkeyList.remove(actionHotkey);
149 m_actionHotkeys.set(actionHotkeyList);
152 bool CSettingsHotkeyComponent::checkAndConfirmConflicts(
const CActionHotkey &actionHotkey,
153 const CActionHotkeyList &ignore)
157 const CActionHotkeyList configuredHotkeysSameMachine =
158 m_actionHotkeys.getThreadLocal().findBySameMachine(actionHotkey);
159 CActionHotkeyList conflicts = configuredHotkeysSameMachine.
findSupersetsOf(actionHotkey);
166 QStringLiteral(
"The selected combination conflicts with the following %1 combination(s):\n\n")
167 .arg(conflicts.
size());
168 for (
const CActionHotkey &conflict : conflicts)
170 message += conflict.toQString();
173 message +=
"\n Do you want to use it anway?";
192 const int position = m_model.rowCount();
195 m_model.setData(index,
QVariant::fromValue(hotkey), CActionHotkeyListModel::ActionHotkeyRole);
203 if (!sGui || !sGui->getIContextApplication())
207 if (sGui->getIContextApplication())
209 identifiers = sGui->getIContextApplication()->getRegisteredApplications();
217 void CSettingsHotkeyComponent::resizeView() { ui->tv_Hotkeys->resizeRowsToContents(); }
219 void CSettingsHotkeyComponent::hotkeySlot(
bool keyDown)
223 auto *msgBox =
new QMessageBox(
this);
226 msgBox->setWindowTitle(
"Test");
227 msgBox->setText(
"Hotkey test");
229 msgBox->setModal(
false);
236 Q_ASSERT_X(m_config, Q_FUNC_INFO,
"Missing configuration");
241 m_config->saveSettings();
247 Q_ASSERT_X(m_config, Q_FUNC_INFO,
"Missing configuration");
248 m_config->reloadHotkeysFromSettings();
static bool lastWizardStepSkipped(const QWizard *standardWizard)
Static version of CConfigurationWizard::lastStepSkipped.
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.
void registerDummyPttEntry()
Create dummy/emtpy Ptt entry for wizard.
~CSettingsHotkeyComponent()
Destructor.
CSettingsHotkeyComponent(QWidget *parent=nullptr)
Constructor.
void saveSettings()
Save settings.
void reloadHotkeysFromSettings()
Reload keys from settings.
int rowCount(const QModelIndex &parent=QModelIndex()) const
bool setData(const QModelIndex &index, const QVariant &var, int role)
bool insertRows(int position, int rows, const QModelIndex &index)
Value object encapsulating information identifying a component of a modular distributed swift process...
Value object encapsulating a list of object identifiers.
Class for emitting a log message.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
Derived & debug()
Set the severity to debug.
size_type size() const
Returns number of elements in the sequence.
void replaceOrAdd(const T &original, const T &replacement)
Replace elements matching the given element. If there is no match, push the new element on the end.
void push_back(const T &value)
Appends an element at the end of the sequence.
void clear()
Removes all elements in the sequence.
int removeIfIn(const CSequence &other)
Remove all elements if they are in other.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
QString toQString(bool i18n=false) const
Cast as QString.
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.
QString classNameShort(const QObject *object)
Class name as from QMetaObject::className without namespace.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
QFrame(QWidget *parent, Qt::WindowFlags f)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QVariant data(int role) const const
bool isValid() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
bool canConvert() const const
QVariant fromValue(T &&value)
QWizard * wizard() const const