Developer Documentation
Loading...
Searching...
No Matches
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 <QElapsedTimer>
64#include <QTimerEvent>
65
66// stdc++
67#include <vector>
68#include <string>
69#include <iostream>
70
71#include "../Config/ACGDefines.hh"
72
73
74//== FORWARD DECLARATIONS =====================================================
75
76
77namespace ACG {
78namespace QtWidgets {
79 class QtMacroDialog;
80}
81}
82
83
84//== NAMESPACES ===============================================================
85
86
87namespace ACG {
88namespace QtWidgets {
89
90
91//== CLASS DEFINITION =========================================================
92
93
94class ACGDLLEXPORT QtApplication : public QApplication
95{
96 Q_OBJECT
97
98public:
99
100 QtApplication(int _argc, char** _argv);
101 virtual ~QtApplication() { cleanUpEventBuffer(); }
102
103
104public slots:
105
106 // save recorded Events to file
107 void saveFile(const char* _filename);
108
109 // load recorded Events from file
110 void loadFile(const char* _filename);
111
112 // start playback
113 void play();
114
115 // stop playback or record
116 void stop();
117
118 // record
119 void record();
120
121 // change loop status for playback
122 void loop(bool _b);
123
124
125public:
126
127 // filter events
128 bool notify (QObject* _receiver, QEvent* _event);
129
130
131private:
132
133 // information for one event
135 {
136 int time;
137 std::string name;
138 std::string classname;
139 std::string parent;
140 QPoint cursorPos;
141 QPoint position;
142 QSize size;
143 QEvent *event;
144 };
145
146 typedef std::vector<FootPrint> FootPrints;
147 typedef FootPrints::iterator FootPrintIter;
148
149
150 // record and play events
151 void recordEvent(QObject* _receiver, QEvent* _event);
152 void playbackEvent(FootPrint & _fp);
153
154
155 // store and restore sizes of all top-level widgets
156 void storeTopLevelSizes();
157 void restoreTopLevelSizes();
158
159 // load and save sizes of top-level widgets
160 void saveTopLevelSizes(std::ostream & _os);
161 void loadTopLevelSizes(std::istream & _is);
162
163
164 // find Widget for event _fp
165 QWidget* findWidget(FootPrint & _fp);
166 // timer callback
167 void timerEvent(QTimerEvent* _e);
168 // clear event buffer (pointers to QEvent)
169 void cleanUpEventBuffer();
170
171
172private:
173
174 // state variables
175 bool record_;
176 bool playback_;
177 bool play_loop_;
178
179 // counter
180 unsigned int eventnr_;
181
182 // timer ID
183 int timer_id_;
184
185 // stop Time
186 QElapsedTimer time_;
187
188 // vector to store events and top-levels sizes
189 FootPrints events_, toplevels_;
190
191 // macro dialog for interaction
192 QtMacroDialog* dialog_;
193
194 // Pointer to MainWidget
195 QWidget* mainWidget_;
196
197 // Main widget pos
198 QPoint mainWidgetDiff_;
199
200 // Old Main widget pos
201 QPoint oldMainWidgetPos_;
202};
203
204//=============================================================================
205} // namespace QtWidgets
206} // namespace ACG
207//=============================================================================
208#endif // MACROAPPLICATION_HH defined
209//=============================================================================
Namespace providing different geometric functions concerning angles.