]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDialogView.h
4fe4a816d821ff35d535ad4c0732693304a7da60
[lyx.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
16 #include "Dialog.h"
17 #include <boost/scoped_ptr.hpp>
18
19 #include <qfont.h>
20 #include <qdialog.h>
21 #include <qobject.h>
22 #include <qapplication.h>
23
24 class Qt2BC;
25
26 /** This class is an Qt2 GUI base class.
27  */
28 class QDialogView : public QObject, public Dialog::View {
29         Q_OBJECT
30 public:
31         ///
32         QDialogView(Dialog &, QString const &);
33         ///
34         virtual ~QDialogView() {}
35         ///
36         bool readOnly() const;
37
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 & bc();
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 private:
83         /// dialog title, displayed by WM.
84         QString title_;
85 };
86
87
88 template <class GUIDialog>
89 class QView: public QDialogView {
90 protected:
91         QView(Dialog &, QString const &);
92
93         /// update the dialog
94         virtual void update();
95
96         /// Build the dialog
97         virtual void build();
98
99         /// Pointer to the actual instantiation of the Qt dialog
100         virtual QDialog * form() const;
101
102         /// Real GUI implementation.
103         boost::scoped_ptr<GUIDialog> dialog_;
104
105 };
106
107
108 template <class GUIDialog>
109 QView<GUIDialog>::QView(Dialog & p, QString const & t)
110         : QDialogView(p, t)
111 {}
112
113
114 template <class GUIDialog>
115 QDialog * QView<GUIDialog>::form() const
116 {
117         return dialog_.get();
118 }
119
120
121 template <class GUIDialog>
122 void QView<GUIDialog>::update()
123 {
124         form()->setUpdatesEnabled(false);
125
126         // protect the BC from unwarranted state transitions
127
128         qApp->processEvents();
129         updating_ = true;
130         update_contents();
131         qApp->processEvents();
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         qApp->processEvents();
145         updating_ = true;
146         build_dialog();
147         qApp->processEvents();
148         updating_ = false;
149 }
150
151
152 template <class Controller, class Base>
153 class QController: public Base
154 {
155 protected:
156         ///
157         QController(Dialog &, QString const &);
158         /// The parent controller
159         Controller & controller();
160         /// The parent controller
161         Controller const & controller() const;
162 };
163
164
165 template <class Controller, class Base>
166 QController<Controller, Base>::QController(Dialog & p, QString const & t)
167         : Base(p, t)
168 {}
169
170
171 template <class Controller, class Base>
172 Controller & QController<Controller, Base>::controller()
173 {
174         return static_cast<Controller &>(getController());
175 }
176
177
178 template <class Controller, class Base>
179 Controller const & QController<Controller, Base>::controller() const
180 {
181         return static_cast<Controller const &>(getController());
182 }
183
184
185 #endif // QDIALOGVIEW_H