00001 /*===========================================================================*\ 00002 * * 00003 * OpenFlipper * 00004 * Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen * 00005 * www.openflipper.org * 00006 * * 00007 *---------------------------------------------------------------------------* 00008 * This file is part of OpenFlipper. * 00009 * * 00010 * OpenFlipper is free software: you can redistribute it and/or modify * 00011 * it under the terms of the GNU Lesser General Public License as * 00012 * published by the Free Software Foundation, either version 3 of * 00013 * the License, or (at your option) any later version with the * 00014 * following exceptions: * 00015 * * 00016 * If other files instantiate templates or use macros * 00017 * or inline functions from this file, or you compile this file and * 00018 * link it with other files to produce an executable, this file does * 00019 * not by itself cause the resulting executable to be covered by the * 00020 * GNU Lesser General Public License. This exception does not however * 00021 * invalidate any other reasons why the executable file might be * 00022 * covered by the GNU Lesser General Public License. * 00023 * * 00024 * OpenFlipper is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU Lesser General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU LesserGeneral Public * 00030 * License along with OpenFlipper. If not, * 00031 * see <http://www.gnu.org/licenses/>. * 00032 * * 00033 \*===========================================================================*/ 00034 00035 /*===========================================================================*\ 00036 * * 00037 * $Revision: 8521 $ * 00038 * $Author: moebius $ * 00039 * $Date: 2010-02-10 15:57:35 +0100 (Mi, 10. Feb 2010) $ * 00040 * * 00041 \*===========================================================================*/ 00042 00043 00044 00045 //============================================================================= 00046 // 00047 // CLASS QtApplication 00048 // 00049 //============================================================================= 00050 00051 #ifndef QTAPPLICATION_HH 00052 #define QTAPPLICATION_HH 00053 00054 00055 //== INCLUDES ================================================================= 00056 00057 00058 // Qt 00059 #include <QApplication> 00060 #include <QObject> 00061 #include <QEvent> 00062 #include <QDateTime> 00063 00064 #include <QTimerEvent> 00065 00066 // stdc++ 00067 #include <vector> 00068 #include <string> 00069 #include <iostream> 00070 00071 #include "../Config/ACGDefines.hh" 00072 00073 00074 //== FORWARD DECLARATIONS ===================================================== 00075 00076 00077 namespace ACG { 00078 namespace QtWidgets { 00079 class QtMacroDialog; 00080 } 00081 } 00082 00083 00084 //== NAMESPACES =============================================================== 00085 00086 00087 namespace ACG { 00088 namespace QtWidgets { 00089 00090 00091 //== CLASS DEFINITION ========================================================= 00092 00093 00094 class ACGDLLEXPORT QtApplication : public QApplication 00095 { 00096 Q_OBJECT 00097 00098 public: 00099 00100 QtApplication(int _argc, char** _argv); 00101 virtual ~QtApplication() { cleanUpEventBuffer(); } 00102 00103 00104 public slots: 00105 00106 // save recorded Events to file 00107 void saveFile(const char* _filename); 00108 00109 // load recorded Events from file 00110 void loadFile(const char* _filename); 00111 00112 // start playback 00113 void play(); 00114 00115 // stop playback or record 00116 void stop(); 00117 00118 // record 00119 void record(); 00120 00121 // change loop status for playback 00122 void loop(bool _b); 00123 00124 00125 public: 00126 00127 // filter events 00128 bool notify (QObject* _receiver, QEvent* _event); 00129 00130 00131 private: 00132 00133 // information for one event 00134 struct FootPrint 00135 { 00136 int time; 00137 std::string name; 00138 std::string classname; 00139 std::string parent; 00140 QPoint cursorPos; 00141 QPoint position; 00142 QSize size; 00143 QEvent *event; 00144 }; 00145 00146 typedef std::vector<FootPrint> FootPrints; 00147 typedef FootPrints::iterator FootPrintIter; 00148 00149 00150 // record and play events 00151 void recordEvent(QObject* _receiver, QEvent* _event); 00152 void playbackEvent(FootPrint & _fp); 00153 00154 00155 // store and restore sizes of all top-level widgets 00156 void storeTopLevelSizes(); 00157 void restoreTopLevelSizes(); 00158 00159 // load and save sizes of top-level widgets 00160 void saveTopLevelSizes(std::ostream & _os); 00161 void loadTopLevelSizes(std::istream & _is); 00162 00163 00164 // find Widget for event _fp 00165 QWidget* findWidget(FootPrint & _fp); 00166 // timer callback 00167 void timerEvent(QTimerEvent* _e); 00168 // clear event buffer (pointers to QEvent) 00169 void cleanUpEventBuffer(); 00170 00171 00172 private: 00173 00174 // state variables 00175 bool record_; 00176 bool playback_; 00177 bool play_loop_; 00178 00179 // counter 00180 unsigned int eventnr_; 00181 00182 // timer ID 00183 int timer_id_; 00184 00185 // stop Time 00186 QTime time_; 00187 00188 // vector to store events and top-levels sizes 00189 FootPrints events_, toplevels_; 00190 00191 // macro dialog for interaction 00192 QtMacroDialog* dialog_; 00193 00194 // Pointer to MainWidget 00195 QWidget* mainWidget_; 00196 00197 // Main widget pos 00198 QPoint mainWidgetDiff_; 00199 00200 // Old Main widget pos 00201 QPoint oldMainWidgetPos_; 00202 }; 00203 00204 //============================================================================= 00205 } // namespace QtWidgets 00206 } // namespace ACG 00207 //============================================================================= 00208 #endif // MACROAPPLICATION_HH defined 00209 //=============================================================================