mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-04 12:15:34 +00:00
added enum settings
This commit is contained in:
parent
8050eba83b
commit
590d6eba9b
5 changed files with 249 additions and 14 deletions
|
@ -138,7 +138,7 @@ opencs_hdrs_noqt (model/settings
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units (model/prefs
|
opencs_units (model/prefs
|
||||||
state setting intsetting doublesetting boolsetting
|
state setting intsetting doublesetting boolsetting enumsetting
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units_noqt (model/prefs
|
opencs_units_noqt (model/prefs
|
||||||
|
|
107
apps/opencs/model/prefs/enumsetting.cpp
Normal file
107
apps/opencs/model/prefs/enumsetting.cpp
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
|
||||||
|
#include "enumsetting.hpp"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
|
#include "category.hpp"
|
||||||
|
#include "state.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
CSMPrefs::EnumValue::EnumValue (const std::string& value, const std::string& tooltip)
|
||||||
|
: mValue (value), mTooltip (tooltip)
|
||||||
|
{}
|
||||||
|
|
||||||
|
CSMPrefs::EnumValue::EnumValue (const char *value)
|
||||||
|
: mValue (value)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
CSMPrefs::EnumValues& CSMPrefs::EnumValues::add (const EnumValues& values)
|
||||||
|
{
|
||||||
|
mValues.insert (mValues.end(), values.mValues.begin(), values.mValues.end());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMPrefs::EnumValues& CSMPrefs::EnumValues::add (const EnumValue& value)
|
||||||
|
{
|
||||||
|
mValues.push_back (value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMPrefs::EnumValues& CSMPrefs::EnumValues::add (const std::string& value, const std::string& tooltip)
|
||||||
|
{
|
||||||
|
mValues.push_back (EnumValue (value, tooltip));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CSMPrefs::EnumSetting::EnumSetting (Category *parent, Settings::Manager *values,
|
||||||
|
const std::string& key, const std::string& label, const EnumValue& default_)
|
||||||
|
: Setting (parent, values, key, label), mDefault (default_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::setTooltip (const std::string& tooltip)
|
||||||
|
{
|
||||||
|
mTooltip = tooltip;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::addValues (const EnumValues& values)
|
||||||
|
{
|
||||||
|
mValues.add (values);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::addValue (const EnumValue& value)
|
||||||
|
{
|
||||||
|
mValues.add (value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::addValue (const std::string& value, const std::string& tooltip)
|
||||||
|
{
|
||||||
|
mValues.add (value, tooltip);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<QWidget *, QWidget *> CSMPrefs::EnumSetting::makeWidgets (QWidget *parent)
|
||||||
|
{
|
||||||
|
QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent);
|
||||||
|
|
||||||
|
QComboBox *widget = new QComboBox (parent);
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (int i=0; i<static_cast<int> (mValues.mValues.size()); ++i)
|
||||||
|
{
|
||||||
|
if (mDefault.mValue==mValues.mValues[i].mValue)
|
||||||
|
index = i;
|
||||||
|
|
||||||
|
widget->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()),
|
||||||
|
Qt::ToolTipRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
widget->setCurrentIndex (index);
|
||||||
|
|
||||||
|
if (!mTooltip.empty())
|
||||||
|
{
|
||||||
|
QString tooltip = QString::fromUtf8 (mTooltip.c_str());
|
||||||
|
label->setToolTip (tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect (widget, SIGNAL (currentIndexChanged (int)), this, SLOT (valueChanged (int)));
|
||||||
|
|
||||||
|
return std::make_pair (label, widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMPrefs::EnumSetting::valueChanged (int value)
|
||||||
|
{
|
||||||
|
getValues().setString (getKey(), getParent()->getKey(), mValues.mValues.at (value).mValue);
|
||||||
|
getParent()->getState()->update (*this);
|
||||||
|
}
|
61
apps/opencs/model/prefs/enumsetting.hpp
Normal file
61
apps/opencs/model/prefs/enumsetting.hpp
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#ifndef CSM_PREFS_ENUMSETTING_H
|
||||||
|
#define CSM_PREFS_ENUMSETTING_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "setting.hpp"
|
||||||
|
|
||||||
|
namespace CSMPrefs
|
||||||
|
{
|
||||||
|
struct EnumValue
|
||||||
|
{
|
||||||
|
std::string mValue;
|
||||||
|
std::string mTooltip;
|
||||||
|
|
||||||
|
EnumValue (const std::string& value, const std::string& tooltip = "");
|
||||||
|
|
||||||
|
EnumValue (const char *value);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EnumValues
|
||||||
|
{
|
||||||
|
std::vector<EnumValue> mValues;
|
||||||
|
|
||||||
|
EnumValues& add (const EnumValues& values);
|
||||||
|
|
||||||
|
EnumValues& add (const EnumValue& value);
|
||||||
|
|
||||||
|
EnumValues& add (const std::string& value, const std::string& tooltip);
|
||||||
|
};
|
||||||
|
|
||||||
|
class EnumSetting : public Setting
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
std::string mTooltip;
|
||||||
|
EnumValue mDefault;
|
||||||
|
EnumValues mValues;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
EnumSetting (Category *parent, Settings::Manager *values,
|
||||||
|
const std::string& key, const std::string& label, const EnumValue& default_);
|
||||||
|
|
||||||
|
EnumSetting& setTooltip (const std::string& tooltip);
|
||||||
|
|
||||||
|
EnumSetting& addValues (const EnumValues& values);
|
||||||
|
|
||||||
|
EnumSetting& addValue (const EnumValue& value);
|
||||||
|
|
||||||
|
EnumSetting& addValue (const std::string& value, const std::string& tooltip);
|
||||||
|
|
||||||
|
/// Return label, input widget.
|
||||||
|
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void valueChanged (int value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -57,20 +57,44 @@ void CSMPrefs::State::declare()
|
||||||
declareInt ("minimum-width", "Minimum subview width", 325).
|
declareInt ("minimum-width", "Minimum subview width", 325).
|
||||||
setTooltip ("Minimum width of subviews.").
|
setTooltip ("Minimum width of subviews.").
|
||||||
setRange (50, 10000);
|
setRange (50, 10000);
|
||||||
// mainwindow-scrollbar
|
EnumValue scrollbarOnly ("Scrollbar Only", "Simple addition of scrollbars, the view window "
|
||||||
|
"does not grow automatically.");
|
||||||
|
declareEnum ("mainwindow-scrollbar", "Horizontal scrollbar mode for main window.", scrollbarOnly).
|
||||||
|
addValue (scrollbarOnly).
|
||||||
|
addValue ("Grow Only", "The view window grows as subviews are added. No scrollbars.").
|
||||||
|
addValue ("Grow then Scroll", "The view window grows. The scrollbar appears once it cannot grow any further.");
|
||||||
declareBool ("grow-limit", "Grow Limit Screen", false).
|
declareBool ("grow-limit", "Grow Limit Screen", false).
|
||||||
setTooltip ("When \"Grow then Scroll\" option is selected, the window size grows to"
|
setTooltip ("When \"Grow then Scroll\" option is selected, the window size grows to"
|
||||||
" the width of the virtual desktop. \nIf this option is selected the the window growth"
|
" the width of the virtual desktop. \nIf this option is selected the the window growth"
|
||||||
"is limited to the current screen.");
|
"is limited to the current screen.");
|
||||||
|
|
||||||
declareCategory ("Records");
|
declareCategory ("Records");
|
||||||
|
EnumValue iconAndText ("Icon and Text");
|
||||||
|
EnumValues recordValues;
|
||||||
|
recordValues.add (iconAndText).add ("Icon Only").add ("Text only");
|
||||||
|
declareEnum ("status-format", "Modification status display format", iconAndText).
|
||||||
|
addValues (recordValues);
|
||||||
|
declareEnum ("type-format", "ID type display format", iconAndText).
|
||||||
|
addValues (recordValues);
|
||||||
|
|
||||||
declareCategory ("ID Tables");
|
declareCategory ("ID Tables");
|
||||||
// double
|
EnumValue inPlaceEdit ("Edit in Place", "Edit the clicked cell");
|
||||||
// double-s
|
EnumValue editRecord ("Edit Record", "Open a dialogue subview for the clicked record");
|
||||||
// double-c
|
EnumValue view ("View", "Open a scene subview for the clicked record (not available everywhere)");
|
||||||
// double-sc
|
EnumValue editRecordAndClose ("Edit Record and Close");
|
||||||
// jump-to-added
|
EnumValues doubleClickValues;
|
||||||
|
doubleClickValues.add (inPlaceEdit).add (editRecord).add (view).add ("Revert").
|
||||||
|
add ("Delete").add (editRecordAndClose).
|
||||||
|
add ("View and Close", "Open a scene subview for the clicked record and close the table subview");
|
||||||
|
declareEnum ("double", "Double Click", inPlaceEdit).addValues (doubleClickValues);
|
||||||
|
declareEnum ("double-s", "Shift Double Click", editRecord).addValues (doubleClickValues);
|
||||||
|
declareEnum ("double-c", "Control Double Click", view).addValues (doubleClickValues);
|
||||||
|
declareEnum ("double-sc", "Shift Control Double Click", editRecordAndClose).addValues (doubleClickValues);
|
||||||
|
EnumValue jumpAndSelect ("Jump and Select", "Scroll new record into view and make it the selection");
|
||||||
|
declareEnum ("jump-to-added", "Action on adding or cloning a record", jumpAndSelect).
|
||||||
|
addValue (jumpAndSelect).
|
||||||
|
addValue ("Jump Only", "Scroll new record into view").
|
||||||
|
addValue ("No Jump", "No special action");
|
||||||
declareBool ("extended-config",
|
declareBool ("extended-config",
|
||||||
"Manually specify affected record types for an extended delete/revert", false).
|
"Manually specify affected record types for an extended delete/revert", false).
|
||||||
setTooltip ("Delete and revert commands have an extended form that also affects "
|
setTooltip ("Delete and revert commands have an extended form that also affects "
|
||||||
|
@ -83,6 +107,16 @@ void CSMPrefs::State::declare()
|
||||||
declareBool ("toolbar", "Show toolbar", true);
|
declareBool ("toolbar", "Show toolbar", true);
|
||||||
|
|
||||||
declareCategory ("Reports");
|
declareCategory ("Reports");
|
||||||
|
EnumValue actionNone ("None");
|
||||||
|
EnumValue actionEdit ("Edit", "Open a table or dialogue suitable for addressing the listed report");
|
||||||
|
EnumValue actionRemove ("Remove", "Remove the report from the report table");
|
||||||
|
EnumValue actionEditAndRemove ("Edit And Remove", "Open a table or dialogue suitable for addressing the listed report, then remove the report from the report table");
|
||||||
|
EnumValues reportValues;
|
||||||
|
reportValues.add (actionNone).add (actionEdit).add (actionRemove).add (actionEditAndRemove);
|
||||||
|
declareEnum ("double", "Double Click", actionEdit).addValues (reportValues);
|
||||||
|
declareEnum ("double-s", "Shift Double Click", actionRemove).addValues (reportValues);
|
||||||
|
declareEnum ("double-c", "Control Double Click", actionEditAndRemove).addValues (reportValues);
|
||||||
|
declareEnum ("double-sc", "Shift Control Double Click", actionNone).addValues (reportValues);
|
||||||
|
|
||||||
declareCategory ("Search & Replace");
|
declareCategory ("Search & Replace");
|
||||||
declareInt ("char-before", "Characters before search string", 10).
|
declareInt ("char-before", "Characters before search string", 10).
|
||||||
|
@ -96,7 +130,11 @@ void CSMPrefs::State::declare()
|
||||||
setTooltip ("Show line numbers to the left of the script editor window."
|
setTooltip ("Show line numbers to the left of the script editor window."
|
||||||
"The current row and column numbers of the text cursor are shown at the bottom.");
|
"The current row and column numbers of the text cursor are shown at the bottom.");
|
||||||
declareBool ("mono-font", "Use monospace font", true);
|
declareBool ("mono-font", "Use monospace font", true);
|
||||||
// warnings
|
EnumValue warningsNormal ("Normal", "Report warnings as warning");
|
||||||
|
declareEnum ("warnings", "Warning Mode", warningsNormal).
|
||||||
|
addValue ("Ignore", "Do not report warning").
|
||||||
|
addValue (warningsNormal).
|
||||||
|
addValue ("Strcit", "Promote warning to an error");
|
||||||
declareBool ("toolbar", "Show toolbar", true);
|
declareBool ("toolbar", "Show toolbar", true);
|
||||||
declareInt ("compile-delay", "Delay between updating of source errors", 100).
|
declareInt ("compile-delay", "Delay between updating of source errors", 100).
|
||||||
setTooltip ("Delay in milliseconds").
|
setTooltip ("Delay in milliseconds").
|
||||||
|
@ -111,12 +149,20 @@ void CSMPrefs::State::declare()
|
||||||
"list go to the first/last item");
|
"list go to the first/last item");
|
||||||
|
|
||||||
declareCategory ("3D Scene Input");
|
declareCategory ("3D Scene Input");
|
||||||
// p-navi
|
EnumValue left ("Left Mouse-Button");
|
||||||
// s-navi
|
EnumValue cLeft ("Ctrl-Left Mouse-Button");
|
||||||
// p-edit
|
EnumValue right ("Right Mouse-Button");
|
||||||
// s-edit
|
EnumValue cRight ("Ctrl-Right Mouse-Button");
|
||||||
// p-select
|
EnumValue middle ("Middle Mouse-Button");
|
||||||
// s-select
|
EnumValue cMiddle ("Ctrl-Middle Mouse-Button");
|
||||||
|
EnumValues inputButtons;
|
||||||
|
inputButtons.add (left).add (cLeft).add (right).add (cRight).add (middle).add (cMiddle);
|
||||||
|
declareEnum ("p-navi", "Primary Camera Navigation Button", left).addValues (inputButtons);
|
||||||
|
declareEnum ("s-navi", "Secondary Camera Navigation Button", cLeft).addValues (inputButtons);
|
||||||
|
declareEnum ("p-edit", "Primary Editing Button", right).addValues (inputButtons);
|
||||||
|
declareEnum ("s-edit", "Secondary Editing Button", cRight).addValues (inputButtons);
|
||||||
|
declareEnum ("p-select", "Primary Selection Button", middle).addValues (inputButtons);
|
||||||
|
declareEnum ("s-select", "Secondary Selection Button", cMiddle).addValues (inputButtons);
|
||||||
declareBool ("context-select", "Context Sensitive Selection", false);
|
declareBool ("context-select", "Context Sensitive Selection", false);
|
||||||
declareDouble ("drag-factor", "Mouse sensitivity during drag operations", 1.0).
|
declareDouble ("drag-factor", "Mouse sensitivity during drag operations", 1.0).
|
||||||
setRange (0.001, 100.0);
|
setRange (0.001, 100.0);
|
||||||
|
@ -207,6 +253,24 @@ CSMPrefs::BoolSetting& CSMPrefs::State::declareBool (const std::string& key,
|
||||||
return *setting;
|
return *setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSMPrefs::EnumSetting& CSMPrefs::State::declareEnum (const std::string& key,
|
||||||
|
const std::string& label, EnumValue default_)
|
||||||
|
{
|
||||||
|
if (mCurrentCategory==mCategories.end())
|
||||||
|
throw std::logic_error ("no category for setting");
|
||||||
|
|
||||||
|
setDefault (key, default_.mValue);
|
||||||
|
|
||||||
|
default_.mValue = mSettings.getString (key, mCurrentCategory->second.getKey());
|
||||||
|
|
||||||
|
CSMPrefs::EnumSetting *setting =
|
||||||
|
new CSMPrefs::EnumSetting (&mCurrentCategory->second, &mSettings, key, label, default_);
|
||||||
|
|
||||||
|
mCurrentCategory->second.addSetting (setting);
|
||||||
|
|
||||||
|
return *setting;
|
||||||
|
}
|
||||||
|
|
||||||
void CSMPrefs::State::setDefault (const std::string& key, const std::string& default_)
|
void CSMPrefs::State::setDefault (const std::string& key, const std::string& default_)
|
||||||
{
|
{
|
||||||
Settings::CategorySetting fullKey (mCurrentCategory->second.getKey(), key);
|
Settings::CategorySetting fullKey (mCurrentCategory->second.getKey(), key);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
#include "setting.hpp"
|
#include "setting.hpp"
|
||||||
|
#include "enumsetting.hpp"
|
||||||
|
|
||||||
namespace CSMPrefs
|
namespace CSMPrefs
|
||||||
{
|
{
|
||||||
|
@ -57,6 +58,8 @@ namespace CSMPrefs
|
||||||
|
|
||||||
BoolSetting& declareBool (const std::string& key, const std::string& label, bool default_);
|
BoolSetting& declareBool (const std::string& key, const std::string& label, bool default_);
|
||||||
|
|
||||||
|
EnumSetting& declareEnum (const std::string& key, const std::string& label, EnumValue default_);
|
||||||
|
|
||||||
void setDefault (const std::string& key, const std::string& default_);
|
void setDefault (const std::string& key, const std::string& default_);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue