]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QDialogView.h
* src/frontends/qt4/ui/TextLayoutUi.ui:
[lyx.git] / src / frontends / qt4 / QDialogView.h
1 // -*- C++ -*-
2 /**
3  * \file QDialogView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef QDIALOGVIEW_H
13 #define QDIALOGVIEW_H
14
15 #include "Dialog.h"
16
17 #include <boost/scoped_ptr.hpp>
18
19 #include <QApplication>
20 #include <QWidget>
21 #include <QObject>
22
23 namespace lyx {
24 namespace frontend {
25
26 class Qt2BC;
27
28 /** This class is an Qt2 GUI base class.
29  */
30 class QDialogView : public QObject, public Dialog::View {
31         Q_OBJECT
32 public:
33         ///
34         QDialogView(Dialog &, docstring const &);
35         ///
36         virtual ~QDialogView() {}
37         ///
38         bool readOnly() const;
39
40         /// the dialog has changed contents
41         virtual void changed();
42
43         ///
44         Qt2BC & bcview();
45
46 protected:
47         /// build the actual dialog
48         virtual void build_dialog() = 0;
49         ///
50         virtual void build() = 0;
51         /// Hide the dialog.
52         virtual void hide();
53         /// Create the dialog if necessary, update it and display it.
54         virtual void show();
55         /// update the dialog's contents
56         virtual void update_contents() = 0;
57         ///
58         virtual bool isVisible() const;
59
60         /// is the dialog currently valid ?
61         virtual bool isValid();
62
63         /// are we updating ?
64         bool updating_;
65
66 public Q_SLOTS:
67         // dialog closed from WM
68         void slotWMHide();
69
70         // Restore button clicked
71         void slotRestore();
72
73         // OK button clicked
74         void slotOK();
75
76         // Apply button clicked
77         void slotApply();
78
79         // Close button clicked
80         void slotClose();
81 private:
82         /// Pointer to the actual instantiation of the Qt dialog
83         virtual QWidget * form() const = 0;
84 };
85
86
87 template <class GUIDialog>
88 class QView: public QDialogView {
89 protected:
90         QView(Dialog & p, docstring const & t): QDialogView(p, t)
91         {}
92
93         virtual ~QView() {}
94
95         /// update the dialog
96         virtual void update() {
97                 dialog_->setUpdatesEnabled(false);
98
99                 // protect the BC from unwarranted state transitions
100                 updating_ = true;
101                 update_contents();
102                 updating_ = false;
103
104                 dialog_->setUpdatesEnabled(true);
105                 dialog_->update();
106         }
107
108         /// Build the dialog
109         virtual void build() {
110                 // protect the BC from unwarranted state transitions
111                 updating_ = true;
112                 build_dialog();
113                 updating_ = false;
114         }
115
116         /// Pointer to the actual instantiation of the Qt dialog
117         virtual GUIDialog * form() const { return dialog_.get(); }
118
119         /// Real GUI implementation.
120         boost::scoped_ptr<GUIDialog> dialog_;
121 };
122
123
124 template <class Controller, class Base>
125 class QController: public Base
126 {
127 protected:
128         ///
129         QController(Dialog & p, docstring const & t): Base(p, t)
130         {}
131 public:
132         /// The parent controller
133         Controller & controller()
134         { return static_cast<Controller &>(this->getController()); }
135
136         /// The parent controller
137         Controller const & controller() const
138         { return static_cast<Controller const &>(this->getController()); }
139 };
140
141 } // namespace frontend
142 } // namespace lyx
143
144 #endif // QDIALOGVIEW_H