Developer Documentation

QtApplication.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43
44
45
46 //=============================================================================
47 //
48 // CLASS QtApplication
49 //
50 //=============================================================================
51
52 #ifndef QTAPPLICATION_HH
53 #define QTAPPLICATION_HH
54
55
56 //== INCLUDES =================================================================
57
58
59 // Qt
60 #include <QApplication>
61 #include <QObject>
62 #include <QEvent>
63 #include <QDateTime>
64
65 #include <QTimerEvent>
66
67 // stdc++
68 #include <vector>
69 #include <string>
70 #include <iostream>
71
72 #include "../Config/ACGDefines.hh"
73
74
75 //== FORWARD DECLARATIONS =====================================================
76
77
78 namespace ACG {
79 namespace QtWidgets {
80 class QtMacroDialog;
81 }
82 }
83
84
85 //== NAMESPACES ===============================================================
86
87
88 namespace ACG {
89 namespace QtWidgets {
90
91
92 //== CLASS DEFINITION =========================================================
93
94
95 class ACGDLLEXPORT QtApplication : public QApplication
96 {
97 Q_OBJECT
98
99 public:
100
101 QtApplication(int _argc, char** _argv);
102 virtual ~QtApplication() { cleanUpEventBuffer(); }
103
104
105 public slots:
106
107 // save recorded Events to file
108 void saveFile(const char* _filename);
109
110 // load recorded Events from file
111 void loadFile(const char* _filename);
112
113 // start playback
114 void play();
115
116 // stop playback or record
117 void stop();
118
119 // record
120 void record();
121
122 // change loop status for playback
123 void loop(bool _b);
124
125
126 public:
127
128 // filter events
129 bool notify (QObject* _receiver, QEvent* _event);
130
131
132 private:
133
134 // information for one event
135 struct FootPrint
136 {
137 int time;
138 std::string name;
139 std::string classname;
140 std::string parent;
141 QPoint cursorPos;
142 QPoint position;
143 QSize size;
144 QEvent *event;
145 };
146
147 typedef std::vector<FootPrint> FootPrints;
148 typedef FootPrints::iterator FootPrintIter;
149
150
151 // record and play events
152 void recordEvent(QObject* _receiver, QEvent* _event);
153 void playbackEvent(FootPrint & _fp);
154
155
156 // store and restore sizes of all top-level widgets
157 void storeTopLevelSizes();
158 void restoreTopLevelSizes();
159
160 // load and save sizes of top-level widgets
161 void saveTopLevelSizes(std::ostream & _os);
162 void loadTopLevelSizes(std::istream & _is);
163
164
165 // find Widget for event _fp
166 QWidget* findWidget(FootPrint & _fp);
167 // timer callback
168 void timerEvent(QTimerEvent* _e);
169 // clear event buffer (pointers to QEvent)
170 void cleanUpEventBuffer();
171
172
173 private:
174
175 // state variables
176 bool record_;
177 bool playback_;
178 bool play_loop_;
179
180 // counter
181 unsigned int eventnr_;
182
183 // timer ID
184 int timer_id_;
185
186 // stop Time
187 QTime time_;
188
189 // vector to store events and top-levels sizes
190 FootPrints events_, toplevels_;
191
192 // macro dialog for interaction
193 QtMacroDialog* dialog_;
194
195 // Pointer to MainWidget
196 QWidget* mainWidget_;
197
198 // Main widget pos
199 QPoint mainWidgetDiff_;
200
201 // Old Main widget pos
202 QPoint oldMainWidgetPos_;
203 };
204
205 //=============================================================================
206 } // namespace QtWidgets
207 } // namespace ACG
208 //=============================================================================
209 #endif // MACROAPPLICATION_HH defined
210 //=============================================================================
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::QtWidgets::QtApplication
Definition: QtApplication.hh:95
ACG::QtWidgets::QtApplication::FootPrint
Definition: QtApplication.hh:135