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>
30 #include "ButtonPolicies.h"
31 #include "ControlButtons.h"
33 #include <boost/smart_ptr.hpp>
37 /** This class is an Qt2 GUI base class.
39 class Qt2Base : public QObject, public ViewBC<Qt2BC>
44 Qt2Base(ControlButtons &, const QString &);
50 virtual void build() = 0;
53 /// Create the dialog if necessary, update it and display it.
55 /// update the dialog's contents
56 virtual void update_contents() = 0;
58 /// the dialog has changed contents
59 virtual void changed();
61 /// is the dialog currently valid ?
62 virtual bool isValid();
68 // dialog closed from WM
71 // Restore button clicked
77 // Apply button clicked
80 // Close button clicked
84 /// Pointer to the actual instantiation of xform's form
85 virtual QDialog* form() const = 0;
88 /// dialog title, displayed by WM.
93 template <class Dialog>
94 class Qt2DB: public Qt2Base
97 Qt2DB(ControlButtons &, const QString &);
100 virtual void update();
102 /// Pointer to the actual instantiation of the Qt dialog
103 virtual QDialog * form() const;
104 /// Real GUI implementation.
105 boost::scoped_ptr<Dialog> dialog_;
110 template <class Dialog>
111 Qt2DB<Dialog>::Qt2DB(ControlButtons & c, const QString & t)
116 template <class Dialog>
117 QDialog * Qt2DB<Dialog>::form() const
119 return dialog_.get();
123 template <class Dialog>
124 void Qt2DB<Dialog>::update()
126 form()->setUpdatesEnabled(false);
128 // this is tricky. First we process pending events
129 // as a result of the bc() state change (if any).
130 // then we lock out any bc() changes as a result of
131 // "innocent" updates during update_contents()
132 // then we enable normal behaviour again.
133 qApp->processEvents();
136 qApp->processEvents();
139 form()->setUpdatesEnabled(true);
144 template <class Controller, class Base>
145 class Qt2CB: public Base
149 Qt2CB(ControlButtons &, const QString&);
150 /// The parent controller
151 Controller & controller() const;
155 template <class Controller, class Base>
156 Qt2CB<Controller, Base>::Qt2CB(ControlButtons & c, const QString& t)
161 template <class Controller, class Base>
162 Controller & Qt2CB<Controller, Base>::controller() const
164 return static_cast<Controller &>(controller_);
165 //return dynamic_cast<Controller &>(controller_);