2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
11 * \author Angus Leeming <a.leeming@ic.ac.uk>
22 #include <qapplication.h>
31 #include "ButtonPolicies.h"
32 #include "ControlButtons.h"
34 #include <boost/smart_ptr.hpp>
38 /** This class is an Qt2 GUI base class.
40 class Qt2Base : public QObject, public ViewBC<Qt2BC>
45 Qt2Base(ControlButtons &, QString const &);
50 /// build the actual dialog
51 virtual void build_dialog() = 0;
54 /// Create the dialog if necessary, update it and display it.
56 /// update the dialog's contents
57 virtual void update_contents() = 0;
59 /// the dialog has changed contents
60 virtual void changed();
62 /// is the dialog currently valid ?
63 virtual bool isValid();
69 // dialog closed from WM
72 // Restore button clicked
78 // Apply button clicked
81 // Close button clicked
85 /// Pointer to the actual instantiation of xform's form
86 virtual QDialog * form() const = 0;
89 /// dialog title, displayed by WM.
94 template <class Dialog>
95 class Qt2DB: public Qt2Base
98 Qt2DB(ControlButtons &, QString const &);
100 /// update the dialog
101 virtual void update();
104 virtual void build();
106 /// Pointer to the actual instantiation of the Qt dialog
107 virtual QDialog * form() const;
109 /// Real GUI implementation.
110 boost::scoped_ptr<Dialog> dialog_;
115 template <class Dialog>
116 Qt2DB<Dialog>::Qt2DB(ControlButtons & c, QString const & t)
121 template <class Dialog>
122 QDialog * Qt2DB<Dialog>::form() const
124 return dialog_.get();
128 template <class Dialog>
129 void Qt2DB<Dialog>::update()
131 form()->setUpdatesEnabled(false);
133 // protect the BC from unwarranted state transitions
135 qApp->processEvents();
138 qApp->processEvents();
141 form()->setUpdatesEnabled(true);
146 template <class Dialog>
147 void Qt2DB<Dialog>::build()
149 // protect the BC from unwarranted state transitions
151 qApp->processEvents();
154 qApp->processEvents();
159 template <class Controller, class Base>
160 class Qt2CB: public Base
163 bool readOnly() const {
164 return controller().isReadonly();
169 Qt2CB(ControlButtons &, QString const &);
170 /// The parent controller
171 Controller & controller() const;
175 template <class Controller, class Base>
176 Qt2CB<Controller, Base>::Qt2CB(ControlButtons & c, QString const & t)
181 template <class Controller, class Base>
182 Controller & Qt2CB<Controller, Base>::controller() const
184 return static_cast<Controller &>(controller_);
185 //return dynamic_cast<Controller &>(controller_);