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.h>
25 /** This class is an Qt2 GUI base class.
27 class Qt2Base : public QObject, public ViewBase {
31 Qt2Base(std::string const &);
35 /// build the actual dialog
36 virtual void build_dialog() = 0;
39 /// Create the dialog if necessary, update it and display it.
41 /// update the dialog's contents
42 virtual void update_contents() = 0;
44 virtual bool isVisible() const;
46 /// the dialog has changed contents
47 virtual void changed();
49 /// is the dialog currently valid ?
50 virtual bool isValid();
58 // dialog closed from WM
61 // Restore button clicked
67 // Apply button clicked
70 // Close button clicked
73 /// Pointer to the actual instantiation of the Qt dialog
74 virtual QDialog * form() const = 0;
78 template <class Dialog>
79 class Qt2DB: public Qt2Base {
81 Qt2DB(std::string const &);
84 virtual void update();
89 /// Pointer to the actual instantiation of the Qt dialog
90 virtual QDialog * form() const;
92 /// Real GUI implementation.
93 boost::scoped_ptr<Dialog> dialog_;
98 template <class Dialog>
99 Qt2DB<Dialog>::Qt2DB(std::string const & t)
104 template <class Dialog>
105 QDialog * Qt2DB<Dialog>::form() const
107 return dialog_.get();
111 template <class Dialog>
112 void Qt2DB<Dialog>::update()
114 form()->setUpdatesEnabled(false);
116 // protect the BC from unwarranted state transitions
118 qApp->processEvents();
121 qApp->processEvents();
124 form()->setUpdatesEnabled(true);
129 template <class Dialog>
130 void Qt2DB<Dialog>::build()
132 // protect the BC from unwarranted state transitions
134 qApp->processEvents();
137 qApp->processEvents();
142 template <class Controller, class Base>
143 class Qt2CB: public Base
146 bool readOnly() const {
147 return controller().bufferIsReadonly();
150 /// The parent controller
151 Controller & controller();
152 /// The parent controller
153 Controller const & controller() const;
157 Qt2CB(std::string const &);
161 template <class Controller, class Base>
162 Qt2CB<Controller, Base>::Qt2CB(std::string const & t)
167 template <class Controller, class Base>
168 Controller & Qt2CB<Controller, Base>::controller()
170 return static_cast<Controller &>(this->getController());
174 template <class Controller, class Base>
175 Controller const & Qt2CB<Controller, Base>::controller() const
177 return static_cast<Controller const &>(this->getController());