]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/Qt2Base.h
some small updates
[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 #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 #include <boost/smart_ptr.hpp>
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         /// the dialog has changed contents
57         virtual void changed(); 
58
59         /// is the dialog currently valid ? 
60         virtual bool isValid();
61  
62 protected slots:
63         // dialog closed from WM
64         void slotWMHide();
65
66         // Apply button clicked
67         void slotApply();
68
69         // OK button clicked
70         void slotOK();
71
72         // Cancel button clicked
73         void slotCancel();
74
75         // Restore button clicked
76         void slotRestore();
77
78 private:
79         /// Pointer to the actual instantiation of xform's form
80         virtual QDialog* form() const = 0;
81
82 private:
83         /// dialog title, displayed by WM.
84         QString title_;
85 };
86
87
88 template <class Dialog>
89 class Qt2DB: public Qt2Base
90 {
91 protected:
92         ///
93         Qt2DB(ControlButtons &, const QString&);
94         /// Pointer to the actual instantiation of the Qt dialog
95         virtual QDialog* form() const;
96         /// Real GUI implementation.
97         boost::scoped_ptr<Dialog> dialog_;
98 };
99
100
101 template <class Dialog>
102 Qt2DB<Dialog>::Qt2DB(ControlButtons & c, const QString& t)
103         : Qt2Base(c, t)
104 {}
105
106
107 template <class Dialog>
108 QDialog* Qt2DB<Dialog>::form() const
109 {
110         return dialog_.get();
111 }
112
113
114 template <class Controller, class Base>
115 class Qt2CB: public Base
116 {
117 protected:
118         ///
119         Qt2CB(ControlButtons &, const QString&);
120         /// The parent controller
121         Controller & controller() const;
122 };
123
124
125 template <class Controller, class Base>
126 Qt2CB<Controller, Base>::Qt2CB(ControlButtons & c, const QString& t)
127         : Base(c, t)
128 {}
129
130
131 template <class Controller, class Base>
132 Controller & Qt2CB<Controller, Base>::controller() const
133 {
134         return static_cast<Controller &>(controller_);
135         //return dynamic_cast<Controller &>(controller_);
136 }
137
138
139 #endif // FORMBASE_H