]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QDialogView.h
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / 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>
20 #include <QDialog>
21 #include <QObject>
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
40         /// the dialog has changed contents
41         virtual void changed();
42
43         ///
44         Qt2BC & bcview();
45
46 protected:
47         /// build the actual dialog
48         virtual void build_dialog() = 0;
49         ///
50         virtual void build() = 0;
51         /// Hide the dialog.
52         virtual void hide();
53         /// Create the dialog if necessary, update it and display it.
54         virtual void show();
55         /// update the dialog's contents
56         virtual void update_contents() = 0;
57         ///
58         virtual bool isVisible() const;
59
60         /// is the dialog currently valid ?
61         virtual bool isValid();
62
63         /// are we updating ?
64         bool updating_;
65
66 public Q_SLOTS:
67         // dialog closed from WM
68         void slotWMHide();
69
70         // Restore button clicked
71         void slotRestore();
72
73         // OK button clicked
74         void slotOK();
75
76         // Apply button clicked
77         void slotApply();
78
79         // Close button clicked
80         void slotClose();
81 private:
82         /// Pointer to the actual instantiation of the Qt dialog
83         virtual QDialog * form() const = 0;
84 };
85
86
87 template <class GUIDialog>
88 class QView: public QDialogView {
89 protected:
90         QView(Dialog &, std::string const &);
91
92         /// update the dialog
93         virtual void update();
94
95         /// Build the dialog
96         virtual void build();
97
98         /// Pointer to the actual instantiation of the Qt dialog
99         virtual QDialog * form() const;
100
101         /// Real GUI implementation.
102         boost::scoped_ptr<GUIDialog> dialog_;
103
104 };
105
106
107 template <class GUIDialog>
108 QView<GUIDialog>::QView(Dialog & p, std::string const & t)
109         : QDialogView(p, t)
110 {}
111
112
113 template <class GUIDialog>
114 QDialog * QView<GUIDialog>::form() const
115 {
116         /* Brain dead MSVC compiler wants to know the class hierarchy at the
117            definition site of the template, rather than the instantation point
118            to downcast correctly. So, rather than including all dialogs to
119            provide that, we just cast it with the ugly hammer. */
120         return (QDialog *) dialog_.get();
121 }
122
123
124 template <class GUIDialog>
125 void QView<GUIDialog>::update()
126 {
127         form()->setUpdatesEnabled(false);
128
129         // protect the BC from unwarranted state transitions
130
131         updating_ = true;
132         update_contents();
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         updating_ = true;
146         build_dialog();
147         updating_ = false;
148 }
149
150
151 template <class Controller, class Base>
152 class QController: public Base
153 {
154 protected:
155         ///
156         QController(Dialog &, std::string const &);
157 public:
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, std::string 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 &>(this->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 &>(this->getController());
182 }
183
184 } // namespace frontend
185 } // namespace lyx
186
187 #endif // QDIALOGVIEW_H