1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 08:53:52 +00:00
openmw/apps/opencs/model/prefs/stringsetting.cpp

52 lines
1.3 KiB
C++

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