]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiDialogView.h
d0eba362bc573f01351a74ab012658c6c7a06e30
[features.git] / src / frontends / qt4 / GuiDialogView.h
1 // -*- C++ -*-
2 /**
3  * \file GuiDialogView.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 GUIDIALOGVIEW_H
13 #define GUIDIALOGVIEW_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 GuiDialogView : public QObject, public Dialog::View {
31         Q_OBJECT
32 public:
33         ///
34         GuiDialogView(Dialog &, docstring const &);
35         ///
36         virtual ~GuiDialogView() {}
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 GuiView : public GuiDialogView {
89 protected:
90         GuiView(Dialog & p, docstring const & t)
91                 : GuiDialogView(p, t)
92         {}
93
94         virtual ~GuiView() {}
95
96         /// update the dialog
97         virtual void update() {
98                 dialog_->setUpdatesEnabled(false);
99
100                 // protect the BC from unwarranted state transitions
101                 updating_ = true;
102                 update_contents();
103                 updating_ = false;
104
105                 dialog_->setUpdatesEnabled(true);
106                 dialog_->update();
107         }
108
109         /// Build the dialog
110         virtual void build() {
111                 // protect the BC from unwarranted state transitions
112                 updating_ = true;
113                 build_dialog();
114                 updating_ = false;
115         }
116
117         /// Pointer to the actual instantiation of the Qt dialog
118         virtual GUIDialog * form() const { return dialog_.get(); }
119
120         /// Real GUI implementation.
121         boost::scoped_ptr<GUIDialog> dialog_;
122 };
123
124 } // namespace frontend
125 } // namespace lyx
126
127 #endif // GUIDIALOGVIEW_H