+static void setWidgetEnabled(QWidget * obj, bool enabled)
+{
+ if (QLineEdit * le = qobject_cast<QLineEdit*>(obj))
+ le->setReadOnly(!enabled);
+ else
+ obj->setEnabled(enabled);
+
+ obj->setFocusPolicy(enabled ? Qt::StrongFocus : Qt::NoFocus);
+}
+
+
+/////////////////////////////////////////////////////////////////////////
+//
+// CheckedLineEdit
+//
+/////////////////////////////////////////////////////////////////////////
+
+class CheckedLineEdit
+{
+public:
+ CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
+ bool check() const;
+
+private:
+ // non-owned
+ QLineEdit * input_;
+ QWidget * label_;
+};
+
+
+CheckedLineEdit::CheckedLineEdit(QLineEdit * input, QWidget * label)
+ : input_(input), label_(label)
+{}
+
+
+bool CheckedLineEdit::check() const
+{
+ QValidator const * validator = input_->validator();
+ if (!validator)
+ return true;
+
+ QString t = input_->text();
+ int p = 0;
+ bool const valid = validator->validate(t, p) == QValidator::Acceptable;
+
+ // Visual feedback.
+ setValid(input_, valid);
+ if (label_)
+ setValid(label_, valid);
+
+ return valid;
+}
+
+
+/////////////////////////////////////////////////////////////////////////
+//
+// ButtonController::Private
+//
+/////////////////////////////////////////////////////////////////////////
+
+class ButtonController::Private
+{
+public:
+ typedef QList<CheckedLineEdit> CheckedWidgetList;
+
+ Private()
+ : okay_(0), apply_(0), cancel_(0), restore_(0), auto_apply_(0),
+ policy_(ButtonPolicy::IgnorantPolicy)
+ {}
+
+ /// \return true if all CheckedWidgets are in a valid state.
+ bool checkWidgets() const
+ {
+ bool valid = true;
+ foreach (const CheckedLineEdit & w, checked_widgets_)
+ valid &= w.check();
+ return valid;
+ }
+
+public:
+ CheckedWidgetList checked_widgets_;
+
+ QPushButton * okay_;
+ QPushButton * apply_;
+ QPushButton * cancel_;
+ QPushButton * restore_;
+ QCheckBox * auto_apply_;
+
+ typedef QList<QWidget *> Widgets;
+ Widgets read_only_;
+
+ ButtonPolicy policy_;
+};
+
+
+/////////////////////////////////////////////////////////////////////////
+//
+// ButtonController
+//
+/////////////////////////////////////////////////////////////////////////
+