added colour settings

openmw-38
Marc Zinnschlag 9 years ago
parent 590d6eba9b
commit 73ffdd5ac5

@ -138,7 +138,7 @@ opencs_hdrs_noqt (model/settings
)
opencs_units (model/prefs
state setting intsetting doublesetting boolsetting enumsetting
state setting intsetting doublesetting boolsetting enumsetting coloursetting
)
opencs_units_noqt (model/prefs

@ -0,0 +1,49 @@
#include "coloursetting.hpp"
#include <limits>
#include <QLabel>
#include <components/settings/settings.hpp>
#include "../../view/widget/coloreditor.hpp"
#include "category.hpp"
#include "state.hpp"
CSMPrefs::ColourSetting::ColourSetting (Category *parent, Settings::Manager *values,
const std::string& key, const std::string& label, QColor default_)
: Setting (parent, values, key, label), mDefault (default_)
{}
CSMPrefs::ColourSetting& CSMPrefs::ColourSetting::setTooltip (const std::string& tooltip)
{
mTooltip = tooltip;
return *this;
}
std::pair<QWidget *, QWidget *> CSMPrefs::ColourSetting::makeWidgets (QWidget *parent)
{
QLabel *label = new QLabel (QString::fromUtf8 (getLabel().c_str()), parent);
CSVWidget::ColorEditor *widget = new CSVWidget::ColorEditor (mDefault, parent);
if (!mTooltip.empty())
{
QString tooltip = QString::fromUtf8 (mTooltip.c_str());
label->setToolTip (tooltip);
widget->setToolTip (tooltip);
}
connect (widget, SIGNAL (pickingFinished()), this, SLOT (valueChanged()));
return std::make_pair (label, widget);
}
void CSMPrefs::ColourSetting::valueChanged()
{
CSVWidget::ColorEditor& widget = dynamic_cast<CSVWidget::ColorEditor&> (*sender());
getValues().setString (getKey(), getParent()->getKey(), widget.color().name().toUtf8().data());
getParent()->getState()->update (*this);
}

@ -0,0 +1,33 @@
#ifndef CSM_PREFS_COLOURSETTING_H
#define CSM_PREFS_COLOURSETTING_H
#include "setting.hpp"
#include <QColor>
namespace CSMPrefs
{
class ColourSetting : public Setting
{
Q_OBJECT
std::string mTooltip;
QColor mDefault;
public:
ColourSetting (Category *parent, Settings::Manager *values,
const std::string& key, const std::string& label, QColor default_);
ColourSetting& setTooltip (const std::string& tooltip);
/// Return label, input widget.
virtual std::pair<QWidget *, QWidget *> makeWidgets (QWidget *parent);
private slots:
void valueChanged();
};
}
#endif

@ -8,6 +8,7 @@
#include "intsetting.hpp"
#include "doublesetting.hpp"
#include "boolsetting.hpp"
#include "coloursetting.hpp"
CSMPrefs::State *CSMPrefs::State::sThis = 0;
@ -141,8 +142,13 @@ void CSMPrefs::State::declare()
setRange (0, 10000);
declareInt ("error-height", "Initial height of the error panel", 100).
setRange (100, 10000);
// syntax-colouring
declareColour ("colour-int", "Highlight Colour: Integer Literals", QColor ("darkmagenta"));
declareColour ("colour-float", "Highlight Colour: Float Literals", QColor ("magenta"));
declareColour ("colour-name", "Highlight Colour: Names", QColor ("grey"));
declareColour ("colour-keyword", "Highlight Colour: Keywords", QColor ("red"));
declareColour ("colour-special", "Highlight Colour: Special Characters", QColor ("darkorange"));
declareColour ("colour-comment", "Highlight Colour: Comments", QColor ("green"));
declareColour ("colour-id", "Highlight Colour: IDs", QColor ("blue"));
declareCategory ("General Input");
declareBool ("cycle", "Cyclic next/previous", false).
setTooltip ("When using next/previous functions at the last/first item of a "
@ -271,6 +277,24 @@ CSMPrefs::EnumSetting& CSMPrefs::State::declareEnum (const std::string& key,
return *setting;
}
CSMPrefs::ColourSetting& CSMPrefs::State::declareColour (const std::string& key,
const std::string& label, QColor default_)
{
if (mCurrentCategory==mCategories.end())
throw std::logic_error ("no category for setting");
setDefault (key, default_.name().toUtf8().data());
default_.setNamedColor (QString::fromUtf8 (mSettings.getString (key, mCurrentCategory->second.getKey()).c_str()));
CSMPrefs::ColourSetting *setting =
new CSMPrefs::ColourSetting (&mCurrentCategory->second, &mSettings, key, label, default_);
mCurrentCategory->second.addSetting (setting);
return *setting;
}
void CSMPrefs::State::setDefault (const std::string& key, const std::string& default_)
{
Settings::CategorySetting fullKey (mCurrentCategory->second.getKey(), key);

@ -16,11 +16,14 @@
#include "setting.hpp"
#include "enumsetting.hpp"
class QColor;
namespace CSMPrefs
{
class IntSetting;
class DoubleSetting;
class BoolSetting;
class ColourSetting;
class State : public QObject
{
@ -60,6 +63,8 @@ namespace CSMPrefs
EnumSetting& declareEnum (const std::string& key, const std::string& label, EnumValue default_);
ColourSetting& declareColour (const std::string& key, const std::string& label, QColor default_);
void setDefault (const std::string& key, const std::string& default_);
public:

Loading…
Cancel
Save