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