3 * \file ButtonController.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef BUTTONCONTROLLER_H
13 #define BUTTONCONTROLLER_H
15 #include "ButtonPolicy.h"
28 CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
37 /** General purpose button controller for up to four buttons.
38 Controls the activation of the OK, Apply and Cancel buttons.
39 Actually supports 4 buttons in all and it's up to the user to decide on
40 the activation policy and which buttons correspond to which output of the
45 /** \c ButtonController controls the activation of the OK, Apply and
48 * It actually supports 4 buttons in all and it's up to the user to decide on
49 * the activation policy and which buttons correspond to which output of the
53 class ButtonController
59 /** Methods to set and get the ButtonPolicy.
60 * \param ptr is owned by the ButtonController.
62 void setPolicy(ButtonPolicy::Policy policy);
63 ButtonPolicy const & policy() const { return policy_; }
64 ButtonPolicy & policy() { return policy_; }
68 void input(ButtonPolicy::SMInput);
71 /// Tell the BC that a particular button has been pressed.
78 /// Tell the BC that the dialog is being hidden
81 /**Refresh the activation state of the Ok, Apply, Close and
86 /** Refresh the activation state of all the widgets under the control
87 * of the BC to reflect the read-only status of the underlying buffer.
89 void refreshReadOnly() const;
91 /** Passthrough function -- returns its input value
92 * Tell the BC about the read-only status of the underlying buffer.
94 bool setReadOnly(bool = true);
96 /** \param validity Tell the BC that the data is, or is not, valid.
97 * Sets the activation state of the buttons immediately.
99 void setValid(bool = true);
106 /** Store pointers to these widgets.
108 void setOK(QPushButton * obj) { okay_ = obj; }
109 void setApply(QPushButton * obj) { apply_ = obj; }
110 void setCancel(QPushButton * obj) { cancel_ = obj; }
111 void setRestore(QPushButton * obj) { restore_ = obj; }
114 /** Add a pointer to the list of widgets whose activation
115 * state is dependent upon the read-only status of the
118 void addReadOnly(QWidget * obj) { read_only_.push_back(obj); }
120 /** Add a widget to the list of all widgets whose validity should
121 * be checked explicitly when the buttons are refreshed.
123 void addCheckedLineEdit(QLineEdit * input, QWidget * label = 0);
126 /// \return true if all CheckedWidgets are in a valid state.
127 bool checkWidgets() const;
130 typedef std::list<CheckedLineEdit> CheckedWidgetList;
131 CheckedWidgetList checked_widgets;
134 /// Updates the widget sensitivity (enabled/disabled)
135 void setWidgetEnabled(QWidget *, bool enabled) const;
138 QPushButton * apply_;
139 QPushButton * cancel_;
140 QPushButton * restore_;
142 typedef std::list<QWidget *> Widgets;
146 ButtonPolicy policy_;
149 } // namespace frontend
152 #endif // BUTTONCONTROLLER_H