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