]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/Qt2Base.h
Minimise the ControlTabular interface in preparation for a move to the
[lyx.git] / src / frontends / qt2 / Qt2Base.h
1 // -*- C++ -*-
2 /**
3  * \file Qt2Base.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #ifndef QT2BASE_H
13 #define QT2BASE_H
14
15
16 #include "ViewBase.h"
17 #include <boost/scoped_ptr.hpp>
18
19 #include <qfont.h>
20 #include <qdialog.h>
21 #include <qobject.h>
22 #include <qapplication.h>
23
24 class Qt2BC;
25
26 /** This class is an Qt2 GUI base class.
27  */
28 class Qt2Base : public QObject, public ViewBase {
29         Q_OBJECT
30 public:
31         ///
32         Qt2Base(QString const &);
33         ///
34         virtual ~Qt2Base() {}
35 protected:
36         /// build the actual dialog
37         virtual void build_dialog() = 0;
38         /// Hide the dialog.
39         virtual void hide();
40         /// Create the dialog if necessary, update it and display it.
41         virtual void show();
42         /// update the dialog's contents
43         virtual void update_contents() = 0;
44         ///
45         virtual bool isVisible() const;
46
47         /// the dialog has changed contents
48         virtual void changed();
49
50         /// is the dialog currently valid ?
51         virtual bool isValid();
52
53         ///
54         Qt2BC & bc();
55
56         /// are we updating ?
57         bool updating_;
58 protected slots:
59         // dialog closed from WM
60         void slotWMHide();
61
62         // Restore button clicked
63         void slotRestore();
64
65         // OK button clicked
66         void slotOK();
67
68         // Apply button clicked
69         void slotApply();
70
71         // Close button clicked
72         void slotClose();
73 private:
74         /// Pointer to the actual instantiation of the Qt dialog
75         virtual QDialog * form() const = 0;
76
77 private:
78         /// dialog title, displayed by WM.
79         QString title_;
80 };
81
82
83 template <class Dialog>
84 class Qt2DB: public Qt2Base {
85 protected:
86         Qt2DB(QString const &);
87
88         /// update the dialog
89         virtual void update();
90
91         /// Build the dialog
92         virtual void build();
93
94         /// Pointer to the actual instantiation of the Qt dialog
95         virtual QDialog * form() const;
96
97         /// Real GUI implementation.
98         boost::scoped_ptr<Dialog> dialog_;
99
100 };
101
102
103 template <class Dialog>
104 Qt2DB<Dialog>::Qt2DB(QString const & t)
105         : Qt2Base(t)
106 {}
107
108
109 template <class Dialog>
110 QDialog * Qt2DB<Dialog>::form() const
111 {
112         return dialog_.get();
113 }
114
115
116 template <class Dialog>
117 void Qt2DB<Dialog>::update()
118 {
119         form()->setUpdatesEnabled(false);
120
121         // protect the BC from unwarranted state transitions
122
123         qApp->processEvents();
124         updating_ = true;
125         update_contents();
126         qApp->processEvents();
127         updating_ = false;
128
129         form()->setUpdatesEnabled(true);
130         form()->update();
131 }
132
133
134 template <class Dialog>
135 void Qt2DB<Dialog>::build()
136 {
137         // protect the BC from unwarranted state transitions
138
139         qApp->processEvents();
140         updating_ = true;
141         build_dialog();
142         qApp->processEvents();
143         updating_ = false;
144 }
145
146
147 template <class Controller, class Base>
148 class Qt2CB: public Base
149 {
150 public:
151         bool readOnly() const {
152                 return controller().bufferIsReadonly();
153         }
154
155         /// The parent controller
156         Controller & controller();
157         /// The parent controller
158         Controller const & controller() const;
159
160 protected:
161         ///
162         Qt2CB(QString const &);
163 };
164
165
166 template <class Controller, class Base>
167 Qt2CB<Controller, Base>::Qt2CB(QString const & t)
168         : Base(t)
169 {}
170
171
172 template <class Controller, class Base>
173 Controller & Qt2CB<Controller, Base>::controller()
174 {
175         return static_cast<Controller &>(getController());
176 }
177
178
179 template <class Controller, class Base>
180 Controller const & Qt2CB<Controller, Base>::controller() const
181 {
182         return static_cast<Controller const &>(getController());
183 }
184
185
186 #endif // FORMBASE_H