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