1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-24 06:53:52 +00:00
openmw/apps/opencs/view/doc/filewidget.cpp

65 lines
1.2 KiB
C++
Raw Normal View History

#include "filewidget.hpp"
#include <QHBoxLayout>
#include <QLabel>
2022-09-22 18:26:05 +00:00
#include <QLineEdit>
QString CSVDoc::FileWidget::getExtension() const
{
return mAddon ? ".omwaddon" : ".omwgame";
}
2022-09-22 18:26:05 +00:00
CSVDoc::FileWidget::FileWidget(QWidget* parent)
: QWidget(parent)
, mAddon(false)
{
2022-09-22 18:26:05 +00:00
QHBoxLayout* layout = new QHBoxLayout(this);
2022-09-22 18:26:05 +00:00
mInput = new QLineEdit(this);
2022-09-22 18:26:05 +00:00
layout->addWidget(mInput, 1);
2022-09-22 18:26:05 +00:00
mType = new QLabel(this);
2022-09-22 18:26:05 +00:00
layout->addWidget(mType);
2022-09-22 18:26:05 +00:00
connect(mInput, &QLineEdit::textChanged, this, &FileWidget::textChanged);
2022-09-22 18:26:05 +00:00
setLayout(layout);
}
2022-09-22 18:26:05 +00:00
void CSVDoc::FileWidget::setType(bool addon)
{
mAddon = addon;
2022-09-22 18:26:05 +00:00
mType->setText(getExtension());
}
QString CSVDoc::FileWidget::getName() const
{
QString text = mInput->text();
if (text.isEmpty())
return "";
return text + getExtension();
}
2022-09-22 18:26:05 +00:00
void CSVDoc::FileWidget::textChanged(const QString& text)
{
2022-09-22 18:26:05 +00:00
emit nameChanged(getName(), mAddon);
}
void CSVDoc::FileWidget::extensionLabelIsVisible(bool visible)
{
mType->setVisible(visible);
}
2022-09-22 18:26:05 +00:00
void CSVDoc::FileWidget::setName(const std::string& text)
{
2022-09-22 18:26:05 +00:00
QString text2 = QString::fromUtf8(text.c_str());
2022-09-22 18:26:05 +00:00
mInput->setText(text2);
textChanged(text2);
}