]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QDialogView.h
Added initial qt4 work by Abdelrazak Younes
[lyx.git] / src / frontends / qt4 / QDialogView.h
1 // -*- C++ -*-
2 /**
3  * \file QDialogView.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 QDIALOGVIEW_H
13 #define QDIALOGVIEW_H
14
15 #include "Dialog.h"
16
17 #include <boost/scoped_ptr.hpp>
18
19 #include <QApplication>
20 #include <QDialog>
21 #include <QObject>
22
23 namespace lyx {
24 namespace frontend {
25
26 class Qt2BC;
27
28 /** This class is an Qt2 GUI base class.
29  */
30 class QDialogView : public QObject, public Dialog::View {
31         Q_OBJECT
32 public:
33         ///
34         QDialogView(Dialog &, std::string const &);
35         ///
36         virtual ~QDialogView() {}
37         ///
38         bool readOnly() const;
39
40         /// the dialog has changed contents
41         virtual void changed();
42
43 protected:
44         /// build the actual dialog
45         virtual void build_dialog() = 0;
46         ///
47         virtual void build() = 0;
48         /// Hide the dialog.
49         virtual void hide();
50         /// Create the dialog if necessary, update it and display it.
51         virtual void show();
52         /// update the dialog's contents
53         virtual void update_contents() = 0;
54         ///
55         virtual bool isVisible() const;
56
57         /// is the dialog currently valid ?
58         virtual bool isValid();
59
60         ///
61         Qt2BC & bcview();
62
63         /// are we updating ?
64         bool updating_;
65 protected slots:
66         // dialog closed from WM
67         void slotWMHide();
68
69         // Restore button clicked
70         void slotRestore();
71
72         // OK button clicked
73         void slotOK();
74
75         // Apply button clicked
76         void slotApply();
77
78         // Close button clicked
79         void slotClose();
80 private:
81         /// Pointer to the actual instantiation of the Qt dialog
82         virtual QDialog * form() const = 0;
83 };
84
85
86 template <class GUIDialog>
87 class QView: public QDialogView {
88 protected:
89         QView(Dialog &, std::string 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<GUIDialog> dialog_;
102
103 };
104
105
106 template <class GUIDialog>
107 QView<GUIDialog>::QView(Dialog & p, std::string const & t)
108         : QDialogView(p, t)
109 {}
110
111
112 template <class GUIDialog>
113 QDialog * QView<GUIDialog>::form() const
114 {
115         /* Brain dead MSVC compiler wants to know the class hierarchy at the
116            definition site of the template, rather than the instantation point
117            to downcast correctly. So, rather than including all dialogs to
118            provide that, we just cast it with the ugly hammer. */
119         return (QDialog *) dialog_.get();
120 }
121
122
123 template <class GUIDialog>
124 void QView<GUIDialog>::update()
125 {
126         form()->setUpdatesEnabled(false);
127
128         // protect the BC from unwarranted state transitions
129
130         updating_ = true;
131         update_contents();
132         updating_ = false;
133
134         form()->setUpdatesEnabled(true);
135         form()->update();
136 }
137
138
139 template <class GUIDialog>
140 void QView<GUIDialog>::build()
141 {
142         // protect the BC from unwarranted state transitions
143
144         updating_ = true;
145         build_dialog();
146         updating_ = false;
147 }
148
149
150 template <class Controller, class Base>
151 class QController: public Base
152 {
153 protected:
154         ///
155         QController(Dialog &, std::string const &);
156 public:
157         /// The parent controller
158         Controller & controller();
159         /// The parent controller
160         Controller const & controller() const;
161 };
162
163
164 template <class Controller, class Base>
165 QController<Controller, Base>::QController(Dialog & p, std::string const & t)
166         : Base(p, t)
167 {}
168
169
170 template <class Controller, class Base>
171 Controller & QController<Controller, Base>::controller()
172 {
173         return static_cast<Controller &>(this->getController());
174 }
175
176
177 template <class Controller, class Base>
178 Controller const & QController<Controller, Base>::controller() const
179 {
180         return static_cast<Controller const &>(this->getController());
181 }
182
183 } // namespace frontend
184 } // namespace lyx
185
186 #endif // QDIALOGVIEW_H