// -*- C++ -*- /** * \file Qt2Base.h * Copyright 2000-2002 the LyX Team * Read the file COPYING * * \author Angus Leeming */ #ifndef QT2BASE_H #define QT2BASE_H #include #ifdef __GNUG__ #pragma interface #endif #include "ViewBase.h" #include "LString.h" #include "debug.h" #include "ButtonPolicies.h" #include #include #include #include #include class Qt2BC; /** This class is an Qt2 GUI base class. */ class Qt2Base : public QObject, public ViewBase { Q_OBJECT public: /// Qt2Base(QString const &); /// virtual ~Qt2Base() {} protected: /// build the actual dialog virtual void build_dialog() = 0; /// Hide the dialog. virtual void hide(); /// Create the dialog if necessary, update it and display it. virtual void show(); /// update the dialog's contents virtual void update_contents() = 0; /// the dialog has changed contents virtual void changed(); /// is the dialog currently valid ? virtual bool isValid(); /// Qt2BC & bc(); /// are we updating ? bool updating_; protected slots: // dialog closed from WM void slotWMHide(); // Restore button clicked void slotRestore(); // OK button clicked void slotOK(); // Apply button clicked void slotApply(); // Close button clicked void slotClose(); private: /// Pointer to the actual instantiation of xform's form virtual QDialog * form() const = 0; private: /// dialog title, displayed by WM. QString title_; }; template class Qt2DB: public Qt2Base { protected: Qt2DB(QString const &); /// update the dialog virtual void update(); /// Build the dialog virtual void build(); /// Pointer to the actual instantiation of the Qt dialog virtual QDialog * form() const; /// Real GUI implementation. boost::scoped_ptr dialog_; }; template Qt2DB::Qt2DB(QString const & t) : Qt2Base(t) {} template QDialog * Qt2DB::form() const { return dialog_.get(); } template void Qt2DB::update() { form()->setUpdatesEnabled(false); // protect the BC from unwarranted state transitions qApp->processEvents(); updating_ = true; update_contents(); qApp->processEvents(); updating_ = false; form()->setUpdatesEnabled(true); form()->update(); } template void Qt2DB::build() { // protect the BC from unwarranted state transitions qApp->processEvents(); updating_ = true; build_dialog(); qApp->processEvents(); updating_ = false; } template class Qt2CB: public Base { public: bool readOnly() const { return controller().isReadonly(); } protected: /// Qt2CB(QString const &); /// The parent controller Controller & controller(); /// The parent controller Controller const & controller() const; }; template Qt2CB::Qt2CB(QString const & t) : Base(t) {} template Controller & Qt2CB::controller() { return static_cast(getController()); } template Controller const & Qt2CB::controller() const { return static_cast(getController()); } #endif // FORMBASE_H