From e99d97c1277bb94a96c8d01617f8ed54a9fcfe33 Mon Sep 17 00:00:00 2001 From: Edwin Leuven Date: Sat, 15 Sep 2007 13:06:48 +0000 Subject: [PATCH] extract code that sets color of widget from ButtonController and move to qt_helpers git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20285 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/ButtonController.cpp | 22 +++------------------- src/frontends/qt4/ButtonController.h | 1 + src/frontends/qt4/qt_helpers.cpp | 13 +++++++++++++ src/frontends/qt4/qt_helpers.h | 3 +++ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/frontends/qt4/ButtonController.cpp b/src/frontends/qt4/ButtonController.cpp index ec3d06cf4a..82379e7749 100644 --- a/src/frontends/qt4/ButtonController.cpp +++ b/src/frontends/qt4/ButtonController.cpp @@ -174,14 +174,6 @@ bool ButtonController::checkWidgets() const // ////////////////////////////////////////////////////////////// -static void setWarningColor(QWidget * widget) -{ - QPalette pal = widget->palette(); - pal.setColor(QPalette::Active, QPalette::Foreground, QColor(255, 0, 0)); - widget->setPalette(pal); -} - - CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QWidget * label) : input_(input), label_(label) {} @@ -198,17 +190,9 @@ bool CheckedLineEdit::check() const bool const valid = validator->validate(t, p) == QValidator::Acceptable; // Visual feedback. - if (valid) - input_->setPalette(QPalette()); - else - setWarningColor(input_); - - if (label_) { - if (valid) - label_->setPalette(QPalette()); - else - setWarningColor(label_); - } + setValid(input_, valid); + if (label_) + setValid(label_, valid); return valid; } diff --git a/src/frontends/qt4/ButtonController.h b/src/frontends/qt4/ButtonController.h index 7c36f9e69e..6e32c897e8 100644 --- a/src/frontends/qt4/ButtonController.h +++ b/src/frontends/qt4/ButtonController.h @@ -12,6 +12,7 @@ #ifndef BUTTONCONTROLLER_H #define BUTTONCONTROLLER_H +#include #include "ButtonPolicy.h" #include "gettext.h" diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 2c14d42149..87abb66ee7 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -141,6 +142,18 @@ void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, } +void setValid(QWidget * widget, bool valid) +{ + if (valid) { + widget->setPalette(QPalette()); + } else { + QPalette pal = widget->palette(); + pal.setColor(QPalette::Active, QPalette::Foreground, QColor(255, 0, 0)); + widget->setPalette(pal); + } +} + + QString const qt_(char const * str, const char *) { return toqstr(_(str)); diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index d6ee69ee2a..980eb624a9 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -23,6 +23,7 @@ class QComboBox; class QLineEdit; class QCheckBox; +class QWidget; class LengthCombo; @@ -66,6 +67,8 @@ void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo, void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, LengthCombo * lengthCombo/*, string text = "auto"*/); +/// colors a widget red if invalid +void setValid(QWidget * widget, bool valid); /// format a string to the given width docstring const formatted(docstring const & text, int w = 80); -- 2.39.5