diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 8ab44243d..680c8f8b7 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -95,6 +95,7 @@ opencs_units (view/settings booleanview textview listview + rangeview resizeablestackedwidget ) diff --git a/apps/opencs/model/settings/setting.cpp b/apps/opencs/model/settings/setting.cpp index 6c7e78087..ca682b454 100644 --- a/apps/opencs/model/settings/setting.cpp +++ b/apps/opencs/model/settings/setting.cpp @@ -12,15 +12,14 @@ CSMSettings::Setting::Setting(SettingType typ, const QString &settingName, { buildDefaultSetting(); - int vType = static_cast (typ); + int settingType = static_cast (typ); - if ((vType % 2) == 0) - setProperty (Property_IsMultiValue, - QVariant(true).toString()); - else - vType--; + //even-numbered setting types are multi-valued + if ((settingType % 2) == 0) + setProperty (Property_IsMultiValue, QVariant(true).toString()); - setProperty (Property_ViewType, QVariant (vType / 2).toString()); + //view type is related to setting type by an order of magnitude + setProperty (Property_ViewType, QVariant (settingType / 10).toString()); setProperty (Property_Page, pageName); setProperty (Property_Name, settingName); setProperty (Property_DeclaredValues, values); @@ -267,9 +266,9 @@ void CSMSettings::Setting::setProperty (SettingProperty prop, QDataStream &operator <<(QDataStream &stream, const CSMSettings::Setting& setting) { - stream << setting.properties(); + // stream << setting.properties(); - stream << setting.proxies(); + // stream << setting.proxies(); return stream; } diff --git a/apps/opencs/model/settings/support.hpp b/apps/opencs/model/settings/support.hpp index abc86a0cb..ce808587f 100644 --- a/apps/opencs/model/settings/support.hpp +++ b/apps/opencs/model/settings/support.hpp @@ -47,14 +47,27 @@ namespace CSMSettings enum SettingType { - Type_MultiBool = 0, - Type_SingleBool = 1, - Type_MultiList = 2, - Type_SingleList = 3, - Type_MultiRange = 4, - Type_SingleRange = 5, - Type_MultiText = 6, - Type_SingleText = 7 + /* + * 0 - 9 - Boolean widgets + * 10-19 - List widgets + * 21-29 - Range widgets + * 31-39 - Text widgets + * + * Each range corresponds to a View_Type enum by a factor of 10. + * + * Even-numbered values are single-value widgets + * Odd-numbered values are multi-valued widgets + */ + + Type_CheckBox = 0, + Type_RadioButton = 1, + Type_ListView = 10, + Type_ComboBox = 11, + Type_SpinBox = 21, + Type_Slider = 23, + Type_Dial = 24, + Type_TextArea = 30, + Type_LineEdit = 31 }; enum MergeMethod diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 808fbfc70..2f8e8098d 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -47,8 +47,8 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() { QString section = "Window Size"; { - Setting *width = createSetting (Type_SingleText, section, "Width"); - Setting *height = createSetting (Type_SingleText, section, "Height"); + Setting *width = createSetting (Type_LineEdit, section, "Width"); + Setting *height = createSetting (Type_LineEdit, section, "Height"); width->setWidgetWidth (5); height->setWidgetWidth (5); @@ -65,7 +65,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() /* *Create the proxy setting for predefined values */ - Setting *preDefined = createSetting (Type_SingleList, section, + Setting *preDefined = createSetting (Type_ComboBox, section, "Pre-Defined", QStringList() << "640 x 480" @@ -94,11 +94,11 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() QStringList values = QStringList() << defaultValue << "Icon Only" << "Text Only"; - Setting *rsd = createSetting (Type_SingleBool, + Setting *rsd = createSetting (Type_RadioButton, section, "Record Status Display", values); - Setting *ritd = createSetting (Type_SingleBool, + Setting *ritd = createSetting (Type_RadioButton, section, "Referenceable ID Type Display", values); @@ -110,24 +110,24 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() { //create three setting objects, specifying the basic widget type, //the setting view name, the page name, and the default value - Setting *masterBoolean = createSetting (Type_SingleBool, section, + Setting *masterBoolean = createSetting (Type_RadioButton, section, "Master Proxy", QStringList() << "Profile One" << "Profile Two" << "Profile Three" << "Profile Four" ); - Setting *slaveBoolean = createSetting (Type_MultiBool, section, + Setting *slaveBoolean = createSetting (Type_CheckBox, section, "Proxy Checkboxes", QStringList() << "One" << "Two" << "Three" << "Four" << "Five" ); - Setting *slaveSingleText = createSetting (Type_SingleText, section, + Setting *slaveSingleText = createSetting (Type_LineEdit, section, "Proxy TextBox 1" ); - Setting *slaveMultiText = createSetting (Type_SingleText, section, + Setting *slaveMultiText = createSetting (Type_LineEdit, section, "ProxyTextBox 2" ); diff --git a/apps/opencs/view/settings/booleanview.hpp b/apps/opencs/view/settings/booleanview.hpp index 52f9e05f1..55ef0bb08 100644 --- a/apps/opencs/view/settings/booleanview.hpp +++ b/apps/opencs/view/settings/booleanview.hpp @@ -1,5 +1,5 @@ #ifndef CSVSETTINGS_BOOLEANVIEW_HPP -#define CSVSETTINGS_BOOELANVIEW_HPP +#define CSVSETTINGS_BOOLEANVIEW_HPP #include #include diff --git a/apps/opencs/view/settings/page.cpp b/apps/opencs/view/settings/page.cpp index a5711c8f8..e67445873 100644 --- a/apps/opencs/view/settings/page.cpp +++ b/apps/opencs/view/settings/page.cpp @@ -3,6 +3,7 @@ #include "booleanview.hpp" #include "textview.hpp" #include "listview.hpp" +#include "rangeview.hpp" #include "../../model/settings/usersettings.hpp" #include "../../model/settings/connector.hpp" @@ -85,4 +86,5 @@ void CSVSettings::Page::buildFactories() mViewFactories[ViewType_Boolean] = new BooleanViewFactory (this); mViewFactories[ViewType_Text] = new TextViewFactory (this); mViewFactories[ViewType_List] = new ListViewFactory (this); + mViewFactories[ViewType_Range] = new RangeViewFactory (this); } diff --git a/apps/opencs/view/settings/rangeview.cpp b/apps/opencs/view/settings/rangeview.cpp new file mode 100644 index 000000000..2bb5863bc --- /dev/null +++ b/apps/opencs/view/settings/rangeview.cpp @@ -0,0 +1,94 @@ +#include +#include + +#include +#include +#include + +#include + +#include "rangeview.hpp" +#include "../../model/settings/setting.hpp" + + +#include + +CSVSettings::RangeView::RangeView (CSMSettings::Setting *setting, + Page *parent) + : View (setting, parent) +{ + foreach (const QString &value, setting->declaredValues()) + { + QAbstractButton *button = 0; + + if (isMultiValue()) + button = new QCheckBox (value, this); + else + button = new QRadioButton (value, this); + + connect (button, SIGNAL (clicked (bool)), + this, SLOT (slotToggled (bool))); + + button->setObjectName (value); + + addWidget (button); + + mButtons[value] = button; + } +} + +void CSVSettings::RangeView::slotToggled (bool state) +{ + //test only for true to avoid multiple selection updates with radiobuttons + if (!isMultiValue() && !state) + return; + + QStringList values; + + foreach (QString key, mButtons.keys()) + { + if (mButtons.value(key)->isChecked()) + values.append (key); + } + setSelectedValues (values, false); + + View::updateView(); +} + +void CSVSettings::RangeView::updateView (bool signalUpdate) const +{ + + QStringList values = selectedValues(); + + foreach (const QString &buttonName, mButtons.keys()) + { + QAbstractButton *button = mButtons[buttonName]; + + //if the value is not found in the list, the widget is checked false + bool buttonValue = values.contains(buttonName); + + //skip if the butotn value will not change + if (button->isChecked() == buttonValue) + continue; + + //disable autoexclusive if it's enabled and we're setting + //the button value to false + bool switchExclusive = (!buttonValue && button->autoExclusive()); + + if (switchExclusive) + button->setAutoExclusive (false); + + button->setChecked (buttonValue); + + if (switchExclusive) + button->setAutoExclusive(true); + } + View::updateView (signalUpdate); +} + +CSVSettings::RangeView *CSVSettings::RangeViewFactory::createView + (CSMSettings::Setting *setting, + Page *parent) +{ + return new RangeView (setting, parent); +} diff --git a/apps/opencs/view/settings/rangeview.hpp b/apps/opencs/view/settings/rangeview.hpp new file mode 100644 index 000000000..1df0c7bd6 --- /dev/null +++ b/apps/opencs/view/settings/rangeview.hpp @@ -0,0 +1,44 @@ +#ifndef CSVSETTINGS_RANGEVIEW_HPP +#define CSVSETTINGS_RANGEVIEW_HPP + +#include +#include + +#include "view.hpp" +#include "../../model/settings/support.hpp" + +class QStringListModel; + +namespace CSVSettings +{ + class RangeView : public View + { + Q_OBJECT + + QMap mButtons; + + public: + explicit RangeView (CSMSettings::Setting *setting, + Page *parent); + + protected: + void updateView (bool signalUpdate = true) const; + + private slots: + void slotToggled (bool state); + }; + + class RangeViewFactory : public QObject, public IViewFactory + { + Q_OBJECT + + public: + explicit RangeViewFactory (QWidget *parent = 0) + : QObject (parent) + {} + + RangeView *createView (CSMSettings::Setting *setting, + Page *parent); + }; +} +#endif // CSVSETTINGS_RANGEVIEW_HPP diff --git a/apps/opencs/view/settings/settingwindow.cpp b/apps/opencs/view/settings/settingwindow.cpp index 9283bbf51..7bd0b228e 100644 --- a/apps/opencs/view/settings/settingwindow.cpp +++ b/apps/opencs/view/settings/settingwindow.cpp @@ -19,7 +19,7 @@ void CSVSettings::SettingWindow::createPages() QList connectedSettings; foreach (const QString &pageName, pageMap.keys()) - { + { QList pageSettings = pageMap.value (pageName); mPages.append (new Page (pageName, pageSettings, this));