mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 18:45:34 +00:00
Rewrite feature to reset options to default
This commit is contained in:
parent
f30d1a3075
commit
3545cfa00a
26 changed files with 331 additions and 44 deletions
|
@ -110,7 +110,7 @@ opencs_units_noqt (view/tools
|
|||
)
|
||||
|
||||
opencs_units (view/prefs
|
||||
dialogue pagebase page keybindingpage
|
||||
dialogue pagebase page keybindingpage contextmenulist contextmenuwidget
|
||||
)
|
||||
|
||||
opencs_units (model/prefs
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
CSMPrefs::BoolSetting::BoolSetting (Category *parent, Settings::Manager *values,
|
||||
QMutex *mutex, const std::string& key, const std::string& label, bool default_)
|
||||
: Setting (parent, values, mutex, key, label), mDefault (default_)
|
||||
: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(0)
|
||||
{}
|
||||
|
||||
CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip (const std::string& tooltip)
|
||||
|
@ -22,18 +22,28 @@ CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip (const std::string& too
|
|||
|
||||
std::pair<QWidget *, QWidget *> CSMPrefs::BoolSetting::makeWidgets (QWidget *parent)
|
||||
{
|
||||
QCheckBox *widget = new QCheckBox (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||
widget->setCheckState (mDefault ? Qt::Checked : Qt::Unchecked);
|
||||
mWidget = new QCheckBox (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||
mWidget->setCheckState (mDefault ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
if (!mTooltip.empty())
|
||||
{
|
||||
QString tooltip = QString::fromUtf8 (mTooltip.c_str());
|
||||
widget->setToolTip (tooltip);
|
||||
mWidget->setToolTip (tooltip);
|
||||
}
|
||||
|
||||
connect (widget, SIGNAL (stateChanged (int)), this, SLOT (valueChanged (int)));
|
||||
connect (mWidget, SIGNAL (stateChanged (int)), this, SLOT (valueChanged (int)));
|
||||
|
||||
return std::make_pair (static_cast<QWidget *> (0), widget);
|
||||
return std::make_pair (static_cast<QWidget *> (0), mWidget);
|
||||
}
|
||||
|
||||
void CSMPrefs::BoolSetting::updateWidget()
|
||||
{
|
||||
if (mWidget)
|
||||
{
|
||||
mWidget->setCheckState(getValues().getBool(getKey(), getParent()->getKey())
|
||||
? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
}
|
||||
}
|
||||
|
||||
void CSMPrefs::BoolSetting::valueChanged (int value)
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "setting.hpp"
|
||||
|
||||
class QCheckBox;
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class BoolSetting : public Setting
|
||||
|
@ -11,6 +13,7 @@ namespace CSMPrefs
|
|||
|
||||
std::string mTooltip;
|
||||
bool mDefault;
|
||||
QCheckBox* mWidget;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -22,6 +25,8 @@ namespace CSMPrefs
|
|||
/// Return label, input widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||
|
||||
virtual void updateWidget();
|
||||
|
||||
private slots:
|
||||
|
||||
void valueChanged (int value);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QLabel>
|
||||
#include <QMutexLocker>
|
||||
#include <QString>
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
|
@ -13,7 +14,7 @@
|
|||
|
||||
CSMPrefs::ColourSetting::ColourSetting (Category *parent, Settings::Manager *values,
|
||||
QMutex *mutex, const std::string& key, const std::string& label, QColor default_)
|
||||
: Setting (parent, values, mutex, key, label), mDefault (default_)
|
||||
: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(0)
|
||||
{}
|
||||
|
||||
CSMPrefs::ColourSetting& CSMPrefs::ColourSetting::setTooltip (const std::string& tooltip)
|
||||
|
@ -26,18 +27,27 @@ std::pair<QWidget *, QWidget *> CSMPrefs::ColourSetting::makeWidgets (QWidget *p
|
|||
{
|
||||
QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||
|
||||
CSVWidget::ColorEditor *widget = new CSVWidget::ColorEditor (mDefault, parent);
|
||||
mWidget = new CSVWidget::ColorEditor (mDefault, parent);
|
||||
|
||||
if (!mTooltip.empty())
|
||||
{
|
||||
QString tooltip = QString::fromUtf8 (mTooltip.c_str());
|
||||
label->setToolTip (tooltip);
|
||||
widget->setToolTip (tooltip);
|
||||
mWidget->setToolTip (tooltip);
|
||||
}
|
||||
|
||||
connect (widget, SIGNAL (pickingFinished()), this, SLOT (valueChanged()));
|
||||
connect (mWidget, SIGNAL (pickingFinished()), this, SLOT (valueChanged()));
|
||||
|
||||
return std::make_pair (label, widget);
|
||||
return std::make_pair (label, mWidget);
|
||||
}
|
||||
|
||||
void CSMPrefs::ColourSetting::updateWidget()
|
||||
{
|
||||
if (mWidget)
|
||||
{
|
||||
mWidget->setColor(QString::fromStdString
|
||||
(getValues().getString(getKey(), getParent()->getKey())));
|
||||
}
|
||||
}
|
||||
|
||||
void CSMPrefs::ColourSetting::valueChanged()
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
|
||||
#include <QColor>
|
||||
|
||||
namespace CSVWidget
|
||||
{
|
||||
class ColorEditor;
|
||||
}
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class ColourSetting : public Setting
|
||||
|
@ -13,6 +18,7 @@ namespace CSMPrefs
|
|||
|
||||
std::string mTooltip;
|
||||
QColor mDefault;
|
||||
CSVWidget::ColorEditor* mWidget;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -25,6 +31,8 @@ namespace CSMPrefs
|
|||
/// Return label, input widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||
|
||||
virtual void updateWidget();
|
||||
|
||||
private slots:
|
||||
|
||||
void valueChanged();
|
||||
|
|
|
@ -16,7 +16,7 @@ CSMPrefs::DoubleSetting::DoubleSetting (Category *parent, Settings::Manager *val
|
|||
QMutex *mutex, const std::string& key, const std::string& label, double default_)
|
||||
: Setting (parent, values, mutex, key, label),
|
||||
mPrecision(2), mMin (0), mMax (std::numeric_limits<double>::max()),
|
||||
mDefault (default_)
|
||||
mDefault (default_), mWidget(0)
|
||||
{}
|
||||
|
||||
CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setPrecision(int precision)
|
||||
|
@ -54,21 +54,29 @@ std::pair<QWidget *, QWidget *> CSMPrefs::DoubleSetting::makeWidgets (QWidget *p
|
|||
{
|
||||
QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||
|
||||
QDoubleSpinBox *widget = new QDoubleSpinBox (parent);
|
||||
widget->setDecimals(mPrecision);
|
||||
widget->setRange (mMin, mMax);
|
||||
widget->setValue (mDefault);
|
||||
mWidget = new QDoubleSpinBox (parent);
|
||||
mWidget->setDecimals(mPrecision);
|
||||
mWidget->setRange (mMin, mMax);
|
||||
mWidget->setValue (mDefault);
|
||||
|
||||
if (!mTooltip.empty())
|
||||
{
|
||||
QString tooltip = QString::fromUtf8 (mTooltip.c_str());
|
||||
label->setToolTip (tooltip);
|
||||
widget->setToolTip (tooltip);
|
||||
mWidget->setToolTip (tooltip);
|
||||
}
|
||||
|
||||
connect (widget, SIGNAL (valueChanged (double)), this, SLOT (valueChanged (double)));
|
||||
connect (mWidget, SIGNAL (valueChanged (double)), this, SLOT (valueChanged (double)));
|
||||
|
||||
return std::make_pair (label, widget);
|
||||
return std::make_pair (label, mWidget);
|
||||
}
|
||||
|
||||
void CSMPrefs::DoubleSetting::updateWidget()
|
||||
{
|
||||
if (mWidget)
|
||||
{
|
||||
mWidget->setValue(getValues().getFloat(getKey(), getParent()->getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
void CSMPrefs::DoubleSetting::valueChanged (double value)
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "setting.hpp"
|
||||
|
||||
class QDoubleSpinBox;
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class DoubleSetting : public Setting
|
||||
|
@ -14,6 +16,7 @@ namespace CSMPrefs
|
|||
double mMax;
|
||||
std::string mTooltip;
|
||||
double mDefault;
|
||||
QDoubleSpinBox* mWidget;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -35,6 +38,8 @@ namespace CSMPrefs
|
|||
/// Return label, input widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||
|
||||
virtual void updateWidget();
|
||||
|
||||
private slots:
|
||||
|
||||
void valueChanged (double value);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QLabel>
|
||||
#include <QComboBox>
|
||||
#include <QMutexLocker>
|
||||
#include <QString>
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
|
@ -41,7 +42,7 @@ CSMPrefs::EnumValues& CSMPrefs::EnumValues::add (const std::string& value, const
|
|||
|
||||
CSMPrefs::EnumSetting::EnumSetting (Category *parent, Settings::Manager *values,
|
||||
QMutex *mutex, const std::string& key, const std::string& label, const EnumValue& default_)
|
||||
: Setting (parent, values, mutex, key, label), mDefault (default_)
|
||||
: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget()
|
||||
{}
|
||||
|
||||
CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::setTooltip (const std::string& tooltip)
|
||||
|
@ -72,7 +73,7 @@ std::pair<QWidget *, QWidget *> CSMPrefs::EnumSetting::makeWidgets (QWidget *par
|
|||
{
|
||||
QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||
|
||||
QComboBox *widget = new QComboBox (parent);
|
||||
mWidget = new QComboBox (parent);
|
||||
|
||||
int index = 0;
|
||||
|
||||
|
@ -81,14 +82,14 @@ std::pair<QWidget *, QWidget *> CSMPrefs::EnumSetting::makeWidgets (QWidget *par
|
|||
if (mDefault.mValue==mValues.mValues[i].mValue)
|
||||
index = i;
|
||||
|
||||
widget->addItem (QString::fromUtf8 (mValues.mValues[i].mValue.c_str()));
|
||||
mWidget->addItem (QString::fromUtf8 (mValues.mValues[i].mValue.c_str()));
|
||||
|
||||
if (!mValues.mValues[i].mTooltip.empty())
|
||||
widget->setItemData (i, QString::fromUtf8 (mValues.mValues[i].mTooltip.c_str()),
|
||||
mWidget->setItemData (i, QString::fromUtf8 (mValues.mValues[i].mTooltip.c_str()),
|
||||
Qt::ToolTipRole);
|
||||
}
|
||||
|
||||
widget->setCurrentIndex (index);
|
||||
mWidget->setCurrentIndex (index);
|
||||
|
||||
if (!mTooltip.empty())
|
||||
{
|
||||
|
@ -96,9 +97,20 @@ std::pair<QWidget *, QWidget *> CSMPrefs::EnumSetting::makeWidgets (QWidget *par
|
|||
label->setToolTip (tooltip);
|
||||
}
|
||||
|
||||
connect (widget, SIGNAL (currentIndexChanged (int)), this, SLOT (valueChanged (int)));
|
||||
connect (mWidget, SIGNAL (currentIndexChanged (int)), this, SLOT (valueChanged (int)));
|
||||
|
||||
return std::make_pair (label, widget);
|
||||
return std::make_pair (label, mWidget);
|
||||
}
|
||||
|
||||
void CSMPrefs::EnumSetting::updateWidget()
|
||||
{
|
||||
if (mWidget)
|
||||
{
|
||||
int index = mWidget->findText(QString::fromStdString
|
||||
(getValues().getString(getKey(), getParent()->getKey())));
|
||||
|
||||
mWidget->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSMPrefs::EnumSetting::valueChanged (int value)
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "setting.hpp"
|
||||
|
||||
class QComboBox;
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
struct EnumValue
|
||||
|
@ -35,6 +37,7 @@ namespace CSMPrefs
|
|||
std::string mTooltip;
|
||||
EnumValue mDefault;
|
||||
EnumValues mValues;
|
||||
QComboBox* mWidget;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -53,6 +56,8 @@ namespace CSMPrefs
|
|||
/// Return label, input widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||
|
||||
virtual void updateWidget();
|
||||
|
||||
private slots:
|
||||
|
||||
void valueChanged (int value);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
CSMPrefs::IntSetting::IntSetting (Category *parent, Settings::Manager *values,
|
||||
QMutex *mutex, const std::string& key, const std::string& label, int default_)
|
||||
: Setting (parent, values, mutex, key, label), mMin (0), mMax (std::numeric_limits<int>::max()),
|
||||
mDefault (default_)
|
||||
mDefault (default_), mWidget(0)
|
||||
{}
|
||||
|
||||
CSMPrefs::IntSetting& CSMPrefs::IntSetting::setRange (int min, int max)
|
||||
|
@ -47,20 +47,28 @@ std::pair<QWidget *, QWidget *> CSMPrefs::IntSetting::makeWidgets (QWidget *pare
|
|||
{
|
||||
QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||
|
||||
QSpinBox *widget = new QSpinBox (parent);
|
||||
widget->setRange (mMin, mMax);
|
||||
widget->setValue (mDefault);
|
||||
mWidget = new QSpinBox (parent);
|
||||
mWidget->setRange (mMin, mMax);
|
||||
mWidget->setValue (mDefault);
|
||||
|
||||
if (!mTooltip.empty())
|
||||
{
|
||||
QString tooltip = QString::fromUtf8 (mTooltip.c_str());
|
||||
label->setToolTip (tooltip);
|
||||
widget->setToolTip (tooltip);
|
||||
mWidget->setToolTip (tooltip);
|
||||
}
|
||||
|
||||
connect (widget, SIGNAL (valueChanged (int)), this, SLOT (valueChanged (int)));
|
||||
connect (mWidget, SIGNAL (valueChanged (int)), this, SLOT (valueChanged (int)));
|
||||
|
||||
return std::make_pair (label, widget);
|
||||
return std::make_pair (label, mWidget);
|
||||
}
|
||||
|
||||
void CSMPrefs::IntSetting::updateWidget()
|
||||
{
|
||||
if (mWidget)
|
||||
{
|
||||
mWidget->setValue(getValues().getInt(getKey(), getParent()->getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
void CSMPrefs::IntSetting::valueChanged (int value)
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "setting.hpp"
|
||||
|
||||
class QSpinBox;
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class IntSetting : public Setting
|
||||
|
@ -13,6 +15,7 @@ namespace CSMPrefs
|
|||
int mMax;
|
||||
std::string mTooltip;
|
||||
int mDefault;
|
||||
QSpinBox* mWidget;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -31,6 +34,8 @@ namespace CSMPrefs
|
|||
/// Return label, input widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||
|
||||
virtual void updateWidget();
|
||||
|
||||
private slots:
|
||||
|
||||
void valueChanged (int value);
|
||||
|
|
|
@ -39,6 +39,19 @@ namespace CSMPrefs
|
|||
return std::make_pair(label, widget);
|
||||
}
|
||||
|
||||
void ModifierSetting::updateWidget()
|
||||
{
|
||||
if (mButton)
|
||||
{
|
||||
std::string shortcut = getValues().getString(getKey(), getParent()->getKey());
|
||||
|
||||
int modifier;
|
||||
State::get().getShortcutManager().convertFromString(shortcut, modifier);
|
||||
State::get().getShortcutManager().setModifier(getKey(), modifier);
|
||||
resetState();
|
||||
}
|
||||
}
|
||||
|
||||
bool ModifierSetting::eventFilter(QObject* target, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress)
|
||||
|
|
|
@ -21,6 +21,8 @@ namespace CSMPrefs
|
|||
|
||||
virtual std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent);
|
||||
|
||||
virtual void updateWidget();
|
||||
|
||||
protected:
|
||||
|
||||
bool eventFilter(QObject* target, QEvent* event);
|
||||
|
|
|
@ -30,6 +30,10 @@ std::pair<QWidget *, QWidget *> CSMPrefs::Setting::makeWidgets (QWidget *parent)
|
|||
return std::pair<QWidget *, QWidget *> (0, 0);
|
||||
}
|
||||
|
||||
void CSMPrefs::Setting::updateWidget()
|
||||
{
|
||||
}
|
||||
|
||||
const CSMPrefs::Category *CSMPrefs::Setting::getParent() const
|
||||
{
|
||||
return mParent;
|
||||
|
|
|
@ -47,6 +47,11 @@ namespace CSMPrefs
|
|||
/// widget.
|
||||
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||
|
||||
/// Updates the widget returned by makeWidgets() to the current setting.
|
||||
///
|
||||
/// \note If make_widgets() has not been called yet then nothing happens.
|
||||
virtual void updateWidget();
|
||||
|
||||
const Category *getParent() const;
|
||||
|
||||
const std::string& getKey() const;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QMouseEvent>
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
|
||||
#include "state.hpp"
|
||||
#include "shortcutmanager.hpp"
|
||||
|
@ -46,6 +47,19 @@ namespace CSMPrefs
|
|||
return std::make_pair(label, widget);
|
||||
}
|
||||
|
||||
void ShortcutSetting::updateWidget()
|
||||
{
|
||||
if (mButton)
|
||||
{
|
||||
std::string shortcut = getValues().getString(getKey(), getParent()->getKey());
|
||||
|
||||
QKeySequence sequence;
|
||||
State::get().getShortcutManager().convertFromString(shortcut, sequence);
|
||||
State::get().getShortcutManager().setSequence(getKey(), sequence);
|
||||
resetState();
|
||||
}
|
||||
}
|
||||
|
||||
bool ShortcutSetting::eventFilter(QObject* target, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress)
|
||||
|
|
|
@ -21,6 +21,8 @@ namespace CSMPrefs
|
|||
|
||||
virtual std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent);
|
||||
|
||||
virtual void updateWidget();
|
||||
|
||||
protected:
|
||||
|
||||
bool eventFilter(QObject* target, QEvent* event);
|
||||
|
|
|
@ -587,6 +587,41 @@ CSMPrefs::State& CSMPrefs::State::get()
|
|||
return *sThis;
|
||||
}
|
||||
|
||||
void CSMPrefs::State::resetCategory(const std::string& category)
|
||||
{
|
||||
for (Settings::CategorySettingValueMap::iterator i = mSettings.mUserSettings.begin();
|
||||
i != mSettings.mUserSettings.end(); ++i)
|
||||
{
|
||||
// if the category matches
|
||||
if (i->first.first == category)
|
||||
{
|
||||
// mark the setting as changed
|
||||
mSettings.mChangedSettings.insert(std::make_pair(i->first.first, i->first.second));
|
||||
// reset the value to the default
|
||||
i->second = mSettings.mDefaultSettings[i->first];
|
||||
}
|
||||
}
|
||||
|
||||
Collection::iterator container = mCategories.find(category);
|
||||
if (container != mCategories.end())
|
||||
{
|
||||
Category settings = container->second;
|
||||
for (Category::Iterator i = settings.begin(); i != settings.end(); ++i)
|
||||
{
|
||||
(*i)->updateWidget();
|
||||
update(**i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSMPrefs::State::resetAll()
|
||||
{
|
||||
for (Collection::iterator iter = mCategories.begin(); iter != mCategories.end(); ++iter)
|
||||
{
|
||||
resetCategory(iter->first);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CSMPrefs::State& CSMPrefs::get()
|
||||
{
|
||||
|
|
|
@ -106,6 +106,10 @@ namespace CSMPrefs
|
|||
|
||||
static State& get();
|
||||
|
||||
void resetCategory(const std::string& category);
|
||||
|
||||
void resetAll();
|
||||
|
||||
signals:
|
||||
|
||||
void settingChanged (const CSMPrefs::Setting *setting);
|
||||
|
|
32
apps/opencs/view/prefs/contextmenulist.cpp
Normal file
32
apps/opencs/view/prefs/contextmenulist.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "contextmenulist.hpp"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
#include "../../model/prefs/state.hpp"
|
||||
|
||||
CSVPrefs::ContextMenuList::ContextMenuList(QWidget* parent)
|
||||
:QListWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void CSVPrefs::ContextMenuList::contextMenuEvent(QContextMenuEvent* e)
|
||||
{
|
||||
QMenu* menu = new QMenu();
|
||||
|
||||
menu->addAction("Reset category to default", this, SLOT(resetCategory()));
|
||||
menu->addAction("Reset all to default", this, SLOT(resetAll()));
|
||||
|
||||
menu->exec(e->globalPos());
|
||||
delete menu;
|
||||
}
|
||||
|
||||
void CSVPrefs::ContextMenuList::resetCategory()
|
||||
{
|
||||
CSMPrefs::State::get().resetCategory(currentItem()->text().toStdString());
|
||||
}
|
||||
|
||||
void CSVPrefs::ContextMenuList::resetAll()
|
||||
{
|
||||
CSMPrefs::State::get().resetAll();
|
||||
}
|
30
apps/opencs/view/prefs/contextmenulist.hpp
Normal file
30
apps/opencs/view/prefs/contextmenulist.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef CSV_PREFS_CONTEXTMENULIST_H
|
||||
#define CSV_PREFS_CONTEXTMENULIST_H
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
class QContextMenuEvent;
|
||||
|
||||
namespace CSVPrefs
|
||||
{
|
||||
class ContextMenuList : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
ContextMenuList(QWidget* parent = 0);
|
||||
|
||||
protected:
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent* e);
|
||||
|
||||
private slots:
|
||||
|
||||
void resetCategory();
|
||||
|
||||
void resetAll();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
33
apps/opencs/view/prefs/contextmenuwidget.cpp
Normal file
33
apps/opencs/view/prefs/contextmenuwidget.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "contextmenuwidget.hpp"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
#include "../../model/prefs/state.hpp"
|
||||
|
||||
CSVPrefs::ContextMenuWidget::ContextMenuWidget(QWidget* parent, const std::string& category)
|
||||
:QWidget(parent)
|
||||
,mCategory(category)
|
||||
{
|
||||
}
|
||||
|
||||
void CSVPrefs::ContextMenuWidget::contextMenuEvent(QContextMenuEvent* e)
|
||||
{
|
||||
QMenu* menu = new QMenu();
|
||||
|
||||
menu->addAction("Reset category to default", this, SLOT(resetCategory()));
|
||||
menu->addAction("Reset all to default", this, SLOT(resetAll()));
|
||||
|
||||
menu->exec(e->globalPos());
|
||||
delete menu;
|
||||
}
|
||||
|
||||
void CSVPrefs::ContextMenuWidget::resetCategory()
|
||||
{
|
||||
CSMPrefs::State::get().resetCategory(mCategory);
|
||||
}
|
||||
|
||||
void CSVPrefs::ContextMenuWidget::resetAll()
|
||||
{
|
||||
CSMPrefs::State::get().resetAll();
|
||||
}
|
36
apps/opencs/view/prefs/contextmenuwidget.hpp
Normal file
36
apps/opencs/view/prefs/contextmenuwidget.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef CSV_PREFS_CONTEXTMENUWIDGET_H
|
||||
#define CSV_PREFS_CONTEXTMENUWIDGET_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QContextMenuEvent;
|
||||
|
||||
namespace CSVPrefs
|
||||
{
|
||||
class ContextMenuWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
ContextMenuWidget(QWidget* parent, const std::string& category);
|
||||
|
||||
protected:
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent* e);
|
||||
|
||||
private slots:
|
||||
|
||||
void resetCategory();
|
||||
|
||||
void resetAll();
|
||||
|
||||
private:
|
||||
|
||||
std::string mCategory;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -12,16 +12,17 @@
|
|||
|
||||
#include "page.hpp"
|
||||
#include "keybindingpage.hpp"
|
||||
#include "contextmenulist.hpp"
|
||||
|
||||
void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main)
|
||||
{
|
||||
mList = new QListWidget (main);
|
||||
mList->setMinimumWidth (50);
|
||||
mList->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
CSVPrefs::ContextMenuList* list = new CSVPrefs::ContextMenuList (main);
|
||||
list->setMinimumWidth (50);
|
||||
list->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
mList->setSelectionBehavior (QAbstractItemView::SelectItems);
|
||||
list->setSelectionBehavior (QAbstractItemView::SelectItems);
|
||||
|
||||
main->addWidget (mList);
|
||||
main->addWidget (list);
|
||||
|
||||
QFontMetrics metrics (QApplication::font());
|
||||
|
||||
|
@ -33,12 +34,12 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main)
|
|||
QString label = QString::fromUtf8 (iter->second.getKey().c_str());
|
||||
maxWidth = std::max (maxWidth, metrics.width (label));
|
||||
|
||||
mList->addItem (label);
|
||||
list->addItem (label);
|
||||
}
|
||||
|
||||
mList->setMaximumWidth (maxWidth + 10);
|
||||
list->setMaximumWidth (maxWidth + 10);
|
||||
|
||||
connect (mList, SIGNAL (currentItemChanged (QListWidgetItem *, QListWidgetItem *)),
|
||||
connect (list, SIGNAL (currentItemChanged (QListWidgetItem *, QListWidgetItem *)),
|
||||
this, SLOT (selectionChanged (QListWidgetItem *, QListWidgetItem *)));
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace CSVPrefs
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
QListWidget *mList;
|
||||
QStackedWidget *mContent;
|
||||
|
||||
private:
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
|
||||
#include "../../model/prefs/setting.hpp"
|
||||
#include "../../model/prefs/category.hpp"
|
||||
#include "../../view/prefs/contextmenuwidget.hpp"
|
||||
|
||||
CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent)
|
||||
: PageBase (category, parent)
|
||||
{
|
||||
QWidget *widget = new QWidget (parent);
|
||||
CSVPrefs::ContextMenuWidget *widget = new CSVPrefs::ContextMenuWidget (parent, category.getKey());
|
||||
mGrid = new QGridLayout (widget);
|
||||
|
||||
for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter)
|
||||
|
|
Loading…
Reference in a new issue