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