From f3148fdd49e5ba1e09640fbce77aaf0f5c7a1415 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 1 Apr 2014 12:18:11 +0200 Subject: [PATCH] refs #198 , changed keyboardkey classes so they can be initialized either by read settings or default values --- src/blackgui/keyboardkeylistmodel.h | 2 +- src/blackmisc/hwkeyboardkeylist.cpp | 25 ++++++++++++++++++------- src/blackmisc/hwkeyboardkeylist.h | 10 ++++++++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/blackgui/keyboardkeylistmodel.h b/src/blackgui/keyboardkeylistmodel.h index 467c60e6c..9feb544f7 100644 --- a/src/blackgui/keyboardkeylistmodel.h +++ b/src/blackgui/keyboardkeylistmodel.h @@ -27,7 +27,7 @@ namespace BlackGui //! \copydoc CListModelBase::data QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const override; - //! \copydoc BlackMisc::Hardware::CKeyboardKeyList::initAsHotkeyList + //! \copydoc CKeyboardKeyList::initAsHotkeyList(bool reset) void initAsHotkeyList() { this->m_container.initAsHotkeyList(); } //! \copydoc QAbstractTableModel::setData diff --git a/src/blackmisc/hwkeyboardkeylist.cpp b/src/blackmisc/hwkeyboardkeylist.cpp index 1c4743282..441d1b66f 100644 --- a/src/blackmisc/hwkeyboardkeylist.cpp +++ b/src/blackmisc/hwkeyboardkeylist.cpp @@ -22,6 +22,14 @@ namespace BlackMisc CSequence(baseClass) { } + /* + * Contains this hotkey function? + */ + bool CKeyboardKeyList::containsFunction(CKeyboardKey::HotkeyFunction key) + { + return CSequence::contains(&CKeyboardKey::getFunction, key); + } + /* * Register metadata */ @@ -35,14 +43,17 @@ namespace BlackMisc qDBusRegisterMetaType(); } - void CKeyboardKeyList::initAsHotkeyList() + /* + * Hotkey list + */ + void CKeyboardKeyList::initAsHotkeyList(bool reset) { - this->clear(); - this->push_back(CKeyboardKey(CKeyboardKey::HotkeyPtt)); - this->push_back(CKeyboardKey(CKeyboardKey::HotkeyOpacity50)); - this->push_back(CKeyboardKey(CKeyboardKey::HotkeyOpacity100)); - this->push_back(CKeyboardKey(CKeyboardKey::HotkeyToggleCom1)); - this->push_back(CKeyboardKey(CKeyboardKey::HotkeyToggleCom2)); + if (reset) this->clear(); + if (!this->containsFunction(CKeyboardKey::HotkeyPtt)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyPtt)); + if (!this->containsFunction(CKeyboardKey::HotkeyOpacity50)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyOpacity50)); + if (!this->containsFunction(CKeyboardKey::HotkeyOpacity100)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyOpacity100)); + if (!this->containsFunction(CKeyboardKey::HotkeyToggleCom1)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyToggleCom1)); + if (!this->containsFunction(CKeyboardKey::HotkeyToggleCom2)) this->push_back(CKeyboardKey(CKeyboardKey::HotkeyToggleCom2)); } } // namespace diff --git a/src/blackmisc/hwkeyboardkeylist.h b/src/blackmisc/hwkeyboardkeylist.h index 94e21c789..626a38ec8 100644 --- a/src/blackmisc/hwkeyboardkeylist.h +++ b/src/blackmisc/hwkeyboardkeylist.h @@ -37,11 +37,17 @@ namespace BlackMisc return QVariant::fromValue(*this); } + //! \brief contains given hotkey function? + bool containsFunction(CKeyboardKey::HotkeyFunction key); + //! \brief Register metadata static void registerMetadata(); - //! \brief Fill the list with hotkey - void initAsHotkeyList(); + /*! + * \brief Fill the list with hotkeys + * \param reset true, list will be be reset, otherwise value will not be overridde + */ + void initAsHotkeyList(bool reset = true); }; } //namespace