]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/ButtonController.h
This is the last of a series of patches that merges the layout modules development...
[lyx.git] / src / frontends / qt4 / ButtonController.h
1 // -*- C++ -*-
2 /**
3  * \file ButtonController.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Allan Rae
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef BUTTONCONTROLLER_H
13 #define BUTTONCONTROLLER_H
14
15 #include "ButtonPolicy.h"
16 #include "gettext.h"
17
18 #include <list>
19
20 class QWidget;
21 class QPushButton;
22 class QLineEdit;
23
24 namespace lyx {
25 namespace frontend {
26
27 class CheckedLineEdit
28 {
29 public:
30         CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
31         bool check() const;
32
33 private:
34         // non-owned
35         QLineEdit * input_;
36         QWidget * label_;
37 };
38
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
43     state machine.
44 */
45
46
47 /** \c ButtonController controls the activation of the OK, Apply and
48  *  Cancel buttons.
49  *
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
52  * state machine.
53  */
54
55 class ButtonController
56 {
57 public:
58         ButtonController();
59
60         //@{
61         /** Methods to set and get the ButtonPolicy.
62          *  \param ptr is owned by the ButtonController.
63          */
64         void setPolicy(ButtonPolicy::Policy policy);
65         ButtonPolicy const & policy() const { return policy_; }
66         ButtonPolicy & policy() { return policy_; }
67         //@}
68
69         ///
70         void input(ButtonPolicy::SMInput);
71
72         //@{
73         /// Tell the BC that a particular button has been pressed.
74         void ok();
75         void apply();
76         void cancel();
77         void restore();
78         //@}
79
80         /// Tell the BC that the dialog is being hidden
81         void hide();
82
83         /**Refresh the activation state of the Ok, Apply, Close and
84          * Restore buttons.
85          */
86         void refresh() const;
87
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.
90          */
91         void refreshReadOnly() const;
92
93         /** Passthrough function -- returns its input value
94          *  Tell the BC about the read-only status of the underlying buffer.
95          */
96         bool setReadOnly(bool = true);
97
98         /** \param validity Tell the BC that the data is, or is not, valid.
99          *  Sets the activation state of the buttons immediately.
100          */
101         void setValid(bool = true);
102
103         //
104         // View
105         //
106
107         //@{
108         /** Store pointers to these widgets.
109          */
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; }
114         //@}
115
116         /** Add a pointer to the list of widgets whose activation
117          *  state is dependent upon the read-only status of the
118          *  underlying buffer.
119          */
120         void addReadOnly(QWidget * obj) { read_only_.push_back(obj); }
121
122         /** Add a widget to the list of all widgets whose validity should
123          *  be checked explicitly when the buttons are refreshed.
124          */
125         void addCheckedLineEdit(QLineEdit * input, QWidget * label = 0);
126
127 protected:
128         /// \return true if all CheckedWidgets are in a valid state.
129         bool checkWidgets() const;
130
131 private:
132         typedef std::list<CheckedLineEdit> CheckedWidgetList;
133         CheckedWidgetList checked_widgets;
134
135 private:
136         /// Updates the widget sensitivity (enabled/disabled)
137         void setWidgetEnabled(QWidget *, bool enabled) const;
138
139         QPushButton * okay_;
140         QPushButton * apply_;
141         QPushButton * cancel_;
142         QPushButton * restore_;
143
144         typedef std::list<QWidget *> Widgets;
145         Widgets read_only_;
146
147 private:
148         ButtonPolicy policy_;
149 };
150
151 } // namespace frontend
152 } // namespace lyx
153
154 #endif // BUTTONCONTROLLER_H