]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/Qt2Base.h
Clean-up of the button controller.
[lyx.git] / src / frontends / qt2 / Qt2Base.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *                 LyX, The Document Processor
6  *
7  *                 Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  *
11  * \author Angus Leeming <a.leeming@ic.ac.uk>
12  */
13
14 #ifndef QT2BASE_H
15 #define QT2BASE_H
16
17 class QDialog;
18
19 #include <config.h> 
20  
21 #include <qfont.h>
22 #include <qobject.h>
23
24 #include <boost/smart_ptr.hpp>
25
26 #ifdef __GNUG__
27 #pragma interface
28 #endif
29
30 #include "ViewBase.h"
31 #include "LString.h"
32 #include "ButtonPolicies.h"
33 #include "ControlButtons.h"
34
35 class qt2BC;
36
37 /** This class is an Qt2 GUI base class.
38  */
39 class Qt2Base : public QObject, public ViewBC<qt2BC>
40 {
41         Q_OBJECT
42 public:
43         ///
44         Qt2Base(ControlButtons &, const QString &);
45         ///
46         virtual ~Qt2Base() {}
47
48 protected:
49         /// Build the dialog
50         virtual void build() = 0;
51         /// Hide the dialog.
52         void hide();
53         /// Create the dialog if necessary, update it and display it.
54         void show();
55
56 protected slots:
57         // dialog closed from WM
58         void slotWMHide();
59
60         // Apply button clicked
61         void slotApply();
62
63         // OK button clicked
64         void slotOK();
65
66         // Cancel button clicked
67         void slotCancel();
68
69         // Restore button clicked
70         void slotRestore();
71
72 private:
73         /// Pointer to the actual instantiation of xform's form
74         virtual QDialog* form() const = 0;
75         /** Filter the inputs on callback from xforms
76                 Return true if inputs are valid. */
77         virtual ButtonPolicy::SMInput input(QWidget*, long);
78
79 private:
80         /// dialog title, displayed by WM.
81         QString title_;
82 };
83
84
85 template <class Dialog>
86 class Qt2DB: public Qt2Base
87 {
88 protected:
89         ///
90         Qt2DB(ControlButtons &, const QString&);
91         /// Pointer to the actual instantiation of the Qt dialog
92         virtual QDialog* form() const;
93         /// Real GUI implementation.
94         boost::scoped_ptr<Dialog> dialog_;
95 };
96
97
98 template <class Dialog>
99 Qt2DB<Dialog>::Qt2DB(ControlButtons & c, const QString& t)
100         : Qt2Base(c, t)
101 {}
102
103
104 template <class Dialog>
105 QDialog* Qt2DB<Dialog>::form() const
106 {
107         return dialog_.get();
108 }
109
110
111 template <class Controller, class Base>
112 class Qt2CB: public Base
113 {
114 protected:
115         ///
116         Qt2CB(ControlButtons &, const QString&);
117         /// The parent controller
118         Controller & controller() const;
119 };
120
121
122 template <class Controller, class Base>
123 Qt2CB<Controller, Base>::Qt2CB(ControlButtons & c, const QString& t)
124         : Base(c, t)
125 {}
126
127
128 template <class Controller, class Base>
129 Controller & Qt2CB<Controller, Base>::controller() const
130 {
131         return static_cast<Controller &>(controller_);
132         //return dynamic_cast<Controller &>(controller_);
133 }
134
135
136 #endif // FORMBASE_H