00001 /* 00002 * Copyright (c) 2006 Thorsten Zachmann <zachmann@kde.org> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef MAINWINDOW_H 00020 #define MAINWINDOW_H 00021 00022 #define KOFFICE_RTREE_DEBUG 00023 00024 #include <QMainWindow> 00025 #include <QtGui> 00026 #include <QLinkedList> 00027 00028 #include "KoRTree.h" 00029 #include "Tool.h" 00030 00031 class QAction; 00032 class QActionGroup; 00033 class QListWidget; 00034 class QMenu; 00035 class QTextEdit; 00036 00037 class Data 00038 { 00039 public: 00040 Data( QRectF rect ) 00041 : m_rect( rect ) 00042 {} 00043 00044 QRectF boundingBox() { return m_rect; } 00045 void paint( QPainter & p ) 00046 { 00047 p.save(); 00048 QPen pen( Qt::black ); 00049 p.setPen( pen ); 00050 p.drawRect( m_rect ); 00051 p.restore(); 00052 } 00053 00054 private: 00055 QRectF m_rect; 00056 }; 00057 00058 00059 class Canvas : public QWidget 00060 { 00061 Q_OBJECT 00062 00063 public: 00064 Canvas(); 00065 virtual ~Canvas() {}; 00066 00067 void updateCanvas(); 00068 void insert( QRectF & rect ); 00069 void select( QRectF & rect ); 00070 void remove( QRectF & rect ); 00071 00072 public slots: 00073 void selectInsertTool(); 00074 void selectSelectTool(); 00075 void selectRemoveTool(); 00076 00077 void replay(); 00078 void debug(); 00079 void replayStep(); 00080 void paintTree( bool paintTree ); 00081 00082 protected: 00083 void mouseMoveEvent(QMouseEvent *e); 00084 void mousePressEvent(QMouseEvent *e); 00085 void mouseReleaseEvent(QMouseEvent *e); 00086 00087 void paintEvent(QPaintEvent * e); 00088 00089 private: 00090 double m_zoom; 00091 QSet<Data*> m_rects; 00092 QList<Data*> m_found; 00093 QRectF m_insertRect; 00094 bool m_buttonPressed; 00095 KoRTree<Data*> m_rtree; 00096 Tool * m_tool; 00097 CreateTool m_createTool; 00098 SelectTool m_selectTool; 00099 RemoveTool m_removeTool; 00100 QFile m_file; 00101 QTextStream m_out; 00102 QStringList m_list; 00103 int m_listId; 00104 bool m_paintTree; 00105 }; 00106 00107 00108 class MainWindow : public QMainWindow 00109 { 00110 Q_OBJECT 00111 00112 public: 00113 MainWindow(); 00114 00115 private slots: 00116 void about(); 00117 00118 private: 00119 void createActions(); 00120 void createMenus(); 00121 void createToolBars(); 00122 void createStatusBar(); 00123 00124 Canvas * m_canvas; 00125 00126 QMenu * m_fileMenu; 00127 QMenu * m_editMenu; 00128 QMenu * m_helpMenu; 00129 00130 QAction * m_aboutAct; 00131 QAction * m_aboutQtAct; 00132 QAction * m_quitAct; 00133 00134 QAction * m_insertAct; 00135 QAction * m_selectAct; 00136 QAction * m_removeAct; 00137 QActionGroup *m_toolAct; 00138 00139 QAction * m_replayAct; 00140 QAction * m_debugAct; 00141 QAction * m_paintTreeAct; 00142 }; 00143 00144 #endif