Utils: Use Utils::InfoLabel in ProjectIntroPage

Increases legibility in dark themes and removes some usages of style sheets.

Task-number: QDS-1346
Task-number: QTCREATORBUG-23346
Change-Id: If4a5583ee63ad14381de4cdef9561333f7854683
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2019-12-12 10:08:18 +01:00
parent d6745b488b
commit 78ffbe0ae7
3 changed files with 16 additions and 32 deletions

View File

@@ -58,29 +58,19 @@ namespace Utils {
class ProjectIntroPagePrivate class ProjectIntroPagePrivate
{ {
public: public:
ProjectIntroPagePrivate();
Ui::ProjectIntroPage m_ui; Ui::ProjectIntroPage m_ui;
bool m_complete = false; bool m_complete = false;
QRegularExpressionValidator m_projectNameValidator; QRegularExpressionValidator m_projectNameValidator;
// Status label style sheets
const QString m_errorStyleSheet;
const QString m_warningStyleSheet;
const QString m_hintStyleSheet;
bool m_forceSubProject = false; bool m_forceSubProject = false;
QStringList m_projectDirectories; QStringList m_projectDirectories;
}; };
ProjectIntroPagePrivate:: ProjectIntroPagePrivate() :
m_errorStyleSheet(QLatin1String("background : red;")),
m_warningStyleSheet(QLatin1String("background : yellow;"))
{
}
ProjectIntroPage::ProjectIntroPage(QWidget *parent) : ProjectIntroPage::ProjectIntroPage(QWidget *parent) :
WizardPage(parent), WizardPage(parent),
d(new ProjectIntroPagePrivate) d(new ProjectIntroPagePrivate)
{ {
d->m_ui.setupUi(this); d->m_ui.setupUi(this);
d->m_ui.stateLabel->setFilled(true);
hideStatusLabel(); hideStatusLabel();
d->m_ui.nameLineEdit->setPlaceholderText(tr("Enter project name")); d->m_ui.nameLineEdit->setPlaceholderText(tr("Enter project name"));
d->m_ui.nameLineEdit->setFocus(); d->m_ui.nameLineEdit->setFocus();
@@ -171,7 +161,7 @@ bool ProjectIntroPage::validate()
} }
// Validate and display status // Validate and display status
if (!d->m_ui.pathChooser->isValid()) { if (!d->m_ui.pathChooser->isValid()) {
displayStatusMessage(Error, d->m_ui.pathChooser->errorMessage()); displayStatusMessage(InfoLabel::Error, d->m_ui.pathChooser->errorMessage());
return false; return false;
} }
@@ -179,7 +169,7 @@ bool ProjectIntroPage::validate()
bool nameValid = false; bool nameValid = false;
switch (d->m_ui.nameLineEdit->state()) { switch (d->m_ui.nameLineEdit->state()) {
case FancyLineEdit::Invalid: case FancyLineEdit::Invalid:
displayStatusMessage(Error, d->m_ui.nameLineEdit->errorMessage()); displayStatusMessage(InfoLabel::Error, d->m_ui.nameLineEdit->errorMessage());
return false; return false;
case FancyLineEdit::DisplayingPlaceholderText: case FancyLineEdit::DisplayingPlaceholderText:
break; break;
@@ -197,11 +187,11 @@ bool ProjectIntroPage::validate()
} }
if (projectDirFile.isDir()) { if (projectDirFile.isDir()) {
displayStatusMessage(Warning, tr("The project already exists.")); displayStatusMessage(InfoLabel::Warning, tr("The project already exists."));
return nameValid; return nameValid;
} }
// Not a directory, but something else, likely causing directory creation to fail // Not a directory, but something else, likely causing directory creation to fail
displayStatusMessage(Error, tr("A file with that name already exists.")); displayStatusMessage(InfoLabel::Error, tr("A file with that name already exists."));
return false; return false;
} }
@@ -292,25 +282,15 @@ bool ProjectIntroPage::validateProjectName(const QString &name, QString *errorMe
return true; return true;
} }
void ProjectIntroPage::displayStatusMessage(StatusLabelMode m, const QString &s) void ProjectIntroPage::displayStatusMessage(InfoLabel::InfoType t, const QString &s)
{ {
switch (m) { d->m_ui.stateLabel->setType(t);
case Error:
d->m_ui.stateLabel->setStyleSheet(d->m_errorStyleSheet);
break;
case Warning:
d->m_ui.stateLabel->setStyleSheet(d->m_warningStyleSheet);
break;
case Hint:
d->m_ui.stateLabel->setStyleSheet(d->m_hintStyleSheet);
break;
}
d->m_ui.stateLabel->setText(s); d->m_ui.stateLabel->setText(s);
} }
void ProjectIntroPage::hideStatusLabel() void ProjectIntroPage::hideStatusLabel()
{ {
displayStatusMessage(Hint, QString()); displayStatusMessage(InfoLabel::None, {});
} }
bool ProjectIntroPage::useAsDefaultPath() const bool ProjectIntroPage::useAsDefaultPath() const

View File

@@ -27,6 +27,7 @@
#include "utils_global.h" #include "utils_global.h"
#include "wizardpage.h" #include "wizardpage.h"
#include "infolabel.h"
namespace Utils { namespace Utils {
@@ -77,10 +78,8 @@ private:
void slotChanged(); void slotChanged();
void slotActivated(); void slotActivated();
enum StatusLabelMode { Error, Warning, Hint };
bool validate(); bool validate();
void displayStatusMessage(StatusLabelMode m, const QString &); void displayStatusMessage(InfoLabel::InfoType t, const QString &);
void hideStatusLabel(); void hideStatusLabel();
ProjectIntroPagePrivate *d; ProjectIntroPagePrivate *d;

View File

@@ -109,7 +109,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="stateLabel"> <widget class="Utils::InfoLabel" name="stateLabel">
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
@@ -129,6 +129,11 @@
<header location="global">utils/pathchooser.h</header> <header location="global">utils/pathchooser.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>Utils::InfoLabel</class>
<extends>QLabel</extends>
<header location="global">utils/infolabel.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>