4 * Copyright 2000-2002 the LyX Team
5 * Read the file COPYING
7 * \author Angus Leeming <a.leeming@ic.ac.uk>
23 #include "ButtonPolicies.h"
24 #include "ControlButtons.h"
26 #include <boost/scoped_ptr.hpp>
31 #include <qapplication.h>
35 /** This class is an Qt2 GUI base class.
37 class Qt2Base : public QObject, public ViewBC<Qt2BC>
42 Qt2Base(ControlButtons &, QString const &);
47 /// build the actual dialog
48 virtual void build_dialog() = 0;
51 /// Create the dialog if necessary, update it and display it.
53 /// update the dialog's contents
54 virtual void update_contents() = 0;
56 /// the dialog has changed contents
57 virtual void changed();
59 /// is the dialog currently valid ?
60 virtual bool isValid();
66 // dialog closed from WM
69 // Restore button clicked
75 // Apply button clicked
78 // Close button clicked
82 /// Pointer to the actual instantiation of xform's form
83 virtual QDialog * form() const = 0;
86 /// dialog title, displayed by WM.
91 template <class Dialog>
92 class Qt2DB: public Qt2Base
95 Qt2DB(ControlButtons &, QString const &);
98 virtual void update();
101 virtual void build();
103 /// Pointer to the actual instantiation of the Qt dialog
104 virtual QDialog * form() const;
106 /// Real GUI implementation.
107 boost::scoped_ptr<Dialog> dialog_;
112 template <class Dialog>
113 Qt2DB<Dialog>::Qt2DB(ControlButtons & c, QString const & t)
118 template <class Dialog>
119 QDialog * Qt2DB<Dialog>::form() const
121 return dialog_.get();
125 template <class Dialog>
126 void Qt2DB<Dialog>::update()
128 form()->setUpdatesEnabled(false);
130 // protect the BC from unwarranted state transitions
132 qApp->processEvents();
135 qApp->processEvents();
138 form()->setUpdatesEnabled(true);
143 template <class Dialog>
144 void Qt2DB<Dialog>::build()
146 // protect the BC from unwarranted state transitions
148 qApp->processEvents();
151 qApp->processEvents();
156 template <class Controller, class Base>
157 class Qt2CB: public Base
160 bool readOnly() const {
161 return controller().isReadonly();
166 Qt2CB(ControlButtons &, QString const &);
167 /// The parent controller
168 Controller & controller() const;
172 template <class Controller, class Base>
173 Qt2CB<Controller, Base>::Qt2CB(ControlButtons & c, QString const & t)
178 template <class Controller, class Base>
179 Controller & Qt2CB<Controller, Base>::controller() const
181 return static_cast<Controller &>(controller_);
182 //return dynamic_cast<Controller &>(controller_);