diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 8a3d3c1c8..0a146dc06 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -110,7 +110,7 @@ opencs_units_noqt (view/tools ) opencs_units (view/prefs - dialogue pagebase page keybindingpage + dialogue pagebase page keybindingpage contextmenulist ) opencs_units (model/prefs diff --git a/apps/opencs/model/prefs/boolsetting.cpp b/apps/opencs/model/prefs/boolsetting.cpp index 6c0babaf7..6431dc6af 100644 --- a/apps/opencs/model/prefs/boolsetting.cpp +++ b/apps/opencs/model/prefs/boolsetting.cpp @@ -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 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 (0), widget); + return std::make_pair (static_cast (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) diff --git a/apps/opencs/model/prefs/boolsetting.hpp b/apps/opencs/model/prefs/boolsetting.hpp index f8a321859..37c018d14 100644 --- a/apps/opencs/model/prefs/boolsetting.hpp +++ b/apps/opencs/model/prefs/boolsetting.hpp @@ -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 makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged (int value); diff --git a/apps/opencs/model/prefs/coloursetting.cpp b/apps/opencs/model/prefs/coloursetting.cpp index d51bfad56..1a41621da 100644 --- a/apps/opencs/model/prefs/coloursetting.cpp +++ b/apps/opencs/model/prefs/coloursetting.cpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -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 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() diff --git a/apps/opencs/model/prefs/coloursetting.hpp b/apps/opencs/model/prefs/coloursetting.hpp index be58426f2..e892b21d6 100644 --- a/apps/opencs/model/prefs/coloursetting.hpp +++ b/apps/opencs/model/prefs/coloursetting.hpp @@ -5,6 +5,11 @@ #include +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 makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged(); diff --git a/apps/opencs/model/prefs/doublesetting.cpp b/apps/opencs/model/prefs/doublesetting.cpp index 531196174..8ae6f4818 100644 --- a/apps/opencs/model/prefs/doublesetting.cpp +++ b/apps/opencs/model/prefs/doublesetting.cpp @@ -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::max()), - mDefault (default_) + mDefault (default_), mWidget(0) {} CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setPrecision(int precision) @@ -54,21 +54,29 @@ std::pair 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) diff --git a/apps/opencs/model/prefs/doublesetting.hpp b/apps/opencs/model/prefs/doublesetting.hpp index 8fd345f4d..4d297409b 100644 --- a/apps/opencs/model/prefs/doublesetting.hpp +++ b/apps/opencs/model/prefs/doublesetting.hpp @@ -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 makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged (double value); diff --git a/apps/opencs/model/prefs/enumsetting.cpp b/apps/opencs/model/prefs/enumsetting.cpp index e69f717ea..226b17173 100644 --- a/apps/opencs/model/prefs/enumsetting.cpp +++ b/apps/opencs/model/prefs/enumsetting.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -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(0) {} CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::setTooltip (const std::string& tooltip) @@ -72,7 +73,7 @@ std::pair 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 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 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) diff --git a/apps/opencs/model/prefs/enumsetting.hpp b/apps/opencs/model/prefs/enumsetting.hpp index 728de3acd..b01635cdf 100644 --- a/apps/opencs/model/prefs/enumsetting.hpp +++ b/apps/opencs/model/prefs/enumsetting.hpp @@ -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 makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged (int value); diff --git a/apps/opencs/model/prefs/intsetting.cpp b/apps/opencs/model/prefs/intsetting.cpp index 269a63af4..25dbf78c2 100644 --- a/apps/opencs/model/prefs/intsetting.cpp +++ b/apps/opencs/model/prefs/intsetting.cpp @@ -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::max()), - mDefault (default_) + mDefault (default_), mWidget(0) {} CSMPrefs::IntSetting& CSMPrefs::IntSetting::setRange (int min, int max) @@ -47,20 +47,28 @@ std::pair 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) diff --git a/apps/opencs/model/prefs/intsetting.hpp b/apps/opencs/model/prefs/intsetting.hpp index 0ee6cf9e3..ee0989d83 100644 --- a/apps/opencs/model/prefs/intsetting.hpp +++ b/apps/opencs/model/prefs/intsetting.hpp @@ -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 makeWidgets (QWidget *parent); + virtual void updateWidget(); + private slots: void valueChanged (int value); diff --git a/apps/opencs/model/prefs/modifiersetting.cpp b/apps/opencs/model/prefs/modifiersetting.cpp index 4f4fac248..da6b2ccdd 100644 --- a/apps/opencs/model/prefs/modifiersetting.cpp +++ b/apps/opencs/model/prefs/modifiersetting.cpp @@ -32,6 +32,10 @@ namespace CSMPrefs widget->setCheckable(true); widget->installEventFilter(this); + + // right clicking on button sets shortcut to RMB, so context menu should not appear + widget->setContextMenuPolicy(Qt::PreventContextMenu); + mButton = widget; connect(widget, SIGNAL(toggled(bool)), this, SLOT(buttonToggled(bool))); @@ -39,6 +43,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) diff --git a/apps/opencs/model/prefs/modifiersetting.hpp b/apps/opencs/model/prefs/modifiersetting.hpp index 95983f66d..2c6a45b5a 100644 --- a/apps/opencs/model/prefs/modifiersetting.hpp +++ b/apps/opencs/model/prefs/modifiersetting.hpp @@ -21,6 +21,8 @@ namespace CSMPrefs virtual std::pair makeWidgets(QWidget* parent); + virtual void updateWidget(); + protected: bool eventFilter(QObject* target, QEvent* event); diff --git a/apps/opencs/model/prefs/setting.cpp b/apps/opencs/model/prefs/setting.cpp index 75b58322d..165062232 100644 --- a/apps/opencs/model/prefs/setting.cpp +++ b/apps/opencs/model/prefs/setting.cpp @@ -30,6 +30,10 @@ std::pair CSMPrefs::Setting::makeWidgets (QWidget *parent) return std::pair (0, 0); } +void CSMPrefs::Setting::updateWidget() +{ +} + const CSMPrefs::Category *CSMPrefs::Setting::getParent() const { return mParent; diff --git a/apps/opencs/model/prefs/setting.hpp b/apps/opencs/model/prefs/setting.hpp index 00bcc638b..7cb2d7acf 100644 --- a/apps/opencs/model/prefs/setting.hpp +++ b/apps/opencs/model/prefs/setting.hpp @@ -47,6 +47,11 @@ namespace CSMPrefs /// widget. virtual std::pair 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; diff --git a/apps/opencs/model/prefs/shortcutsetting.cpp b/apps/opencs/model/prefs/shortcutsetting.cpp index c56119deb..de495b9fc 100644 --- a/apps/opencs/model/prefs/shortcutsetting.cpp +++ b/apps/opencs/model/prefs/shortcutsetting.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "state.hpp" #include "shortcutmanager.hpp" @@ -39,6 +40,10 @@ namespace CSMPrefs widget->setCheckable(true); widget->installEventFilter(this); + + // right clicking on button sets shortcut to RMB, so context menu should not appear + widget->setContextMenuPolicy(Qt::PreventContextMenu); + mButton = widget; connect(widget, SIGNAL(toggled(bool)), this, SLOT(buttonToggled(bool))); @@ -46,6 +51,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) diff --git a/apps/opencs/model/prefs/shortcutsetting.hpp b/apps/opencs/model/prefs/shortcutsetting.hpp index bb38b580a..c388305a6 100644 --- a/apps/opencs/model/prefs/shortcutsetting.hpp +++ b/apps/opencs/model/prefs/shortcutsetting.hpp @@ -21,6 +21,8 @@ namespace CSMPrefs virtual std::pair makeWidgets(QWidget* parent); + virtual void updateWidget(); + protected: bool eventFilter(QObject* target, QEvent* event); diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 3921e32f2..618a4bfc9 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -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() { diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index 1e46c68ee..a32583dc5 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -106,6 +106,10 @@ namespace CSMPrefs static State& get(); + void resetCategory(const std::string& category); + + void resetAll(); + signals: void settingChanged (const CSMPrefs::Setting *setting); diff --git a/apps/opencs/view/prefs/contextmenulist.cpp b/apps/opencs/view/prefs/contextmenulist.cpp new file mode 100644 index 000000000..8115c3ecc --- /dev/null +++ b/apps/opencs/view/prefs/contextmenulist.cpp @@ -0,0 +1,44 @@ +#include "contextmenulist.hpp" + +#include +#include +#include + +#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::mousePressEvent(QMouseEvent* e) +{ + // enable all buttons except right click + // This means that when right-clicking to enable the + // context menu, the page doesn't switch at the same time. + if (!(e->buttons() & Qt::RightButton)) + { + QListWidget::mousePressEvent(e); + } +} + +void CSVPrefs::ContextMenuList::resetCategory() +{ + CSMPrefs::State::get().resetCategory(currentItem()->text().toStdString()); +} + +void CSVPrefs::ContextMenuList::resetAll() +{ + CSMPrefs::State::get().resetAll(); +} diff --git a/apps/opencs/view/prefs/contextmenulist.hpp b/apps/opencs/view/prefs/contextmenulist.hpp new file mode 100644 index 000000000..6aa187ca4 --- /dev/null +++ b/apps/opencs/view/prefs/contextmenulist.hpp @@ -0,0 +1,33 @@ +#ifndef CSV_PREFS_CONTEXTMENULIST_H +#define CSV_PREFS_CONTEXTMENULIST_H + +#include + +class QContextMenuEvent; +class QMouseEvent; + +namespace CSVPrefs +{ + class ContextMenuList : public QListWidget + { + Q_OBJECT + + public: + + ContextMenuList(QWidget* parent = 0); + + protected: + + void contextMenuEvent(QContextMenuEvent* e); + + void mousePressEvent(QMouseEvent* e); + + private slots: + + void resetCategory(); + + void resetAll(); + }; +} + +#endif diff --git a/apps/opencs/view/prefs/dialogue.cpp b/apps/opencs/view/prefs/dialogue.cpp index 6848bcaba..7f901c470 100644 --- a/apps/opencs/view/prefs/dialogue.cpp +++ b/apps/opencs/view/prefs/dialogue.cpp @@ -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 *))); } diff --git a/apps/opencs/view/prefs/dialogue.hpp b/apps/opencs/view/prefs/dialogue.hpp index fc66892c8..ce017209a 100644 --- a/apps/opencs/view/prefs/dialogue.hpp +++ b/apps/opencs/view/prefs/dialogue.hpp @@ -16,7 +16,6 @@ namespace CSVPrefs { Q_OBJECT - QListWidget *mList; QStackedWidget *mContent; private: diff --git a/apps/opencs/view/prefs/pagebase.cpp b/apps/opencs/view/prefs/pagebase.cpp index 16684a69d..15535b785 100644 --- a/apps/opencs/view/prefs/pagebase.cpp +++ b/apps/opencs/view/prefs/pagebase.cpp @@ -1,7 +1,11 @@ #include "pagebase.hpp" +#include +#include + #include "../../model/prefs/category.hpp" +#include "../../model/prefs/state.hpp" CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent) : QScrollArea (parent), mCategory (category) @@ -11,3 +15,24 @@ CSMPrefs::Category& CSVPrefs::PageBase::getCategory() { return mCategory; } + +void CSVPrefs::PageBase::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::PageBase::resetCategory() +{ + CSMPrefs::State::get().resetCategory(getCategory().getKey()); +} + +void CSVPrefs::PageBase::resetAll() +{ + CSMPrefs::State::get().resetAll(); +} diff --git a/apps/opencs/view/prefs/pagebase.hpp b/apps/opencs/view/prefs/pagebase.hpp index affe49f4a..91a4dee5b 100644 --- a/apps/opencs/view/prefs/pagebase.hpp +++ b/apps/opencs/view/prefs/pagebase.hpp @@ -3,6 +3,8 @@ #include +class QContextMenuEvent; + namespace CSMPrefs { class Category; @@ -21,6 +23,16 @@ namespace CSVPrefs PageBase (CSMPrefs::Category& category, QWidget *parent); CSMPrefs::Category& getCategory(); + + protected: + + void contextMenuEvent(QContextMenuEvent*); + + private slots: + + void resetCategory(); + + void resetAll(); }; }