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