1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-08 09:37:53 +00:00
OpenMW/apps/opencs/model/prefs/coloursetting.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.7 KiB
C++
Raw Normal View History

2015-12-11 10:15:14 +00:00
#include "coloursetting.hpp"
#include <QLabel>
2015-12-15 11:19:48 +00:00
#include <QMutexLocker>
#include <QString>
2015-12-11 10:15:14 +00:00
#include <components/settings/settings.hpp>
2022-10-19 17:02:00 +00:00
#include <apps/opencs/model/prefs/setting.hpp>
2015-12-11 10:15:14 +00:00
#include "../../view/widget/coloreditor.hpp"
#include "category.hpp"
#include "state.hpp"
CSMPrefs::ColourSetting::ColourSetting(
2015-12-15 11:19:48 +00:00
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, QColor default_)
: Setting(parent, mutex, key, label)
, mDefault(default_)
, mWidget(nullptr)
2015-12-11 10:15:14 +00:00
{
}
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);
mWidget = new CSVWidget::ColorEditor(mDefault, parent);
2015-12-11 10:15:14 +00:00
if (!mTooltip.empty())
{
QString tooltip = QString::fromUtf8(mTooltip.c_str());
label->setToolTip(tooltip);
mWidget->setToolTip(tooltip);
2015-12-11 10:15:14 +00:00
}
connect(mWidget, &CSVWidget::ColorEditor::pickingFinished, this, &ColourSetting::valueChanged);
2015-12-11 10:15:14 +00:00
return std::make_pair(label, mWidget);
}
void CSMPrefs::ColourSetting::updateWidget()
{
if (mWidget)
{
mWidget->setColor(QString::fromStdString(Settings::Manager::getString(getKey(), getParent()->getKey())));
}
2015-12-11 10:15:14 +00:00
}
void CSMPrefs::ColourSetting::valueChanged()
{
CSVWidget::ColorEditor& widget = dynamic_cast<CSVWidget::ColorEditor&>(*sender());
2015-12-15 11:19:48 +00:00
{
QMutexLocker lock(getMutex());
Settings::Manager::setString(getKey(), getParent()->getKey(), widget.color().name().toUtf8().data());
2015-12-15 11:19:48 +00:00
}
2015-12-11 10:15:14 +00:00
getParent()->getState()->update(*this);
}