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

@@ -11,7 +11,7 @@
#include "blackcore/context.h"
#include "blackcore/dbus_server.h"
#include "blackinput/keyboard.h"
#include "blackmisc/hwkeyboardkeylist.h"
#include "blackmisc/setkeyboardhotkeylist.h"
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/dbus.h"
#include "blackmisc/variant.h"
@@ -143,7 +143,7 @@ namespace BlackCore
virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const = 0;
//! Hotkeys
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const = 0;
virtual BlackMisc::Settings::CSettingKeyboardHotkeyList getHotkeys() const = 0;
//! Save settings
virtual BlackMisc::CStatusMessage write() const = 0;

View File

@@ -186,7 +186,7 @@ namespace BlackCore
/*
* Hotkeys
*/
CKeyboardKeyList CContextSettings::getHotkeys() const
CSettingKeyboardHotkeyList CContextSettings::getHotkeys() const
{
return this->m_hotkeys;
}
@@ -230,7 +230,7 @@ namespace BlackCore
{
if (command == CSettingUtilities::CmdUpdate())
{
BlackMisc::Hardware::CKeyboardKeyList hotkeys = value.value<BlackMisc::Hardware::CKeyboardKeyList>();
BlackMisc::Settings::CSettingKeyboardHotkeyList hotkeys = value.value<BlackMisc::Settings::CSettingKeyboardHotkeyList>();
this->m_hotkeys = hotkeys;
msgs.push_back(this->write()); // write settings
emit this->changedSettings(static_cast<uint>(SettingsHotKeys));

View File

@@ -60,7 +60,7 @@ namespace BlackCore
virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const override;
//! \copydoc IContextSettings::getHotkeys()
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override;
virtual BlackMisc::Settings::CSettingKeyboardHotkeyList getHotkeys() const override;
//! read settings
virtual BlackMisc::CStatusMessage read() override;
@@ -81,7 +81,7 @@ namespace BlackCore
BlackMisc::Settings::CSettingsNetwork m_settingsNetwork;
BlackMisc::Settings::CSettingsAudio m_settingsAudio;
BlackSim::Settings::CSettingsSimulator m_settingsSimulator;
BlackMisc::Hardware::CKeyboardKeyList m_hotkeys;
BlackMisc::Settings::CSettingKeyboardHotkeyList m_hotkeys;
QJsonDocument toJsonDocument() const;
void emitCompletelyChanged();
};

View File

@@ -69,9 +69,9 @@ namespace BlackCore
/*
* Relay to DBus
*/
CKeyboardKeyList CContextSettingsProxy::getHotkeys() const
CSettingKeyboardHotkeyList CContextSettingsProxy::getHotkeys() const
{
return this->m_dBusInterface->callDBusRet<CKeyboardKeyList>(QLatin1Literal("getHotkeys"));
return this->m_dBusInterface->callDBusRet<CSettingKeyboardHotkeyList>(QLatin1Literal("getHotkeys"));
}
/*

View File

@@ -55,7 +55,7 @@ namespace BlackCore
virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const override;
//! \copydoc IContextSettings::getHotkeys()
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override;
virtual Settings::CSettingKeyboardHotkeyList getHotkeys() const override;
//! \copydoc IContextSettings::value
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value) override;

View File

@@ -323,10 +323,10 @@ namespace BlackGui
{
QModelIndex i = this->ui->tvp_SettingsMiscHotkeys->currentIndex();
if (i.row() < 0 || i.row() >= this->ui->tvp_SettingsMiscHotkeys->rowCount()) return;
BlackMisc::Hardware::CKeyboardKey key = this->ui->tvp_SettingsMiscHotkeys->at<BlackMisc::Hardware::CKeyboardKey>(i);
BlackMisc::Hardware::CKeyboardKey defaultKey;
defaultKey.setFunction(key.getFunction());
this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultKey);
CSettingKeyboardHotkey hotkey = this->ui->tvp_SettingsMiscHotkeys->at<CSettingKeyboardHotkey>(i);
CSettingKeyboardHotkey defaultHotkey;
defaultHotkey.setFunction(hotkey.getFunction());
this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultHotkey);
}
/*

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

View File

@@ -21,7 +21,7 @@ namespace BlackGui
{
this->m_model = new CKeyboardKeyListModel(this);
this->setModel(this->m_model); // via QTableView
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Hardware::CKeyboardKey::IndexFunctionAsString);
this->m_model->setSortColumnByPropertyIndex(BlackMisc::Settings::CSettingKeyboardHotkey::IndexFunctionAsString);
if (this->m_model->hasValidSortColumn())
this->horizontalHeader()->setSortIndicator(
this->m_model->getSortColumn(),

View File

@@ -527,17 +527,17 @@ void MainWindow::ps_registerHotkeyFunctions()
m_inputManager->registerHotkeyFunc(CHotkeyFunction::Opacity50(), this, [ this ](bool isPressed)
{
if (isPressed) this->changeWindowOpacity(50);
if (isPressed) this->ps_changeWindowOpacity(50);
});
m_inputManager->registerHotkeyFunc(CHotkeyFunction::Opacity100(), this, [ this ](bool isPressed)
{
if (isPressed) this->changeWindowOpacity(100);
if (isPressed) this->ps_changeWindowOpacity(100);
});
m_inputManager->registerHotkeyFunc(CHotkeyFunction::ToogleWindowsStayOnTop(), this, [ this ](bool isPressed)
{
if (isPressed) this->toogleWindowStayOnTop();
if (isPressed) this->ps_toogleWindowStayOnTop();
});
}