]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/Qt2Base.h
Some string(widget->text()) fixes. Weirdness
[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         /// the dialog has changed contents
49         virtual void changed();
50
51         /// is the dialog currently valid ?
52         virtual bool isValid();
53
54         ///
55         Qt2BC & bc();
56
57         /// are we updating ?
58         bool updating_;
59 protected slots:
60         // dialog closed from WM
61         void slotWMHide();
62
63         // Restore button clicked
64         void slotRestore();
65
66         // OK button clicked
67         void slotOK();
68
69         // Apply button clicked
70         void slotApply();
71
72         // Close button clicked
73         void slotClose();
74 private:
75         /// Pointer to the actual instantiation of xform's form
76         virtual QDialog * form() const = 0;
77
78 private:
79         /// dialog title, displayed by WM.
80         QString title_;
81 };
82
83
84 template <class Dialog>
85 class Qt2DB: public Qt2Base {
86 protected:
87         Qt2DB(QString const &);
88
89         /// update the dialog
90         virtual void update();
91
92         /// Build the dialog
93         virtual void build();
94
95         /// Pointer to the actual instantiation of the Qt dialog
96         virtual QDialog * form() const;
97
98         /// Real GUI implementation.
99         boost::scoped_ptr<Dialog> dialog_;
100
101 };
102
103
104 template <class Dialog>
105 Qt2DB<Dialog>::Qt2DB(QString const & t)
106         : Qt2Base(t)
107 {}
108
109
110 template <class Dialog>
111 QDialog * Qt2DB<Dialog>::form() const
112 {
113         return dialog_.get();
114 }
115
116
117 template <class Dialog>
118 void Qt2DB<Dialog>::update()
119 {
120         form()->setUpdatesEnabled(false);
121
122         // protect the BC from unwarranted state transitions
123
124         qApp->processEvents();
125         updating_ = true;
126         update_contents();
127         qApp->processEvents();
128         updating_ = false;
129
130         form()->setUpdatesEnabled(true);
131         form()->update();
132 }
133
134
135 template <class Dialog>
136 void Qt2DB<Dialog>::build()
137 {
138         // protect the BC from unwarranted state transitions
139
140         qApp->processEvents();
141         updating_ = true;
142         build_dialog();
143         qApp->processEvents();
144         updating_ = false;
145 }
146
147
148 template <class Controller, class Base>
149 class Qt2CB: public Base
150 {
151 public:
152         bool readOnly() const {
153                 return controller().bufferIsReadonly();
154         }
155
156 protected:
157         ///
158         Qt2CB(QString const &);
159         /// The parent controller
160         Controller & controller();
161         /// The parent controller
162         Controller const & controller() 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