refs #313 Change GUI classes to use new hotkey settings wrapper classes

This commit is contained in:
Roland Winklmeier
2014-08-19 14:38:24 +02:00
parent 4d60ca3a87
commit f76e0bc957
11 changed files with 50 additions and 48 deletions

View File

@@ -15,7 +15,7 @@
#include <QEvent>
#include <QKeyEvent>
using namespace BlackMisc::Settings;
using namespace BlackMisc::Hardware;
namespace BlackGui
@@ -26,14 +26,14 @@ namespace BlackGui
* Constructor
*/
CKeyboardKeyListModel::CKeyboardKeyListModel(QObject *parent) :
CListModelBase<BlackMisc::Hardware::CKeyboardKey, BlackMisc::Hardware::CKeyboardKeyList>("ViewKeyboardKeyList", parent)
CListModelBase<CSettingKeyboardHotkey, CSettingKeyboardHotkeyList>("ViewKeyboardKeyList", parent)
{
this->m_columns.addColumn(CColumn("key", CKeyboardKey::IndexKeyAsStringRepresentation, true));
this->m_columns.addColumn(CColumn("modifier 1", CKeyboardKey::IndexModifier1AsString, true));
this->m_columns.addColumn(CColumn("modifier 2", CKeyboardKey::IndexModifier2AsString, true));
this->m_columns.addColumn(CColumn("function", CKeyboardKey::IndexFunctionAsString));
this->m_columns.addColumn(CColumn("key", CSettingKeyboardHotkey::IndexKeyAsStringRepresentation, true));
this->m_columns.addColumn(CColumn("modifier 1", CSettingKeyboardHotkey::IndexModifier1AsString, true));
this->m_columns.addColumn(CColumn("modifier 2", CSettingKeyboardHotkey::IndexModifier2AsString, true));
this->m_columns.addColumn(CColumn("function", CSettingKeyboardHotkey::IndexFunctionAsString));
this->setSortColumnByPropertyIndex(CKeyboardKey::IndexFunctionAsString);
this->setSortColumnByPropertyIndex(CSettingKeyboardHotkey::IndexFunctionAsString);
this->m_sortOrder = Qt::AscendingOrder;
// force strings for translation in resource files
@@ -57,21 +57,21 @@ namespace BlackGui
if (role == Qt::EditRole)
{
int pi = this->indexToPropertyIndex(index);
if (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier2 || pi == CKeyboardKey::IndexModifier1AsString || pi == CKeyboardKey::IndexModifier2AsString)
if (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier2 || pi == CSettingKeyboardHotkey::IndexModifier1AsString || pi == CSettingKeyboardHotkey::IndexModifier2AsString)
{
if (index.row() >= this->m_container.size()) return true;
CKeyboardKey key = this->m_container[index.row()];
CSettingKeyboardHotkey key = this->m_container[index.row()];
key.setPropertyByIndex(value, pi);
key.cleanup();
this->m_container[index.row()] = key;
return true;
}
else if (pi == CKeyboardKey::IndexKey || pi == CKeyboardKey::IndexKeyAsString || pi == CKeyboardKey::IndexKeyAsStringRepresentation)
else if (pi == CSettingKeyboardHotkey::IndexKey || pi == CSettingKeyboardHotkey::IndexKeyAsString || pi == CSettingKeyboardHotkey::IndexKeyAsStringRepresentation)
{
Q_ASSERT(value.canConvert<CKeyboardKey>());
Q_ASSERT(value.canConvert<CSettingKeyboardHotkey>());
if (index.row() >= this->m_container.size()) return true;
CKeyboardKey key = this->m_container[index.row()];
key.setPropertyByIndex(value, CKeyboardKey::IndexKeyObject);
CSettingKeyboardHotkey key = this->m_container[index.row()];
key.setPropertyByIndex(value, CSettingKeyboardHotkey::IndexObject);
key.cleanup();
this->m_container[index.row()] = key;
return true;
@@ -88,20 +88,20 @@ namespace BlackGui
if (index.row() < model->rowCount())
{
int pi = model->indexToPropertyIndex(index);
if (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier2 || pi == CKeyboardKey::IndexModifier1AsString || pi == CKeyboardKey::IndexModifier2AsString)
if (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier2 || pi == CSettingKeyboardHotkey::IndexModifier1AsString || pi == CSettingKeyboardHotkey::IndexModifier2AsString)
{
CKeyboardKey key = model->at(index);
QString v = (pi == CKeyboardKey::IndexModifier1 || pi == CKeyboardKey::IndexModifier1AsString) ? key.getModifier1AsString() : key.getModifier2AsString();
CSettingKeyboardHotkey key = model->at(index);
QString v = (pi == CSettingKeyboardHotkey::IndexModifier1 || pi == CSettingKeyboardHotkey::IndexModifier1AsString) ? key.getModifier1AsString() : key.getModifier2AsString();
QComboBox *edit = new QComboBox(parent);
edit->addItems(CKeyboardKey::modifiers());
edit->addItems(CSettingKeyboardHotkey::modifiers());
edit->setCurrentText(v);
return edit;
}
else if (pi == CKeyboardKey::IndexKey || pi == CKeyboardKey::IndexKeyAsString || pi == CKeyboardKey::IndexKeyAsStringRepresentation)
else if (pi == CSettingKeyboardHotkey::IndexKey || pi == CSettingKeyboardHotkey::IndexKeyAsString || pi == CSettingKeyboardHotkey::IndexKeyAsStringRepresentation)
{
CKeyboardKey key = model->at(index);
CKeyboardLineEdit *edit = new CKeyboardLineEdit(key, parent);
edit->setText(key.getKeyAsString());
CSettingKeyboardHotkey hotkey = model->at(index);
CKeyboardLineEdit *edit = new CKeyboardLineEdit(hotkey, parent);
edit->setText(hotkey.getKey().getKeyAsString());
return edit;
}
}
@@ -146,9 +146,10 @@ namespace BlackGui
{
const Qt::Key k = static_cast<Qt::Key>(event->key());
if (k == Qt::Key_Shift || k == Qt::Key_Control || k == Qt::Key_Meta || k == Qt::Key_Alt || k == Qt::Key_CapsLock || k == Qt::Key_NumLock || k == Qt::Key_ScrollLock) return;
this->m_key.setKey(k);
this->m_key.setNativeVirtualKey(event->nativeVirtualKey());
this->setText(CKeyboardKey::toStringRepresentation(event->key()));
BlackMisc::Hardware::CKeyboardKey key;
key.setKey(k);
this->m_hotkey.setKey(key);
this->setText(CSettingKeyboardHotkey::toStringRepresentation(event->key()));
}
}

View File

@@ -11,6 +11,7 @@
#define BLACKGUI_KEYBOARDKEYLISTMODEL_H
#include "blackmisc/hwkeyboardkeylist.h"
#include "blackmisc/setkeyboardhotkeylist.h"
#include "blackgui/models/listmodelbase.h"
#include <QAbstractItemModel>
#include <QDBusConnection>
@@ -24,7 +25,7 @@ namespace BlackGui
/*!
* Keyboard key list model
*/
class CKeyboardKeyListModel : public CListModelBase<BlackMisc::Hardware::CKeyboardKey, BlackMisc::Hardware::CKeyboardKeyList>
class CKeyboardKeyListModel : public CListModelBase<BlackMisc::Settings::CSettingKeyboardHotkey, BlackMisc::Settings::CSettingKeyboardHotkeyList>
{
public:
@@ -82,18 +83,18 @@ namespace BlackGui
public:
//! Constructor
CKeyboardLineEdit(BlackMisc::Hardware::CKeyboardKey &key, QWidget *parent = nullptr) :
QLineEdit(parent), m_key(key) { }
CKeyboardLineEdit(const BlackMisc::Settings::CSettingKeyboardHotkey &hotkey, QWidget *parent = nullptr) :
QLineEdit(parent), m_hotkey(hotkey) { }
//! get key
BlackMisc::Hardware::CKeyboardKey getKey() const { return this->m_key; }
const BlackMisc::Settings::CSettingKeyboardHotkey &getKey() const { return this->m_hotkey; }
protected:
//! Overriding and handling key press
virtual void keyPressEvent(QKeyEvent *event) override;
private:
BlackMisc::Hardware::CKeyboardKey m_key;
BlackMisc::Settings::CSettingKeyboardHotkey m_hotkey;
};
}
}

View File

@@ -16,7 +16,7 @@
#include "blackmisc/nwserverlist.h"
#include "blackmisc/nwuserlist.h"
#include "blackmisc/nwclientlist.h"
#include "blackmisc/hwkeyboardkeylist.h"
#include "blackmisc/setkeyboardhotkeylist.h"
#include "blackmisc/blackmiscfreefunctions.h"
namespace BlackGui
@@ -239,6 +239,6 @@ namespace BlackGui
template class CListModelBase<BlackMisc::Network::CServer, BlackMisc::Network::CServerList>;
template class CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>;
template class CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>;
template class CListModelBase<BlackMisc::Hardware::CKeyboardKey, BlackMisc::Hardware::CKeyboardKeyList>;
template class CListModelBase<BlackMisc::Settings::CSettingKeyboardHotkey, BlackMisc::Settings::CSettingKeyboardHotkeyList>;
}
} // namespace