refactor: ValidationError, use palette to set the colors used
This commit is contained in:
parent
ccd40c2927
commit
1855d33e1f
1 changed files with 13 additions and 16 deletions
|
|
@ -9,13 +9,22 @@
|
||||||
|
|
||||||
#include "gui/Styles.h"
|
#include "gui/Styles.h"
|
||||||
|
|
||||||
using namespace deskflow::gui;
|
#include <QPalette>
|
||||||
|
|
||||||
namespace validators {
|
namespace validators {
|
||||||
|
|
||||||
ValidationError::ValidationError(QObject *parent, QLabel *label) : QObject(parent), m_label(label)
|
ValidationError::ValidationError(QObject *parent, QLabel *label) : QObject(parent), m_label(label)
|
||||||
{
|
{
|
||||||
clear();
|
if (!m_label)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_label->clear();
|
||||||
|
m_label->setContentsMargins(5, 3, 5, 3);
|
||||||
|
|
||||||
|
auto palette = m_label->palette();
|
||||||
|
palette.setColor(QPalette::WindowText, Qt::white);
|
||||||
|
palette.setColor(QPalette::Window, deskflow::gui::kColorError);
|
||||||
|
m_label->setPalette(palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &ValidationError::message() const
|
const QString &ValidationError::message() const
|
||||||
|
|
@ -33,20 +42,8 @@ void ValidationError::setMessage(const QString &message)
|
||||||
if (!m_label)
|
if (!m_label)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (message.isEmpty()) {
|
m_label->setAutoFillBackground(!message.isEmpty());
|
||||||
clear();
|
m_label->setText(message);
|
||||||
} else {
|
|
||||||
m_label->setStyleSheet(kStyleErrorActiveLabel);
|
|
||||||
m_label->setText(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ValidationError::clear()
|
|
||||||
{
|
|
||||||
if (!m_label)
|
|
||||||
return;
|
|
||||||
m_label->setStyleSheet(kStyleErrorInactiveLabel);
|
|
||||||
m_label->setText({});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace validators
|
} // namespace validators
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue