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