tychoBCGEN  0.5
 All Data Structures Namespaces Files Functions Variables
mainwindow.cpp
Go to the documentation of this file.
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include "myscene.h"
4 #include "global.h"
5 #include "colormask.h"
6 #include "ui_colormask.h"
7 #include <QFileDialog>
8 #include <QMouseEvent>
9 #include <QResizeEvent>
10 #include <QSize>
11 #include <QColor>
12 #include <QScrollArea>
13 #include <QGraphicsSceneMouseEvent>
14 #include <QTimer>
15 #include <math.h>
16 
17 QPointF point;
18 QPointF point_old;
19 QPointF point_new;
20 
25 
26 bool no_image;
27 
31 
32 int click = 0;
33 
37 MainWindow::MainWindow(QWidget *parent) :
38  QMainWindow(parent),
39  ui(new Ui::MainWindow)
40 {
41  QTimer *timer = new QTimer(this);
42 
43  ui->setupUi(this);
44 
45  counter = 0;
48  red_low = 0;
49  red_up = 0;
50  green_low = 0;
51  green_up = 0;
52  blue_low = 0;
53  blue_up = 0;
54  value = 0;
56  alpha = 90;
57  alpha_emitter = 200;
59 
60  red_checked = true;
61  green_checked = true;
62  blue_checked = true;
63  no_image = true;
64 
66 
67  final_mark_color.setRgb(Qt::black);
68  final_mark_color.setAlpha(alpha);
69 
70  emitter_color_x.setRgb(255,0,0,alpha_emitter);
71  emitter_color_mx.setRgb(0,0,255,alpha_emitter);
72  emitter_color_y.setRgb(0,255,0,alpha_emitter);
73  emitter_color_my.setRgb(100,255,200,alpha_emitter);
74 
75  //to make changes on the colormask-window received by the mainwindow
76  connect(timer, SIGNAL(timeout()), this, SLOT(value_change_int()));
77  timer->start(200);
78 
79  //menus
80  connect(ui->actionQuit_tychoICGEN, SIGNAL(triggered()), this, SLOT(quit()));
81  connect(ui->actionLoad_Image, SIGNAL(triggered()), this, SLOT(openfile()));
82  connect(ui->actionSave_Boundary, SIGNAL(triggered()), this, SLOT(savefile()));
83  connect(ui->actionSave_Sound_Emitter, SIGNAL(triggered()), this, SLOT(savefile_soundemitter()));
84  connect(ui->actionSave_Wind_Emitter, SIGNAL(triggered()), this, SLOT(save_wind_emitter()));
85  connect(ui->actionSave_Masked_Image, SIGNAL(triggered()), this, SLOT(save_masked_image()));
86  connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(open_about()));
87  connect(ui->actionTutorial, SIGNAL(triggered()), this, SLOT(open_tutorial()));
88 
89  //buttons
90  connect(ui->scale_to_width, SIGNAL(clicked()), this, SLOT(scale_to_width()));
91  connect(ui->original, SIGNAL(clicked()), this, SLOT(scale_original()));
92  connect(ui->zoom_in, SIGNAL(clicked()), this, SLOT(zoom_in()));
93  connect(ui->zoom_out, SIGNAL(clicked()), this, SLOT(zoom_out()));
94  connect(ui->ColorMask, SIGNAL(clicked()), this, SLOT(open_color_mask()));
95  connect(ui->invertmask, SIGNAL(clicked()), this, SLOT(invert_mask()));
96  connect(ui->rotate_by_90, SIGNAL(clicked()), this, SLOT(rotate_by_90()));
97 
98  //mask memo, remove and reset
99  connect(ui->reset_mask, SIGNAL(clicked()), this, SLOT(reset_mask()));
100  connect(ui->memo_mask, SIGNAL(clicked()), this, SLOT(memo_color_mask()));
101  connect(ui->remove_mask, SIGNAL(clicked()), this, SLOT(clear_last_color_mask()));
102 
103  //windemitter
104  connect(ui->windemitter, SIGNAL(clicked(bool)), this, SLOT(wind_emitter_on()));
105  connect(ui->windemitter, SIGNAL(toggled(bool)), this, SLOT(wind_emitter_off()));
106  connect(ui->resetwindemitter, SIGNAL(clicked()), this, SLOT(reset_wind_emitter()));
107 
108  //rescaling of the image
109  connect(ui->image_width, SIGNAL(editingFinished()), this, SLOT(scale_image()));
110  connect(ui->image_height, SIGNAL(editingFinished()), this, SLOT(scale_image()));
111 }
112 
114 {
115  delete ui;
116 }
117 
121 void myscene::mouseMoveEvent(QGraphicsSceneMouseEvent *event){
122 
123  int x,y;
124 
125  x = floor(event->scenePos().x());
126  y = floor(event->scenePos().y());
127 
128  point.setX(x);
129  point.setY(y);
130  point_new = point;
131 }
132 
136 void MainWindow::resizeEvent(QResizeEvent *){
137 
138  int width = MainWindow::width()-20;
139  int heigth = MainWindow::height()-200;
140 
141  ui->graphicsView->setGeometry(10,140,width, heigth);
142 
143 }
144 
148 void MainWindow::keyPressEvent(QKeyEvent *event){
149 
150  if (event->key() == Qt::Key_E){
151  zoom_in();
152  }
153 
154  if (event->key() == Qt::Key_W){
155  zoom_out();
156  }
157 
158 
159  if ((event->key() == 16777249)&&(ui->maksmode->isChecked()== true)){
160 
161  pick_red = qRed(image_stack::imagestack.at(0).pixel(point.toPoint()));
162  pick_green = qGreen(image_stack::imagestack.at(0).pixel(point.toPoint()));
163  pick_blue = qBlue(image_stack::imagestack.at(0).pixel(point.toPoint()));
164 
165  make_color_mask();
166 
167  }
168 
169  if ((event->key() == 16777249)&&(ui->clearmode->isChecked() == true)){
170  //clear_pixel();
172  }
173 
174  if ((event->key() == 16777249)&&(ui->clearpixel->isChecked() == true)){
176  }
177 
178  if ((event->key() == 16777249)&&(ui->maskpixel->isChecked() == true)){
180  }
181 
182  if ((event->key() == 16777249)&&(ui->maskislands->isChecked() == true)){
184  }
185 
186  if ((event->key() == 16777249)&&(ui->windemitter->isChecked() == true)){
189  }
190 }
191 
196 
197  if (value != toCheck){
198  toCheck = value;
199  make_color_mask();
200  }
201 }
202 
207 
208  counter = 0;
211 
212  ui->invertmask->setEnabled(false);
213 
214  image_stack::imagestack.clear();
215  image.load(file);
216  image = image.convertToFormat(QImage::Format_ARGB32,Qt::AutoColor);
217  image = image.mirrored(false, true);
219 
222 
223  imagewidth = image.width();
224  imageheight = image.height();
225 
226  ui->image_width->setText(QString::number(imagewidth));
227  ui->image_height->setText(QString::number(imageheight));
228  ui->image_depth->setText("0");
229 
230  pixmap = QPixmap::fromImage(image_stack::imagestack.at(0));
231  pixmapwidth = pixmap.width();
232  pixmapheight = pixmap.height();
233 
234  scene = new myscene();
235  scene->addPixmap(pixmap);
236  ui->reset_mask->setEnabled(true);
237 
238  ui->graphicsView->setScene(scene);
239  ui->graphicsView->setDragMode(ui->graphicsView->ScrollHandDrag);
240  ui->graphicsView->setFocus();
241 
242 }
243 
249 
250  mycolormask = new colormask;
251  mycolormask->show();
252 
253 }
254 
259 
260  myabout = new about;
261  myabout->show();
262 
263 }
264 
269 
270  mytutorial = new tutorial;
271  mytutorial->show();
272 
273 }
274 
275 
280 {
281  qApp->exit();
282 }
283 
288 
289  int x, y;
290 
291  x = ui->image_width->text().toInt();
292  y = ui->image_width->text().toInt();
293 
294  ui->image_width->setText(QString::number(x));
295  ui->image_height->setText(QString::number(y));
296 
298  image = image.scaled(x,y,Qt::KeepAspectRatio,Qt::FastTransformation);
300 
301  wind_emitter = wind_emitter.scaled(x,y,Qt::KeepAspectRatio,Qt::FastTransformation);
303 
304  //pixmap = QPixmap::fromImage(image_stack::imagestack.last());
305  pixmap = QPixmap::fromImage(wind_emitter);
306  pixmapwidth = pixmap.width();
307  pixmapheight = pixmap.height();
308 
309  scene = new myscene();
310  scene->addPixmap(pixmap);
311  ui->reset_mask->setEnabled(true);
312  ui->graphicsView->setScene(scene);
313  ui->graphicsView->setDragMode(ui->graphicsView->ScrollHandDrag);
314  QApplication::setOverrideCursor(Qt::ArrowCursor);
315  ui->graphicsView->setFocus();
316 
317 }
318 
323 
324  ui->graphicsView->rotate(90);
325 
326 
327  }