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