mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-09 21:42:13 +00:00
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
#include "shortcutsetting.hpp"
|
|
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QWidget>
|
|
|
|
#include "state.hpp"
|
|
#include "shortcutmanager.hpp"
|
|
|
|
namespace CSMPrefs
|
|
{
|
|
ShortcutSetting::ShortcutSetting(Category* parent, Settings::Manager* values, QMutex* mutex, const std::string& key,
|
|
const std::string& label, const QKeySequence& default_)
|
|
: Setting(parent, values, mutex, key, label)
|
|
, mDefault(default_)
|
|
{
|
|
State::get().getShortcutManager().setSequence(key, mDefault);
|
|
}
|
|
|
|
std::pair<QWidget*, QWidget*> ShortcutSetting::makeWidgets(QWidget* parent)
|
|
{
|
|
QLabel* label = new QLabel(QString::fromUtf8(getLabel().c_str()), parent);
|
|
QLineEdit* widget = new QLineEdit(State::get().getShortcutManager().sequenceToString(mDefault).c_str(), parent);
|
|
|
|
connect(widget, SIGNAL(textChanged(const QString&)), this, SLOT(valueChanged(const QString&)));
|
|
|
|
return std::make_pair(label, widget);
|
|
}
|
|
|
|
void ShortcutSetting::valueChanged(const QString& text)
|
|
{
|
|
{
|
|
QMutexLocker lock(getMutex());
|
|
getValues().setString(getKey(), getParent()->getKey(), text.toUtf8().data());
|
|
|
|
QKeySequence sequence = State::get().getShortcutManager().stringToSequence(text.toUtf8().data());
|
|
|
|
State::get().getShortcutManager().setSequence(getKey(), sequence);
|
|
}
|
|
|
|
getParent()->getState()->update(*this);
|
|
}
|
|
}
|