4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
17 #include <boost/scoped_ptr.hpp>
19 #include <QApplication>
28 /** This class is an Qt2 GUI base class.
30 class QDialogView : public QObject, public Dialog::View {
34 QDialogView(Dialog &, std::string const &);
36 virtual ~QDialogView() {}
38 bool readOnly() const;
40 /// the dialog has changed contents
41 virtual void changed();
44 /// build the actual dialog
45 virtual void build_dialog() = 0;
47 virtual void build() = 0;
50 /// Create the dialog if necessary, update it and display it.
52 /// update the dialog's contents
53 virtual void update_contents() = 0;
55 virtual bool isVisible() const;
57 /// is the dialog currently valid ?
58 virtual bool isValid();
66 // dialog closed from WM
69 // Restore button clicked
75 // Apply button clicked
78 // Close button clicked
81 /// Pointer to the actual instantiation of the Qt dialog
82 virtual QDialog * form() const = 0;
86 template <class GUIDialog>
87 class QView: public QDialogView {
89 QView(Dialog &, std::string const &);
92 virtual void update();
97 /// Pointer to the actual instantiation of the Qt dialog
98 virtual QDialog * form() const;
100 /// Real GUI implementation.
101 boost::scoped_ptr<GUIDialog> dialog_;
106 template <class GUIDialog>
107 QView<GUIDialog>::QView(Dialog & p, std::string const & t)
112 template <class GUIDialog>
113 QDialog * QView<GUIDialog>::form() const
115 /* Brain dead MSVC compiler wants to know the class hierarchy at the
116 definition site of the template, rather than the instantation point
117 to downcast correctly. So, rather than including all dialogs to
118 provide that, we just cast it with the ugly hammer. */
119 return (QDialog *) dialog_.get();
123 template <class GUIDialog>
124 void QView<GUIDialog>::update()
126 form()->setUpdatesEnabled(false);
128 // protect the BC from unwarranted state transitions
134 form()->setUpdatesEnabled(true);
139 template <class GUIDialog>
140 void QView<GUIDialog>::build()
142 // protect the BC from unwarranted state transitions
150 template <class Controller, class Base>
151 class QController: public Base
155 QController(Dialog &, std::string const &);
157 /// The parent controller
158 Controller & controller();
159 /// The parent controller
160 Controller const & controller() const;
164 template <class Controller, class Base>
165 QController<Controller, Base>::QController(Dialog & p, std::string const & t)
170 template <class Controller, class Base>
171 Controller & QController<Controller, Base>::controller()
173 return static_cast<Controller &>(this->getController());
177 template <class Controller, class Base>
178 Controller const & QController<Controller, Base>::controller() const
180 return static_cast<Controller const &>(this->getController());
183 } // namespace frontend
186 #endif // QDIALOGVIEW_H