2021-04-15 00:37:00 +03:00
|
|
|
|
|
|
|
#include "stringsetting.hpp"
|
|
|
|
|
2021-04-15 22:34:25 +03:00
|
|
|
#include <QLineEdit>
|
2021-04-15 00:37:00 +03:00
|
|
|
#include <QMutexLocker>
|
|
|
|
|
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
|
2022-10-19 19:02:00 +02:00
|
|
|
#include <apps/opencs/model/prefs/setting.hpp>
|
|
|
|
|
2021-04-15 00:37:00 +03:00
|
|
|
#include "category.hpp"
|
|
|
|
#include "state.hpp"
|
|
|
|
|
2022-07-11 20:41:07 +04:00
|
|
|
CSMPrefs::StringSetting::StringSetting(
|
2023-11-12 00:52:09 +01:00
|
|
|
Category* parent, QMutex* mutex, const std::string& key, const QString& label, Settings::Index& index)
|
|
|
|
: TypedSetting(parent, mutex, key, label, index)
|
2022-07-11 20:41:07 +04:00
|
|
|
, mWidget(nullptr)
|
2021-04-15 00:37:00 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSMPrefs::StringSetting& CSMPrefs::StringSetting::setTooltip(const std::string& tooltip)
|
|
|
|
{
|
|
|
|
mTooltip = tooltip;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2023-11-10 13:28:10 +01:00
|
|
|
CSMPrefs::SettingWidgets CSMPrefs::StringSetting::makeWidgets(QWidget* parent)
|
2021-04-15 00:37:00 +03:00
|
|
|
{
|
2023-11-12 00:52:09 +01:00
|
|
|
mWidget = new QLineEdit(QString::fromStdString(getValue()), parent);
|
2021-04-15 00:37:00 +03:00
|
|
|
|
|
|
|
if (!mTooltip.empty())
|
|
|
|
{
|
|
|
|
QString tooltip = QString::fromUtf8(mTooltip.c_str());
|
|
|
|
mWidget->setToolTip(tooltip);
|
|
|
|
}
|
|
|
|
|
2022-08-22 23:28:58 -03:00
|
|
|
connect(mWidget, &QLineEdit::textChanged, this, &StringSetting::textChanged);
|
2021-04-15 00:37:00 +03:00
|
|
|
|
2023-11-10 13:28:10 +01:00
|
|
|
return SettingWidgets{ .mLabel = nullptr, .mInput = mWidget, .mLayout = nullptr };
|
2021-04-15 00:37:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::StringSetting::updateWidget()
|
|
|
|
{
|
|
|
|
if (mWidget)
|
2023-11-12 00:52:09 +01:00
|
|
|
mWidget->setText(QString::fromStdString(getValue()));
|
2021-04-15 00:37:00 +03:00
|
|
|
}
|
|
|
|
|
2021-04-15 22:34:25 +03:00
|
|
|
void CSMPrefs::StringSetting::textChanged(const QString& text)
|
2021-04-15 00:37:00 +03:00
|
|
|
{
|
2023-11-12 00:52:09 +01:00
|
|
|
setValue(text.toStdString());
|
2021-04-15 00:37:00 +03:00
|
|
|
getParent()->getState()->update(*this);
|
|
|
|
}
|