mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-28 08:37:12 +00:00
The text color of the profiles dialog now turns red on invalid names
This commit is contained in:
parent
990895fd2b
commit
43e9ad8733
@ -1,4 +1,5 @@
|
|||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
#include <QApplication>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
@ -17,9 +18,19 @@ TextInputDialog::TextInputDialog(const QString& title, const QString &text, QWid
|
|||||||
mButtonBox->addButton(QDialogButtonBox::Ok);
|
mButtonBox->addButton(QDialogButtonBox::Ok);
|
||||||
mButtonBox->addButton(QDialogButtonBox::Cancel);
|
mButtonBox->addButton(QDialogButtonBox::Cancel);
|
||||||
|
|
||||||
setMaximumHeight(height());
|
// Line edit
|
||||||
setOkButtonEnabled(false);
|
QValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
||||||
setModal(true);
|
mLineEdit = new LineEdit(this);
|
||||||
|
mLineEdit->setValidator(validator);
|
||||||
|
mLineEdit->setCompleter(0);
|
||||||
|
|
||||||
|
QLabel *label = new QLabel(this);
|
||||||
|
label->setText(text);
|
||||||
|
|
||||||
|
QVBoxLayout *dialogLayout = new QVBoxLayout(this);
|
||||||
|
dialogLayout->addWidget(label);
|
||||||
|
dialogLayout->addWidget(mLineEdit);
|
||||||
|
dialogLayout->addWidget(mButtonBox);
|
||||||
|
|
||||||
// Messageboxes on mac have no title
|
// Messageboxes on mac have no title
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
@ -28,22 +39,13 @@ TextInputDialog::TextInputDialog(const QString& title, const QString &text, QWid
|
|||||||
Q_UNUSED(title);
|
Q_UNUSED(title);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QLabel *label = new QLabel(this);
|
setMaximumHeight(height());
|
||||||
label->setText(text);
|
setOkButtonEnabled(false);
|
||||||
|
setModal(true);
|
||||||
// Line edit
|
|
||||||
QValidator *validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
|
||||||
mLineEdit = new LineEdit(this);
|
|
||||||
mLineEdit->setValidator(validator);
|
|
||||||
mLineEdit->setCompleter(0);
|
|
||||||
|
|
||||||
QVBoxLayout *dialogLayout = new QVBoxLayout(this);
|
|
||||||
dialogLayout->addWidget(label);
|
|
||||||
dialogLayout->addWidget(mLineEdit);
|
|
||||||
dialogLayout->addWidget(mButtonBox);
|
|
||||||
|
|
||||||
connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(mButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TextInputDialog::exec()
|
int TextInputDialog::exec()
|
||||||
@ -55,7 +57,17 @@ int TextInputDialog::exec()
|
|||||||
|
|
||||||
void TextInputDialog::setOkButtonEnabled(bool enabled)
|
void TextInputDialog::setOkButtonEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
|
|
||||||
QPushButton *okButton = mButtonBox->button(QDialogButtonBox::Ok);
|
QPushButton *okButton = mButtonBox->button(QDialogButtonBox::Ok);
|
||||||
okButton->setEnabled(enabled);
|
okButton->setEnabled(enabled);
|
||||||
|
|
||||||
|
QPalette *palette = new QPalette();
|
||||||
|
palette->setColor(QPalette::Text,Qt::red);
|
||||||
|
|
||||||
|
if (enabled) {
|
||||||
|
mLineEdit->setPalette(QApplication::palette());
|
||||||
|
} else {
|
||||||
|
// Existing profile name, make the text red
|
||||||
|
mLineEdit->setPalette(*palette);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user