1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 21:45:35 +00:00
openmw/apps/opencs/model/prefs/stringsetting.cpp

53 lines
1.3 KiB
C++
Raw Normal View History

#include "stringsetting.hpp"
#include <QLineEdit>
#include <QMutexLocker>
#include <components/settings/settings.hpp>
2022-10-19 17:02:00 +00:00
#include <apps/opencs/model/prefs/setting.hpp>
#include "category.hpp"
#include "state.hpp"
2022-09-22 18:26:05 +00:00
CSMPrefs::StringSetting::StringSetting(
Category* parent, QMutex* mutex, std::string_view key, const QString& label, Settings::Index& index)
2023-11-11 23:52:09 +00:00
: TypedSetting(parent, mutex, key, label, index)
2022-09-22 18:26:05 +00:00
, mWidget(nullptr)
{
}
2022-09-22 18:26:05 +00:00
CSMPrefs::StringSetting& CSMPrefs::StringSetting::setTooltip(const std::string& tooltip)
{
mTooltip = tooltip;
return *this;
}
CSMPrefs::SettingWidgets CSMPrefs::StringSetting::makeWidgets(QWidget* parent)
{
2023-11-11 23:52:09 +00:00
mWidget = new QLineEdit(QString::fromStdString(getValue()), parent);
if (!mTooltip.empty())
{
2022-09-22 18:26:05 +00:00
QString tooltip = QString::fromUtf8(mTooltip.c_str());
mWidget->setToolTip(tooltip);
}
2022-09-22 18:26:05 +00:00
connect(mWidget, &QLineEdit::textChanged, this, &StringSetting::textChanged);
return SettingWidgets{ .mLabel = nullptr, .mInput = mWidget };
}
void CSMPrefs::StringSetting::updateWidget()
{
if (mWidget)
2023-11-11 23:52:09 +00:00
mWidget->setText(QString::fromStdString(getValue()));
}
2022-09-22 18:26:05 +00:00
void CSMPrefs::StringSetting::textChanged(const QString& text)
{
2023-11-11 23:52:09 +00:00
setValue(text.toStdString());
2022-09-22 18:26:05 +00:00
getParent()->getState()->update(*this);
}