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