00001
00002 #include "gui.hpp"
00003
00004 #include <CGAL/Bbox_2.h>
00005 #include <CGAL/IO/Qt_widget.h>
00006 #include <CGAL/IO/Qt_widget_standard_toolbar.h>
00007 #include <qpixmap.h>
00008 #include <qimage.h>
00009
00010 using namespace Arak;
00011
00012 #include "gui.moc"
00013
00014 QApplication* Arak::InitGui(int argc,
00015 char** argv,
00016 int width,
00017 int height,
00018 Coloring& c,
00019 ArakProcess& p,
00020 GridColorEstimator& e,
00021 QMutex& mutex,
00022 bool toolbar,
00023 double refreshRateHz) {
00024 ColoringQTLayer* layer = new ColoringQTLayer(c, p, e, mutex);
00025 QApplication* app = new QApplication(argc, argv);
00026 QMainWindow* win = new QMainWindow();
00027 app->setMainWidget(win);
00028 win->resize(width, height);
00029 win->show();
00030
00031 ColoringQTWidget* w = new ColoringQTWidget(*win, *layer, refreshRateHz);
00032 w->attach(layer);
00033 win->setCentralWidget(w);
00034 CGAL::Bbox_2 bbox = c.boundary().bbox();
00035 w->set_window(bbox.xmin(),
00036 bbox.xmax(),
00037 bbox.ymin(),
00038 bbox.ymax());
00039 w->setFilled(true);
00040 w->resize(width, height);
00041 w->show();
00042
00043 if (toolbar) {
00044 CGAL::Qt_widget_standard_toolbar *stoolbar;
00045 stoolbar =
00046 new CGAL::Qt_widget_standard_toolbar(w, win, "Standard Toolbar");
00047 }
00048
00049 layer->draw();
00050
00051 return app;
00052 }
00053
00054 ColoringQTLayer::ColoringQTLayer(Coloring& c,
00055 ArakProcess& p,
00056 GridColorEstimator& e,
00057 QMutex& mutex)
00058 : c(c), p(p), e(e), mutex(mutex), curType(COLORING) {
00059 }
00060
00061 void ColoringQTLayer::draw() {
00062 mutex.lock();
00063 widget->lock();
00064
00065
00066 *widget << CGAL::BackgroundColor(CGAL::WHITE);
00067
00068 switch (curType) {
00069 case PROC_AND_BD:
00070 p.visualize(*widget);
00071 c.visualize(*widget, true, true, false, false);
00072 break;
00073 case COLORING:
00074 c.visualize(*widget, false, false, true, false);
00075 break;
00076 case PT_COL_EST_AND_BD:
00077 e.visualize(*widget);
00078 c.visualize(*widget, true, true, false, false);
00079 break;
00080 case QUERY_PTS_AND_BD:
00081 c.visualize(*widget, true, true, false, true);
00082 break;
00083 default:
00084 assert(false);
00085 }
00086
00087 widget->unlock();
00088 mutex.unlock();
00089 }
00090
00091 ColoringQTWidget::ColoringQTWidget(QMainWindow& win,
00092 ColoringQTLayer& layer,
00093 double refreshRateHz)
00094 : CGAL::Qt_widget(&win) {
00095 this->layer = &layer;
00096 this->timer = new QTimer(this);
00097 connect(timer, SIGNAL(timeout()), SLOT(timeout()));
00098 timer->start(int(1000.0 / refreshRateHz));
00099 }
00100
00101 void ColoringQTWidget::timeout() {
00102 layer->draw();
00103 }
00104
00105 void ColoringQTWidget::mousePressEvent(QMouseEvent *e) {
00106 Qt_widget::mousePressEvent(e);
00107 if(e->button() == Qt::RightButton) {
00108 if (layer->curType == PROC_AND_BD) {
00109 layer->curType = COLORING;
00110 } else if (layer->curType == COLORING) {
00111 layer->curType = PT_COL_EST_AND_BD;
00112 } else if (layer->curType == PT_COL_EST_AND_BD) {
00113 layer->curType = QUERY_PTS_AND_BD;
00114
00115 } else if (layer->curType == QUERY_PTS_AND_BD) {
00116 layer->curType = PROC_AND_BD;
00117 }
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 }
00195
00196