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