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