6 #include <QAbstractItemModel>
8 #include <QItemSelectionModel>
10 #include <QMessageBox>
11 #include <QModelIndex>
12 #include <QModelIndexList>
13 #include <QPushButton>
19 #include "ui_settingshotkeycomponent.h"
31 using namespace swift::misc::input;
34 using namespace swift::core::context;
38 CSettingsHotkeyComponent::CSettingsHotkeyComponent(QWidget *parent)
41 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing sGui");
43 ui->tv_Hotkeys->setModel(&m_model);
45 connect(ui->pb_AddHotkey, &QPushButton::clicked,
this, &CSettingsHotkeyComponent::addEntry);
46 connect(ui->pb_EditHotkey, &QPushButton::clicked,
this, &CSettingsHotkeyComponent::editEntry);
47 connect(ui->pb_RemoveHotkey, &QPushButton::clicked,
this, &CSettingsHotkeyComponent::removeEntry);
51 ui->tv_Hotkeys->selectRow(0);
68 void CSettingsHotkeyComponent::addEntry()
72 if (selectedActionHotkey.
isValid() && checkAndConfirmConflicts(selectedActionHotkey))
74 addHotkeyToSettings(selectedActionHotkey);
75 const int position = m_model.
rowCount();
76 m_model.
insertRows(position, 1, QModelIndex());
77 const QModelIndex index = m_model.index(position, 0, QModelIndex());
78 m_model.
setData(index, QVariant::fromValue(selectedActionHotkey), CActionHotkeyListModel::ActionHotkeyRole);
87 void CSettingsHotkeyComponent::editEntry()
89 const auto index = ui->tv_Hotkeys->selectionModel()->currentIndex();
90 if (!index.isValid()) {
return; }
92 const auto model = ui->tv_Hotkeys->model();
93 const QModelIndex indexHotkey = model->index(index.row(), 0, QModelIndex());
94 Q_ASSERT_X(indexHotkey.data(CActionHotkeyListModel::ActionHotkeyRole).canConvert<
CActionHotkey>(), Q_FUNC_INFO,
97 indexHotkey.data(CActionHotkeyListModel::ActionHotkeyRole).value<
CActionHotkey>();
100 if (selectedActionHotkey.isValid() && checkAndConfirmConflicts(selectedActionHotkey, { actionHotkey }))
102 updateHotkeyInSettings(actionHotkey, selectedActionHotkey);
103 m_model.
setData(indexHotkey, QVariant::fromValue(selectedActionHotkey),
104 CActionHotkeyListModel::ActionHotkeyRole);
113 void CSettingsHotkeyComponent::removeEntry()
115 const QModelIndexList indexes = ui->tv_Hotkeys->selectionModel()->selectedRows();
116 for (
const auto &index : indexes)
119 index.data(CActionHotkeyListModel::ActionHotkeyRole).value<
CActionHotkey>();
120 removeHotkeyFromSettings(actionHotkey);
121 m_model.
removeRows(index.row(), 1, QModelIndex());
126 void CSettingsHotkeyComponent::addHotkeyToSettings(
const CActionHotkey &actionHotkey)
129 actionHotkeyList.push_back(actionHotkey);
130 m_actionHotkeys.
set(actionHotkeyList);
136 this->removeHotkeyFromSettings(oldValue);
137 this->addHotkeyToSettings(newValue);
144 void CSettingsHotkeyComponent::removeHotkeyFromSettings(
const CActionHotkey &actionHotkey)
147 actionHotkeyList.remove(actionHotkey);
148 m_actionHotkeys.
set(actionHotkeyList);
151 bool CSettingsHotkeyComponent::checkAndConfirmConflicts(
const CActionHotkey &actionHotkey,
165 QStringLiteral(
"The selected combination conflicts with the following %1 combination(s):\n\n")
166 .arg(conflicts.
size());
169 message += conflict.toQString();
172 message +=
"\n Do you want to use it anway?";
173 const auto reply = QMessageBox::warning(
this,
"SettingsHotkeyComponent", message,
174 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
175 if (reply == QMessageBox::No) {
return false; }
188 const int position = m_model.
rowCount();
189 m_model.
insertRows(position, 1, QModelIndex());
190 const QModelIndex index = m_model.index(position, 0, QModelIndex());
191 m_model.
setData(index, QVariant::fromValue(hotkey), CActionHotkeyListModel::ActionHotkeyRole);
210 void CSettingsHotkeyComponent::resizeView() { ui->tv_Hotkeys->resizeRowsToContents(); }
212 void CSettingsHotkeyComponent::hotkeySlot(
bool keyDown)
216 QMessageBox *msgBox =
new QMessageBox(
this);
217 msgBox->setAttribute(Qt::WA_DeleteOnClose);
218 msgBox->setStandardButtons(QMessageBox::Ok);
219 msgBox->setWindowTitle(
"Test");
220 msgBox->setText(
"Hotkey test");
221 msgBox->setIcon(QMessageBox::Information);
222 msgBox->setModal(
false);
229 Q_ASSERT_X(m_config, Q_FUNC_INFO,
"Missing configuration");
237 Q_ASSERT_X(m_config, Q_FUNC_INFO,
"Missing configuration");
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.
virtual misc::CIdentifierList getRegisteredApplications() const =0
All registered applications.
virtual void initializePage()
virtual bool validatePage()
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.
virtual ~CSettingsHotkeyComponent()
Destructor.
void saveSettings()
Save settings.
void reloadHotkeysFromSettings()
Reload keys from settings.
bool removeRows(int position, int rows, const QModelIndex &index)
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)
CStatusMessage save()
Save using the currently set value. Must be called from the thread in which the owner lives.
CStatusMessage set(const T &value, qint64 timestamp=0)
Write a new value. Must be called from the thread in which the owner lives.
const T & getThreadLocal() const
Read the current value.
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.
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.
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.
QString classNameShort(const QObject *object)
Class name as from QMetaObject::className without namespace.