WSL/SLF GitLab Repository

Commit 2acf890f authored by Michael Reisecker's avatar Michael Reisecker
Browse files

Minor structure changes

... to prepare having "valid" icon
parent 3f33f76c
......@@ -58,8 +58,6 @@ Atomic::Atomic(QString section, QString key, QWidget *parent)
*/
void Atomic::setDefaultPanelStyles(const QString &in_value)
{
setPanelStyle(FAULTY, false); //first we disable temporary styles
setPanelStyle(VALID, false);
const bool is_default = (QString::compare(in_value, this->property("default_value").toString(),
Qt::CaseInsensitive) == 0);
setPanelStyle(DEFAULT, is_default && !this->property("default_value").isNull() && !in_value.isNull());
......@@ -197,11 +195,8 @@ void Atomic::setPanelStyle(const PanelStyle &style, const bool &set, QWidget *wi
case DEFAULT:
style_string = "shows_default";
break;
case FAULTY:
style_string = "faulty";
break;
case VALID:
style_string = "valid";
case INVALID:
style_string = "invalid";
}
widget_to_set->setProperty(style_string.toLocal8Bit(), set? "true" : "false");
this->style()->unpolish(widget_to_set); //if a property is set dynamically, we might have to refresh
......@@ -209,13 +204,12 @@ void Atomic::setPanelStyle(const PanelStyle &style, const bool &set, QWidget *wi
} //https://wiki.qt.io/Technical_FAQ#How_can_my_stylesheet_account_for_custom_properties.3F
/**
* @brief Switch between "faulty" and "valid" panel styles.
* @param[in] on True to set "faulty", false to set "valid".
* @brief Style a panel to contain invalid values.
* @param[in] invalid True to set "invalid", false to disable (= "valid").
*/
void Atomic::setValidPanelStyle(const bool &on)
void Atomic::setInvalidStyle(const bool &invalid)
{
setPanelStyle(VALID, on);
setPanelStyle(FAULTY, !on);
setPanelStyle(INVALID, invalid);
}
/**
......
......@@ -46,8 +46,7 @@ class Atomic : public QWidget {
enum PanelStyle {
MANDATORY,
DEFAULT,
VALID,
FAULTY
INVALID
};
Atomic(QString section, QString key, QWidget *parent = nullptr);
virtual void setDefaultPanelStyles(const QString &in_value);
......@@ -61,7 +60,7 @@ class Atomic : public QWidget {
void setEmphasisWidget(QWidget *emphasis_widget, const bool &set_object_name = true);
QString getId() const noexcept { return section_ + Cst::sep + key_; }
void setPanelStyle(const PanelStyle &style, const bool &set = true, QWidget *widget = nullptr);
void setValidPanelStyle(const bool &on);
void setInvalidStyle(const bool &on);
void substituteKeys(QDomElement &parent_element, const QString &replace,
const QString &replace_with);
QSpacerItem * buildSpacer();
......
......@@ -167,8 +167,6 @@ Number::~Number()
*/
void Number::setDefaultPanelStyles(const QString &in_value)
{
setPanelStyle(FAULTY, false); //first we disable temporary styles
setPanelStyle(VALID, false);
bool is_default = false;
bool success_inval, success_default;
double inval = in_value.toDouble(&success_inval);
......@@ -307,7 +305,7 @@ void Number::setOptions(const QDomNode &options)
QString bg_color( colors::getQColor("app_bg").name() );
//find font color to use for hidden spinbox text dependent on background color:
if (options.toElement().attribute("optional").toLower() == "false")
if (!qobject_cast<QLabel*>(getEmphasisWidget())) //the entry widget is used for styling
if (!qobject_cast<QLabel *>(getEmphasisWidget())) //the entry widget is used for styling
bg_color = colors::getQColor("mandatory").name();
number_element_->setStyleSheet("* [empty=\"true\"] {color: " + bg_color + "}");
......@@ -391,7 +389,7 @@ void Number::checkStrValue(const QString &str_check)
setDefaultPanelStyles(str_check);
if (expr::checkExpression(str_check, evaluation_success, substitutions_) || !evaluation_success)
setValidPanelStyle(evaluation_success || str_check.isEmpty());
setInvalidStyle(!evaluation_success && !str_check.isEmpty());
QTimer::singleShot(1, this, [=]{ setEmpty(false); });
setIniValue(str_check); //it is just a hint - save anyway
}
......
......@@ -129,11 +129,12 @@ void Textfield::checkValue(const QString &text)
if (!validation_regex_.isNull()) { //check against regex specified in XML
const QRegularExpression rex_xml(validation_regex_);
const QRegularExpressionMatch xml_match(rex_xml.match(text));
setValidPanelStyle(xml_match.captured(idx_full) == text && !text.isEmpty());
setInvalidStyle(xml_match.captured(idx_full) != text && !text.isEmpty());
} else { //check for (arithmetic) expressions
bool evaluation_success;
if (expr::checkExpression(text, evaluation_success, substitutions_, needs_prefix_for_evaluation_))
setValidPanelStyle(evaluation_success);
const bool is_expression = expr::checkExpression(text, evaluation_success,
substitutions_, needs_prefix_for_evaluation_);
setInvalidStyle((is_expression && !evaluation_success) && !text.isEmpty());
}
}
setIniValue(text); //checks are just a hint - set anyway
......
......@@ -71,10 +71,8 @@ QColor getQColor(const QString &colorname)
name = "sl_red";
else if (name == "default_values")
name = "sl_base00";
else if (name == "faulty_values")
else if (name == "invalid_values")
name = "sl_yellow";
else if (name == "valid_values")
return (use_darkmode)? QColor("white") : QColor();
else if (name == "number")
name = "sl_cyan";
else if (name == "groupborder")
......
......@@ -189,11 +189,10 @@ void setAppStylesheet(QApplication &app, const command_line_args &cmd_args)
* of our design elements trying to take into account current OS color scheme settings.
*/
app.setStyleSheet(" \
* [mandatory=\"true\"] {background-color: " + colors::getQColor("mandatory").name() + "; color: " + colors::getQColor("normal").name() + "} \
* [mandatory=\"true\"] {font: bold; color: " + colors::getQColor("mandatory").name() + "} \
* [shows_default=\"true\"] {font-style: italic; color: " + colors::getQColor("default_values").name() + "} \
* [faulty=\"true\"] {color: " + colors::getQColor("faulty_values").name() + "} \
* [valid=\"true\"] {color: " + colors::getQColor("valid_values").name() + "} \
* [highlight=\"true\"] {background-color: " + colors::getQColor("sl_yellow").name() + "} \
* [invalid=\"true\"] {color:" + colors::getQColor("invalid_values").name() + ";} \
* [highlight=\"true\"] {background-color: " + colors::getQColor("sl_yellow").name() + "} \
QTabWidget {padding: 0px; font-weight: bold; background-color: " + colors::getQColor("app_bg").name() + "} \
QTabWidget:pane {background-color: " + colors::getQColor("app_bg").name() + "} \
QScrollArea {background-color: " + colors::getQColor("app_bg").name() + "} \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment