mirror of
https://github.com/huderlem/porymap.git
synced 2026-03-21 17:45:44 -05:00
Combine QLineEdit error stylesheets
This commit is contained in:
parent
82304ae828
commit
d795a1133d
|
|
@ -3,6 +3,7 @@
|
|||
#define UTILITY_H
|
||||
|
||||
#include <QString>
|
||||
#include <QLineEdit>
|
||||
|
||||
namespace Util {
|
||||
void numericalModeSort(QStringList &list);
|
||||
|
|
@ -12,6 +13,7 @@ namespace Util {
|
|||
QString toHtmlParagraph(const QString &text);
|
||||
Qt::Orientations getOrientation(bool xflip, bool yflip);
|
||||
QString replaceExtension(const QString &path, const QString &newExtension);
|
||||
void setErrorStylesheet(QLineEdit *lineEdit, bool isError);
|
||||
}
|
||||
|
||||
#endif // UTILITY_H
|
||||
|
|
|
|||
|
|
@ -64,3 +64,8 @@ QString Util::replaceExtension(const QString &path, const QString &newExtension)
|
|||
}
|
||||
return basePath + newExtension;
|
||||
}
|
||||
|
||||
void Util::setErrorStylesheet(QLineEdit *lineEdit, bool isError) {
|
||||
static const QString stylesheet = QStringLiteral("QLineEdit { background-color: rgba(255, 0, 0, 25%) }");
|
||||
lineEdit->setStyleSheet(isError ? stylesheet : "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -308,13 +308,9 @@ void Editor::addNewWildMonGroup(QWidget *window) {
|
|||
form.addRow(new QLabel("Group Base Label:"), lineEdit);
|
||||
lineEdit->setValidator(new IdentifierValidator(lineEdit));
|
||||
connect(lineEdit, &QLineEdit::textChanged, [this, &lineEdit, &buttonBox](QString text){
|
||||
if (!this->project->isIdentifierUnique(text)) {
|
||||
lineEdit->setStyleSheet("QLineEdit { background-color: rgba(255, 0, 0, 25%) }");
|
||||
buttonBox.button(QDialogButtonBox::Ok)->setDisabled(true);
|
||||
} else {
|
||||
lineEdit->setStyleSheet("");
|
||||
buttonBox.button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
}
|
||||
bool invalid = !this->project->isIdentifierUnique(text);
|
||||
Util::setErrorStylesheet(lineEdit, invalid);
|
||||
buttonBox.button(QDialogButtonBox::Ok)->setDisabled(invalid);
|
||||
});
|
||||
// Give a default value to the label.
|
||||
lineEdit->setText(this->project->toUniqueIdentifier("g" + map->name()));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "customattributesdialog.h"
|
||||
#include "ui_customattributesdialog.h"
|
||||
#include "utility.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
|
|
@ -61,7 +62,7 @@ bool CustomAttributesDialog::validateName(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_NameError->setText(errorText);
|
||||
ui->label_NameError->setVisible(!isValid);
|
||||
ui->lineEdit_Name->setStyleSheet(!isValid ? "QLineEdit { background-color: rgba(255, 0, 0, 25%) }" : "");
|
||||
Util::setErrorStylesheet(ui->lineEdit_Name, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
#include "newdefinedialog.h"
|
||||
#include "ui_newdefinedialog.h"
|
||||
#include "validator.h"
|
||||
|
||||
const QString lineEdit_ErrorStylesheet = "QLineEdit { background-color: rgba(255, 0, 0, 25%) }";
|
||||
#include "utility.h"
|
||||
|
||||
NewDefineDialog::NewDefineDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
|
|
@ -39,7 +38,7 @@ bool NewDefineDialog::validateName(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_NameError->setText(errorText);
|
||||
ui->label_NameError->setVisible(!isValid);
|
||||
ui->lineEdit_Name->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->lineEdit_Name, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
#include <QSet>
|
||||
#include <QStringList>
|
||||
|
||||
const QString lineEdit_ErrorStylesheet = "QLineEdit { background-color: rgba(255, 0, 0, 25%) }";
|
||||
|
||||
NewLayoutDialog::NewLayoutDialog(Project *project, QWidget *parent) :
|
||||
NewLayoutDialog(project, nullptr, parent)
|
||||
{}
|
||||
|
|
@ -95,7 +93,7 @@ bool NewLayoutDialog::validateLayoutID(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_LayoutIDError->setText(errorText);
|
||||
ui->label_LayoutIDError->setVisible(!isValid);
|
||||
ui->lineEdit_LayoutID->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->lineEdit_LayoutID, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +114,7 @@ bool NewLayoutDialog::validateName(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_NameError->setText(errorText);
|
||||
ui->label_NameError->setVisible(!isValid);
|
||||
ui->lineEdit_Name->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->lineEdit_Name, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
#include "ui_newlayoutform.h"
|
||||
#include "project.h"
|
||||
|
||||
const QString lineEdit_ErrorStylesheet = "QLineEdit { background-color: rgba(255, 0, 0, 25%) }";
|
||||
|
||||
NewLayoutForm::NewLayoutForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::NewLayoutForm)
|
||||
|
|
@ -119,7 +117,7 @@ bool NewLayoutForm::validatePrimaryTileset(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_PrimaryTilesetError->setText(errorText);
|
||||
ui->label_PrimaryTilesetError->setVisible(!isValid);
|
||||
ui->comboBox_PrimaryTileset->lineEdit()->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->comboBox_PrimaryTileset->lineEdit(), !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
@ -136,6 +134,6 @@ bool NewLayoutForm::validateSecondaryTileset(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_SecondaryTilesetError->setText(errorText);
|
||||
ui->label_SecondaryTilesetError->setVisible(!isValid);
|
||||
ui->comboBox_SecondaryTileset->lineEdit()->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->comboBox_SecondaryTileset->lineEdit(), !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
#include "project.h"
|
||||
#include "validator.h"
|
||||
|
||||
const QString lineEdit_ErrorStylesheet = "QLineEdit { background-color: rgba(255, 0, 0, 25%) }";
|
||||
|
||||
NewLocationDialog::NewLocationDialog(Project* project, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NewLocationDialog),
|
||||
|
|
@ -52,7 +50,7 @@ bool NewLocationDialog::validateIdName(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_IdNameError->setText(errorText);
|
||||
ui->label_IdNameError->setVisible(!isValid);
|
||||
ui->lineEdit_IdName->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->lineEdit_IdName, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@
|
|||
#include <QSet>
|
||||
#include <QStringList>
|
||||
|
||||
const QString lineEdit_ErrorStylesheet = "QLineEdit { background-color: rgba(255, 0, 0, 25%) }";
|
||||
|
||||
NewMapDialog::NewMapDialog(Project *project, QWidget *parent) :
|
||||
NewMapDialog(project, nullptr, parent)
|
||||
{}
|
||||
|
|
@ -158,7 +156,7 @@ bool NewMapDialog::validateName(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_NameError->setText(errorText);
|
||||
ui->label_NameError->setVisible(!isValid);
|
||||
ui->lineEdit_Name->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->lineEdit_Name, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +182,7 @@ bool NewMapDialog::validateGroup(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_GroupError->setText(errorText);
|
||||
ui->label_GroupError->setVisible(!isValid);
|
||||
ui->comboBox_Group->lineEdit()->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->comboBox_Group->lineEdit(), !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
@ -205,7 +203,7 @@ bool NewMapDialog::validateLayoutID(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_LayoutIDError->setText(errorText);
|
||||
ui->label_LayoutIDError->setVisible(!isValid);
|
||||
ui->comboBox_LayoutID->lineEdit()->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->comboBox_LayoutID->lineEdit(), !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
#include "project.h"
|
||||
#include "validator.h"
|
||||
|
||||
const QString lineEdit_ErrorStylesheet = "QLineEdit { background-color: rgba(255, 0, 0, 25%) }";
|
||||
|
||||
NewMapGroupDialog::NewMapGroupDialog(Project* project, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NewMapGroupDialog)
|
||||
|
|
@ -44,7 +42,7 @@ bool NewMapGroupDialog::validateName(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_NameError->setText(errorText);
|
||||
ui->label_NameError->setVisible(!isValid);
|
||||
ui->lineEdit_Name->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->lineEdit_Name, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
#include "imageexport.h"
|
||||
#include "validator.h"
|
||||
|
||||
const QString lineEdit_ErrorStylesheet = "QLineEdit { background-color: rgba(255, 0, 0, 25%) }";
|
||||
|
||||
NewTilesetDialog::NewTilesetDialog(Project* project, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NewTilesetDialog),
|
||||
|
|
@ -49,7 +47,7 @@ bool NewTilesetDialog::validateName(bool allowEmpty) {
|
|||
bool isValid = errorText.isEmpty();
|
||||
ui->label_NameError->setText(errorText);
|
||||
ui->label_NameError->setVisible(!isValid);
|
||||
ui->lineEdit_Name->setStyleSheet(!isValid ? lineEdit_ErrorStylesheet : "");
|
||||
Util::setErrorStylesheet(ui->lineEdit_Name, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user