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