]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Qt2BC.h
simplify ButtonPolicy machinery
[lyx.git] / src / frontends / qt4 / Qt2BC.h
1 // -*- C++ -*-
2 /**
3  * \file Qt2BC.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  * \author Angus Leeming
9  * \author Baruch Even
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef QT2BC_H
15 #define QT2BC_H
16
17 #include "BCView.h"
18 #include "gettext.h"
19 #include "CheckedLineEdit.h"
20
21 class QWidget;
22 class QPushButton;
23
24 namespace lyx {
25 namespace frontend {
26
27 /** General purpose button controller for up to four buttons.
28     Controls the activation of the OK, Apply and Cancel buttons.
29     Actually supports 4 buttons in all and it's up to the user to decide on
30     the activation policy and which buttons correspond to which output of the
31     state machine.
32 */
33
34 class Qt2BC : public BCView
35 {
36 public:
37         ///
38         Qt2BC(ButtonController & parent);
39
40         //@{
41         /** Store pointers to these widgets.
42          */
43         void setOK(QPushButton * obj) { okay_ = obj; }
44         void setApply(QPushButton * obj) { apply_ = obj; }
45         void setCancel(QPushButton * obj) { cancel_ = obj; }
46         void setRestore(QPushButton * obj) { restore_ = obj; }
47         //@}
48
49         /** Add a pointer to the list of widgets whose activation
50          *  state is dependent upon the read-only status of the
51          *  underlying buffer.
52          */
53         void addReadOnly(QWidget * obj) { read_only_.push_back(obj); }
54
55         /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
56         virtual void refresh() const;
57         /// Refresh the status of any widgets in the read_only list
58         virtual void refreshReadOnly() const;
59
60         /** Add a widget to the list of all widgets whose validity should
61          *  be checked explicitly when the buttons are refreshed.
62          */
63         void addCheckedWidget(CheckedLineEdit * ptr);
64
65 protected:
66         /// \return true if all CheckedWidgets are in a valid state.
67         bool checkWidgets() const;
68
69 private:
70         typedef boost::shared_ptr<CheckedLineEdit> CheckedWidgetPtr;
71         typedef std::list<CheckedWidgetPtr> CheckedWidgetList;
72         CheckedWidgetList checked_widgets;
73
74 private:
75         /// Updates the widget sensitivity (enabled/disabled)
76         void setWidgetEnabled(QWidget *, bool enabled) const;
77
78         QPushButton * okay_;
79         QPushButton * apply_;
80         QPushButton * cancel_;
81         QPushButton * restore_;
82
83         typedef std::list<QWidget *> Widgets;
84         Widgets read_only_;
85 };
86
87 } // namespace frontend
88 } // namespace lyx
89
90 #endif // QT2BC_H