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