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