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