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"
29 CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
38 /** General purpose button controller for up to four buttons.
39 Controls the activation of the OK, Apply and Cancel buttons.
40 Actually supports 4 buttons in all and it's up to the user to decide on
41 the activation policy and which buttons correspond to which output of the
46 /** \c ButtonController controls the activation of the OK, Apply and
49 * It actually supports 4 buttons in all and it's up to the user to decide on
50 * the activation policy and which buttons correspond to which output of the
54 class ButtonController
60 /** Methods to set and get the ButtonPolicy.
61 * \param ptr is owned by the ButtonController.
63 void setPolicy(ButtonPolicy::Policy policy);
64 ButtonPolicy const & policy() const { return policy_; }
65 ButtonPolicy & policy() { return policy_; }
69 void input(ButtonPolicy::SMInput);
72 /// Tell the BC that a particular button has been pressed.
79 /// Tell the BC that the dialog is being hidden
82 /**Refresh the activation state of the Ok, Apply, Close and
87 /** Refresh the activation state of all the widgets under the control
88 * of the BC to reflect the read-only status of the underlying buffer.
90 void refreshReadOnly() const;
92 /** Passthrough function -- returns its input value
93 * Tell the BC about the read-only status of the underlying buffer.
95 bool setReadOnly(bool = true);
97 /** \param validity Tell the BC that the data is, or is not, valid.
98 * Sets the activation state of the buttons immediately.
100 void setValid(bool = true);
107 /** Store pointers to these widgets.
109 void setOK(QPushButton * obj) { okay_ = obj; }
110 void setApply(QPushButton * obj) { apply_ = obj; }
111 void setCancel(QPushButton * obj) { cancel_ = obj; }
112 void setRestore(QPushButton * obj) { restore_ = obj; }
115 /** Add a pointer to the list of widgets whose activation
116 * state is dependent upon the read-only status of the
119 void addReadOnly(QWidget * obj) { read_only_.push_back(obj); }
121 /** Add a widget to the list of all widgets whose validity should
122 * be checked explicitly when the buttons are refreshed.
124 void addCheckedLineEdit(QLineEdit * input, QWidget * label = 0);
127 /// \return true if all CheckedWidgets are in a valid state.
128 bool checkWidgets() const;
131 typedef std::list<CheckedLineEdit> CheckedWidgetList;
132 CheckedWidgetList checked_widgets;
135 /// Updates the widget sensitivity (enabled/disabled)
136 void setWidgetEnabled(QWidget *, bool enabled) const;
139 QPushButton * apply_;
140 QPushButton * cancel_;
141 QPushButton * restore_;
143 typedef std::list<QWidget *> Widgets;
147 ButtonPolicy policy_;
150 } // namespace frontend
153 #endif // BUTTONCONTROLLER_H