1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00
OpenMW/apps/opencs/model/prefs/stringsetting.cpp
Alexei Kotov 0b1465446d Editor: Improve Models category layout
Increase minimum input field width and give proper labels to string settings
2024-09-20 05:12:38 +03:00

58 lines
1.4 KiB
C++

#include "stringsetting.hpp"
#include <QLabel>
#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)
{
QLabel* label = new QLabel(getLabel(), parent);
mWidget = new QLineEdit(QString::fromStdString(getValue()), parent);
mWidget->setMinimumWidth(300);
if (!mTooltip.empty())
{
QString tooltip = QString::fromUtf8(mTooltip.c_str());
label->setToolTip(tooltip);
mWidget->setToolTip(tooltip);
}
connect(mWidget, &QLineEdit::textChanged, this, &StringSetting::textChanged);
return SettingWidgets{ .mLabel = label, .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);
}