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
20 #include <boost/scoped_ptr.hpp>
25 #include <qapplication.h>
29 /** This class is an Qt2 GUI base class.
31 class Qt2Base : public QObject, public ViewBase {
35 Qt2Base(QString const &);
39 /// build the actual dialog
40 virtual void build_dialog() = 0;
43 /// Create the dialog if necessary, update it and display it.
45 /// update the dialog's contents
46 virtual void update_contents() = 0;
48 /// the dialog has changed contents
49 virtual void changed();
51 /// is the dialog currently valid ?
52 virtual bool isValid();
60 // dialog closed from WM
63 // Restore button clicked
69 // Apply button clicked
72 // Close button clicked
75 /// Pointer to the actual instantiation of xform's form
76 virtual QDialog * form() const = 0;
79 /// dialog title, displayed by WM.
84 template <class Dialog>
85 class Qt2DB: public Qt2Base {
87 Qt2DB(QString const &);
90 virtual void update();
95 /// Pointer to the actual instantiation of the Qt dialog
96 virtual QDialog * form() const;
98 /// Real GUI implementation.
99 boost::scoped_ptr<Dialog> dialog_;
104 template <class Dialog>
105 Qt2DB<Dialog>::Qt2DB(QString const & t)
110 template <class Dialog>
111 QDialog * Qt2DB<Dialog>::form() const
113 return dialog_.get();
117 template <class Dialog>
118 void Qt2DB<Dialog>::update()
120 form()->setUpdatesEnabled(false);
122 // protect the BC from unwarranted state transitions
124 qApp->processEvents();
127 qApp->processEvents();
130 form()->setUpdatesEnabled(true);
135 template <class Dialog>
136 void Qt2DB<Dialog>::build()
138 // protect the BC from unwarranted state transitions
140 qApp->processEvents();
143 qApp->processEvents();
148 template <class Controller, class Base>
149 class Qt2CB: public Base
152 bool readOnly() const {
153 return controller().bufferIsReadonly();
158 Qt2CB(QString const &);
159 /// The parent controller
160 Controller & controller();
161 /// The parent controller
162 Controller const & controller() const;
166 template <class Controller, class Base>
167 Qt2CB<Controller, Base>::Qt2CB(QString const & t)
172 template <class Controller, class Base>
173 Controller & Qt2CB<Controller, Base>::controller()
175 return static_cast<Controller &>(getController());
179 template <class Controller, class Base>
180 Controller const & Qt2CB<Controller, Base>::controller() const
182 return static_cast<Controller const &>(getController());