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"
30 CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
39 /** General purpose button controller for up to four buttons.
40 Controls the activation of the OK, Apply and Cancel buttons.
41 Actually supports 4 buttons in all and it's up to the user to decide on
42 the activation policy and which buttons correspond to which output of the
47 /** \c ButtonController controls the activation of the OK, Apply and
50 * It actually supports 4 buttons in all and it's up to the user to decide on
51 * the activation policy and which buttons correspond to which output of the
55 class ButtonController
61 /** Methods to set and get the ButtonPolicy.
62 * \param ptr is owned by the ButtonController.
64 void setPolicy(ButtonPolicy::Policy policy);
65 ButtonPolicy const & policy() const { return policy_; }
66 ButtonPolicy & policy() { return policy_; }
70 void input(ButtonPolicy::SMInput);
73 /// Tell the BC that a particular button has been pressed.
80 /// Tell the BC that the dialog is being hidden
83 /**Refresh the activation state of the Ok, Apply, Close and
88 /** Refresh the activation state of all the widgets under the control
89 * of the BC to reflect the read-only status of the underlying buffer.
91 void refreshReadOnly() const;
93 /** Passthrough function -- returns its input value
94 * Tell the BC about the read-only status of the underlying buffer.
96 bool setReadOnly(bool = true);
98 /** \param validity Tell the BC that the data is, or is not, valid.
99 * Sets the activation state of the buttons immediately.
101 void setValid(bool = true);
108 /** Store pointers to these widgets.
110 void setOK(QPushButton * obj) { okay_ = obj; }
111 void setApply(QPushButton * obj) { apply_ = obj; }
112 void setCancel(QPushButton * obj) { cancel_ = obj; }
113 void setRestore(QPushButton * obj) { restore_ = obj; }
116 /** Add a pointer to the list of widgets whose activation
117 * state is dependent upon the read-only status of the
120 void addReadOnly(QWidget * obj) { read_only_.push_back(obj); }
122 /** Add a widget to the list of all widgets whose validity should
123 * be checked explicitly when the buttons are refreshed.
125 void addCheckedLineEdit(QLineEdit * input, QWidget * label = 0);
128 /// \return true if all CheckedWidgets are in a valid state.
129 bool checkWidgets() const;
132 typedef std::list<CheckedLineEdit> CheckedWidgetList;
133 CheckedWidgetList checked_widgets;
136 /// Updates the widget sensitivity (enabled/disabled)
137 void setWidgetEnabled(QWidget *, bool enabled) const;
140 QPushButton * apply_;
141 QPushButton * cancel_;
142 QPushButton * restore_;
144 typedef std::list<QWidget *> Widgets;
148 ButtonPolicy policy_;
151 } // namespace frontend
154 #endif // BUTTONCONTROLLER_H