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"
17 #include "support/gettext.h"
31 CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
40 /** General purpose button controller for up to four buttons.
41 Controls the activation of the OK, Apply and Cancel buttons.
42 Actually supports 4 buttons in all and it's up to the user to decide on
43 the activation policy and which buttons correspond to which output of the
48 /** \c ButtonController controls the activation of the OK, Apply and
51 * It actually supports 4 buttons in all and it's up to the user to decide on
52 * the activation policy and which buttons correspond to which output of the
56 class ButtonController
62 /** Methods to set and get the ButtonPolicy.
63 * \param ptr is owned by the ButtonController.
65 void setPolicy(ButtonPolicy::Policy policy);
66 ButtonPolicy const & policy() const { return policy_; }
67 ButtonPolicy & policy() { return policy_; }
71 void input(ButtonPolicy::SMInput);
74 /// Tell the BC that a particular button has been pressed.
81 /// Tell the BC that the dialog is being hidden
84 /**Refresh the activation state of the Ok, Apply, Close and
89 /** Refresh the activation state of all the widgets under the control
90 * of the BC to reflect the read-only status of the underlying buffer.
92 void refreshReadOnly() const;
94 /** Passthrough function -- returns its input value
95 * Tell the BC about the read-only status of the underlying buffer.
97 bool setReadOnly(bool = true);
99 /** \param validity Tell the BC that the data is, or is not, valid.
100 * Sets the activation state of the buttons immediately.
102 void setValid(bool = true);
109 /** Store pointers to these widgets.
111 void setOK(QPushButton * obj) { okay_ = obj; }
112 void setApply(QPushButton * obj) { apply_ = obj; }
113 void setCancel(QPushButton * obj) { cancel_ = obj; }
114 void setRestore(QPushButton * obj) { restore_ = obj; }
117 /** Add a pointer to the list of widgets whose activation
118 * state is dependent upon the read-only status of the
121 void addReadOnly(QWidget * obj) { read_only_.push_back(obj); }
123 /** Add a widget to the list of all widgets whose validity should
124 * be checked explicitly when the buttons are refreshed.
126 void addCheckedLineEdit(QLineEdit * input, QWidget * label = 0);
129 /// \return true if all CheckedWidgets are in a valid state.
130 bool checkWidgets() const;
133 typedef std::list<CheckedLineEdit> CheckedWidgetList;
134 CheckedWidgetList checked_widgets;
137 /// Updates the widget sensitivity (enabled/disabled)
138 void setWidgetEnabled(QWidget *, bool enabled) const;
141 QPushButton * apply_;
142 QPushButton * cancel_;
143 QPushButton * restore_;
145 typedef std::list<QWidget *> Widgets;
149 ButtonPolicy policy_;
152 } // namespace frontend
155 #endif // BUTTONCONTROLLER_H