// -*- C++ -*- /** * \file QDialogView.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author Angus Leeming * * Full author contact details are available in file CREDITS. */ #ifndef QDIALOGVIEW_H #define QDIALOGVIEW_H #include "Dialog.h" #include #include #include #include namespace lyx { namespace frontend { class Qt2BC; /** This class is an Qt2 GUI base class. */ class QDialogView : public QObject, public Dialog::View { Q_OBJECT public: /// QDialogView(Dialog &, docstring const &); /// virtual ~QDialogView() {} /// bool readOnly() const; /// the dialog has changed contents virtual void changed(); /// Qt2BC & bcview(); protected: /// build the actual dialog virtual void build_dialog() = 0; /// virtual void build() = 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; /// virtual bool isVisible() const; /// is the dialog currently valid ? virtual bool isValid(); /// are we updating ? bool updating_; public Q_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 the Qt dialog virtual QDialog * form() const = 0; }; template class QView: public QDialogView { protected: QView(Dialog &, docstring 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 QView::QView(Dialog & p, docstring const & t) : QDialogView(p, t) {} template QDialog * QView::form() const { return dialog_.get(); } template void QView::update() { form()->setUpdatesEnabled(false); // protect the BC from unwarranted state transitions updating_ = true; update_contents(); updating_ = false; form()->setUpdatesEnabled(true); form()->update(); } template void QView::build() { // protect the BC from unwarranted state transitions updating_ = true; build_dialog(); updating_ = false; } template class QController: public Base { protected: /// QController(Dialog &, docstring const &); public: /// The parent controller Controller & controller(); /// The parent controller Controller const & controller() const; }; template QController::QController(Dialog & p, docstring const & t) : Base(p, t) {} template Controller & QController::controller() { return static_cast(this->getController()); } template Controller const & QController::controller() const { return static_cast(this->getController()); } } // namespace frontend } // namespace lyx #endif // QDIALOGVIEW_H