From 035e52b780036762799174dd2630d3780d540f1f Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 2 Apr 2009 10:05:14 +0000 Subject: Validation and coloring of radiobuttons. --- client/widgets/radiobuttons.cc | 48 ++++++++++++++++++++++++------------------ client/widgets/radiobuttons.h | 1 + 2 files changed, 28 insertions(+), 21 deletions(-) (limited to 'client') diff --git a/client/widgets/radiobuttons.cc b/client/widgets/radiobuttons.cc index 2385428..d11c3e5 100644 --- a/client/widgets/radiobuttons.cc +++ b/client/widgets/radiobuttons.cc @@ -56,21 +56,40 @@ RadioButtons::RadioButtons(QDomNode &node, MacroWindow *macrowindow) layout()->setContentsMargins(0,0,0,0); } -bool RadioButtons::isValid() +bool RadioButtons::setBGColor(bool valid) { - if(!regexpValidator()) return false; - if(!luaValidator()) return false; + QPalette palette; + + if(valid) { + palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); + } else { + //palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); + palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); + } + + QVector< RadioButton* >::iterator i; + for (i = radiobutton_list.begin(); i != radiobutton_list.end(); ++i) { + RadioButton *widget = *i; + widget->setPalette(palette); + } + + return valid; +} +bool RadioButtons::isValid() +{ + if(!regexpValidator()) return setBGColor(false); + if(!luaValidator()) return setBGColor(false); QVector< RadioButton* >::iterator i; for (i = radiobutton_list.begin(); i != radiobutton_list.end(); ++i) { RadioButton *widget = *i; if(widget->isChecked()) { - return true; + return setBGColor(true); } } - return false; + return setBGColor(false); } QString RadioButtons::getValue() @@ -102,6 +121,8 @@ void RadioButtons::setValue(QString value, QString source) } setInitialValue(value); + + isValid(); } void RadioButtons::connectFrom(const char *signal, @@ -143,22 +164,7 @@ void RadioButtons::setVisibility(bool visible) void RadioButtons::childChanged() { - QPalette palette; - - if(regexpValidator()) { - if(luaValidator()) { - // valid string - palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); - } else { - // invalid string - palette.setBrush(QPalette::Base, QBrush(QColor(200, 230, 200))); - } - } else { - // invalid string - palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); - } - - setPalette(palette); + isValid(); emit wasChanged(); } diff --git a/client/widgets/radiobuttons.h b/client/widgets/radiobuttons.h index b0f6cd3..a32147b 100644 --- a/client/widgets/radiobuttons.h +++ b/client/widgets/radiobuttons.h @@ -66,6 +66,7 @@ signals: private: QVector < RadioButton* > radiobutton_list; + bool setBGColor(bool valid); }; #endif/*__PRACRO_RADIOBUTTONS_H__*/ -- cgit v1.2.3