]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/Qt2Base.h
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / Qt2Base.h
index 360dc6e1e5b096ddbfe09e1f758e41d24eee93fe..2491a9895c448ddb5f9f5ea12836b97198be5eda 100644 (file)
@@ -1,73 +1,68 @@
 // -*- C++ -*-
-/* This file is part of
- * ======================================================
+/**
+ * \file Qt2Base.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *                LyX, The Document Processor
+ * \author Angus Leeming
  *
- *                Copyright 2000 The LyX Team.
- *
- * ======================================================
- *
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * Full author contact details are available in file CREDITS
  */
 
 #ifndef QT2BASE_H
 #define QT2BASE_H
 
-class QDialog;
-
-#include <config.h> 
-#include <qfont.h>
-#include <qobject.h>
-
 #ifdef __GNUG__
 #pragma interface
 #endif
 
 #include "ViewBase.h"
-#include "LString.h"
-#include "ButtonPolicies.h"
-#include "ControlButtons.h"
+#include <boost/scoped_ptr.hpp>
 
-#include <boost/smart_ptr.hpp>
+#include <qfont.h>
+#include <qdialog.h>
+#include <qobject.h>
+#include <qapplication.h>
 
 class Qt2BC;
 
 /** This class is an Qt2 GUI base class.
  */
-class Qt2Base : public QObject, public ViewBC<Qt2BC>
-{
+class Qt2Base : public QObject, public ViewBase {
        Q_OBJECT
 public:
        ///
-       Qt2Base(ControlButtons &, const QString &);
+       Qt2Base(QString const &);
        ///
        virtual ~Qt2Base() {}
-
 protected:
-       /// Build the dialog
-       virtual void build() = 0;
+       /// 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();
-       /// reset after an update
-       virtual void reset();
+       /// update the dialog's contents
+       virtual void update_contents() = 0;
 
        /// the dialog has changed contents
-       virtual void changed(); 
+       virtual void changed();
 
-       /// is the dialog currently valid ? 
+       /// 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();
 
@@ -76,25 +71,30 @@ protected slots:
 
        // Close button clicked
        void slotClose();
-
 private:
        /// Pointer to the actual instantiation of xform's form
-       virtual QDialog* form() const = 0;
+       virtual QDialog * form() const = 0;
 
 private:
        /// dialog title, displayed by WM.
-       QString title_;
+       QString title_;
 };
 
 
 template <class Dialog>
-class Qt2DB: public Qt2Base
-{
+class Qt2DB: public Qt2Base {
 protected:
-       Qt2DB(ControlButtons &, const QString&);
+       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;
+       virtual QDialog * form() const;
+
        /// Real GUI implementation.
        boost::scoped_ptr<Dialog> dialog_;
 
@@ -102,40 +102,84 @@ protected:
 
 
 template <class Dialog>
-Qt2DB<Dialog>::Qt2DB(ControlButtons & c, const QString& t)
-       : Qt2Base(c, t)
+Qt2DB<Dialog>::Qt2DB(QString const & t)
+       : Qt2Base(t)
 {}
 
 
 template <class Dialog>
-QDialog* Qt2DB<Dialog>::form() const
+QDialog * Qt2DB<Dialog>::form() const
 {
        return dialog_.get();
 }
 
 
+template <class Dialog>
+void Qt2DB<Dialog>::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 <class Dialog>
+void Qt2DB<Dialog>::build()
+{
+       // protect the BC from unwarranted state transitions
+
+       qApp->processEvents();
+       updating_ = true;
+       build_dialog();
+       qApp->processEvents();
+       updating_ = false;
+}
+
+
 template <class Controller, class Base>
 class Qt2CB: public Base
 {
+public:
+       bool readOnly() const {
+               return controller().bufferIsReadonly();
+       }
+
 protected:
        ///
-       Qt2CB(ControlButtons &, const QString&);
+       Qt2CB(QString const &);
+       /// The parent controller
+       Controller & controller();
        /// The parent controller
-       Controller & controller() const;
+       Controller const & controller() const;
 };
 
 
 template <class Controller, class Base>
-Qt2CB<Controller, Base>::Qt2CB(ControlButtons & c, const QString& t)
-       : Base(c, t)
+Qt2CB<Controller, Base>::Qt2CB(QString const & t)
+       : Base(t)
 {}
 
 
 template <class Controller, class Base>
-Controller & Qt2CB<Controller, Base>::controller() const
+Controller & Qt2CB<Controller, Base>::controller()
+{
+       return static_cast<Controller &>(getController());
+}
+
+
+template <class Controller, class Base>
+Controller const & Qt2CB<Controller, Base>::controller() const
 {
-       return static_cast<Controller &>(controller_);
-       //return dynamic_cast<Controller &>(controller_);
+       return static_cast<Controller const &>(getController());
 }