]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Qt2BC.h
all CheckedWidgets are line edits...
[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
20 class QWidget;
21 class QPushButton;
22 class QLineEdit;
23
24 namespace lyx {
25 namespace frontend {
26
27
28 void addCheckedLineEdit(BCView & bcview,
29         QLineEdit * input, QWidget * label = 0);
30
31 class CheckedLineEdit
32 {
33 public:
34         CheckedLineEdit(QLineEdit * input, QWidget * label = 0);
35         bool check() const;
36
37 private:
38         // non-owned
39         QLineEdit * input_;
40         QWidget * label_;
41 };
42
43 /** General purpose button controller for up to four buttons.
44     Controls the activation of the OK, Apply and Cancel buttons.
45     Actually supports 4 buttons in all and it's up to the user to decide on
46     the activation policy and which buttons correspond to which output of the
47     state machine.
48 */
49
50 class Qt2BC : public BCView
51 {
52 public:
53         ///
54         Qt2BC(ButtonController & parent);
55
56         //@{
57         /** Store pointers to these widgets.
58          */
59         void setOK(QPushButton * obj) { okay_ = obj; }
60         void setApply(QPushButton * obj) { apply_ = obj; }
61         void setCancel(QPushButton * obj) { cancel_ = obj; }
62         void setRestore(QPushButton * obj) { restore_ = obj; }
63         //@}
64
65         /** Add a pointer to the list of widgets whose activation
66          *  state is dependent upon the read-only status of the
67          *  underlying buffer.
68          */
69         void addReadOnly(QWidget * obj) { read_only_.push_back(obj); }
70
71         /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
72         virtual void refresh() const;
73         /// Refresh the status of any widgets in the read_only list
74         virtual void refreshReadOnly() const;
75
76         /** Add a widget to the list of all widgets whose validity should
77          *  be checked explicitly when the buttons are refreshed.
78          */
79         void addCheckedLineEdit(QLineEdit * input, QWidget * label = 0);
80
81 protected:
82         /// \return true if all CheckedWidgets are in a valid state.
83         bool checkWidgets() const;
84
85 private:
86         typedef std::list<CheckedLineEdit> CheckedWidgetList;
87         CheckedWidgetList checked_widgets;
88
89 private:
90         /// Updates the widget sensitivity (enabled/disabled)
91         void setWidgetEnabled(QWidget *, bool enabled) const;
92
93         QPushButton * okay_;
94         QPushButton * apply_;
95         QPushButton * cancel_;
96         QPushButton * restore_;
97
98         typedef std::list<QWidget *> Widgets;
99         Widgets read_only_;
100 };
101
102 } // namespace frontend
103 } // namespace lyx
104
105 #endif // QT2BC_H