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