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