]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDialogView.h
some tabular fixes for the problems reported by Helge
[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
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         qApp->processEvents();
130         updating_ = true;
131         update_contents();
132         qApp->processEvents();
133         updating_ = false;
134
135         form()->setUpdatesEnabled(true);
136         form()->update();
137 }
138
139
140 template <class GUIDialog>
141 void QView<GUIDialog>::build()
142 {
143         // protect the BC from unwarranted state transitions
144
145         qApp->processEvents();
146         updating_ = true;
147         build_dialog();
148         qApp->processEvents();
149         updating_ = false;
150 }
151
152
153 template <class Controller, class Base>
154 class QController: public Base
155 {
156 protected:
157         ///
158         QController(Dialog &, std::string const &);
159 public:
160         /// The parent controller
161         Controller & controller();
162         /// The parent controller
163         Controller const & controller() const;
164 };
165
166
167 template <class Controller, class Base>
168 QController<Controller, Base>::QController(Dialog & p, std::string const & t)
169         : Base(p, t)
170 {}
171
172
173 template <class Controller, class Base>
174 Controller & QController<Controller, Base>::controller()
175 {
176         return static_cast<Controller &>(this->getController());
177 }
178
179
180 template <class Controller, class Base>
181 Controller const & QController<Controller, Base>::controller() const
182 {
183         return static_cast<Controller const &>(this->getController());
184 }
185
186 } // namespace frontend
187 } // namespace lyx
188
189 #endif // QDIALOGVIEW_H