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