2015-12-11 10:15:14 +00:00
|
|
|
#include "coloursetting.hpp"
|
|
|
|
|
|
|
|
#include <QLabel>
|
2015-12-15 11:19:48 +00:00
|
|
|
#include <QMutexLocker>
|
2017-05-09 07:50:16 +00:00
|
|
|
#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"
|
|
|
|
|
2022-07-11 16:41:07 +00:00
|
|
|
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_)
|
2022-07-11 16:41:07 +00:00
|
|
|
: 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);
|
|
|
|
|
2017-05-09 07:50:16 +00:00
|
|
|
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);
|
2017-05-09 07:50:16 +00:00
|
|
|
mWidget->setToolTip(tooltip);
|
2015-12-11 10:15:14 +00:00
|
|
|
}
|
|
|
|
|
2022-08-23 02:28:58 +00:00
|
|
|
connect(mWidget, &CSVWidget::ColorEditor::pickingFinished, this, &ColourSetting::valueChanged);
|
2015-12-11 10:15:14 +00:00
|
|
|
|
2017-05-09 07:50:16 +00:00
|
|
|
return std::make_pair(label, mWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::ColourSetting::updateWidget()
|
|
|
|
{
|
|
|
|
if (mWidget)
|
|
|
|
{
|
2022-07-11 16:41:07 +00:00
|
|
|
mWidget->setColor(QString::fromStdString(Settings::Manager::getString(getKey(), getParent()->getKey())));
|
2017-05-09 07:50:16 +00:00
|
|
|
}
|
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());
|
2022-07-11 16:41:07 +00:00
|
|
|
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);
|
|
|
|
}
|