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