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);
51 ui->tv_Hotkeys->selectRow(0);
59 CLogMessage::preformatted(msg);
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();
90 if (!index.
isValid()) {
return; }
92 const auto model = ui->tv_Hotkeys->model();
96 const auto actionHotkey = indexHotkey.
data(CActionHotkeyListModel::ActionHotkeyRole).
value<
CActionHotkey>();
99 if (selectedActionHotkey.isValid() && checkAndConfirmConflicts(selectedActionHotkey, { actionHotkey }))
101 updateHotkeyInSettings(actionHotkey, selectedActionHotkey);
103 CActionHotkeyListModel::ActionHotkeyRole);
112 void CSettingsHotkeyComponent::removeEntry()
114 const QModelIndexList indexes = ui->tv_Hotkeys->selectionModel()->selectedRows();
115 for (
const auto &index : indexes)
118 removeHotkeyFromSettings(actionHotkey);
124 void CSettingsHotkeyComponent::addHotkeyToSettings(
const CActionHotkey &actionHotkey)
127 actionHotkeyList.push_back(actionHotkey);
128 m_actionHotkeys.
set(actionHotkeyList);
134 this->removeHotkeyFromSettings(oldValue);
135 this->addHotkeyToSettings(newValue);
142 void CSettingsHotkeyComponent::removeHotkeyFromSettings(
const CActionHotkey &actionHotkey)
145 actionHotkeyList.remove(actionHotkey);
146 m_actionHotkeys.
set(actionHotkeyList);
149 bool CSettingsHotkeyComponent::checkAndConfirmConflicts(
const CActionHotkey &actionHotkey,
163 QStringLiteral(
"The selected combination conflicts with the following %1 combination(s):\n\n")
167 message += conflict.toQString();
170 message +=
"\n Do you want to use it anway?";
186 const int position = m_model.
rowCount();
208 void CSettingsHotkeyComponent::resizeView() { ui->tv_Hotkeys->resizeRowsToContents(); }
210 void CSettingsHotkeyComponent::hotkeySlot(
bool keyDown)
217 msgBox->setWindowTitle(
"Test");
218 msgBox->setText(
"Hotkey test");
220 msgBox->setModal(
false);
227 Q_ASSERT_X(m_config, Q_FUNC_INFO,
"Missing configuration");
235 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.
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.
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.
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.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
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)
QString arg(Args &&... args) const const
bool canConvert() const const
QVariant fromValue(T &&value)
QWizard * wizard() const const