]> git.lyx.org Git - features.git/commitdiff
extract code that sets color of widget from ButtonController and move to qt_helpers
authorEdwin Leuven <e.leuven@gmail.com>
Sat, 15 Sep 2007 13:06:48 +0000 (13:06 +0000)
committerEdwin Leuven <e.leuven@gmail.com>
Sat, 15 Sep 2007 13:06:48 +0000 (13:06 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20285 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/ButtonController.cpp
src/frontends/qt4/ButtonController.h
src/frontends/qt4/qt_helpers.cpp
src/frontends/qt4/qt_helpers.h

index ec3d06cf4a8dda90cae973a5d2e800ad4d4960bb..82379e7749501bff11907283f61828aecbd2cdd1 100644 (file)
@@ -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;
 }
index 7c36f9e69e7512b098dad051b9d4c16adf16363c..6e32c897e80ff690eddfb9535dd332406fcd4e33 100644 (file)
@@ -12,6 +12,7 @@
 #ifndef BUTTONCONTROLLER_H
 #define BUTTONCONTROLLER_H
 
+#include <list>
 #include "ButtonPolicy.h"
 #include "gettext.h"
 
index 2c14d42149a32545d8bb9302fda74bb5d6603b95..87abb66ee72561637f480835b09061b42015f047 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QComboBox>
 #include <QCheckBox>
+#include <QPalette>
 #include <qlineedit.h>
 #include <qtextcodec.h>
 
@@ -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));
index d6ee69ee2ab2bca5ddc2c99ba8ca18e1de0a3a66..980eb624a947368e396d7a35df023044eb06fc85 100644 (file)
@@ -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);