IntelliPhoto  0.6
IntelliPhotoGui.cpp
Go to the documentation of this file.
1 // ---------- IntelliPhotoGui.cpp ----------
2 
3 #include "IntelliPhotoGui.h"
4 #include "Layer/PaintingArea.h"
5 
6 #include "QEvent"
7 #include "QCloseEvent"
8 
9 // IntelliPhotoGui constructor
11  // create Gui elements and lay them out
12  createGui();
13  // Create actions
14  createActions();
15  // create Menus
16  createMenus();
17  // set style of the gui
18  setIntelliStyle();
19  // Size the app
20  resize(600,600);
21  showMaximized();
22  setDefaultToolValue();
23 }
24 
25 // User tried to close the app
26 void IntelliPhotoGui::closeEvent(QCloseEvent*event){
27  // If they try to close maybeSave() returns true
28  // if no changes have been made and the app closes
29  if (maybeSave()) {
30  event->accept();
31  } else {
32  // If there have been changes ignore the event
33  event->ignore();
34  }
35 }
36 
37 // Check if the current image has been changed and then
38 // open a dialog to open a file
39 void IntelliPhotoGui::slotOpen(){
40  // Check if changes have been made since last save
41  // maybeSave() returns true if no changes have been made
42  if (maybeSave()) {
43 
44  // Get the file to open from a dialog
45  // tr sets the window title to Open File
46  // QDir opens the current dirctory
47  QString fileName = QFileDialog::getOpenFileName(this,
48  tr("Open File"), QDir::currentPath(), nullptr, nullptr, QFileDialog::DontUseNativeDialog);
49 
50  // If we have a file name load the image and place
51  // it in the paintingArea
52  if (!fileName.isEmpty()) {
53  paintingArea->open(fileName);
54  UpdateGui();
55  }
56  }
57 }
58 
59 // Called when the user clicks Save As in the menu
60 void IntelliPhotoGui::slotSave(){
61  // A QAction represents the action of the user clicking
62  QAction*action = qobject_cast<QAction*>(sender());
63 
64  // Stores the array of bytes of the users data
65  QByteArray fileFormat = action->data().toByteArray();
66 
67  // Pass it to be saved
68  saveFile(fileFormat);
69 }
70 
71 // Opens a dialog that allows the user to create a New RASTER Layer
72 void IntelliPhotoGui::slotCreateNewRasterLayer(){
73  // Stores button value
74  bool ok1, ok2;
75 
76  // "New Layer" is the title of the window
77  // the next tr is the text to display
78  // Define the standard Value, min, max, step and ok button
79  int width = IntelliInputDialog::getInt("New Raster Layer", "Width:", 200, 1, paintingArea->getMaxWidth(), 1, &ok1);
80 
81  int height = IntelliInputDialog::getInt("New Raster Layer", "Height:", 200, 1, paintingArea->getMaxHeight(), 1, &ok2);
82 
83  // Create New Layer
84  if (ok1&&ok2) {
85  paintingArea->addLayer(width,height,0,0,IntelliImage::ImageType::RASTERIMAGE);
86  UpdateGui();
87  }
88 }
89 
90 // Opens a dialog that allows the user to create a New SHAPED Layer
91 void IntelliPhotoGui::slotCreateNewShapedLayer(){
92  // Stores button value
93  bool ok1, ok2;
94 
95  // "New Layer" is the title of the window
96  // the next tr is the text to display
97  // Define the standard Value, min, max, step and ok button
98  int width = IntelliInputDialog::getInt("New Shaped Layer", "Width:", 200, 1, paintingArea->getMaxWidth(), 1, &ok1);
99 
100  int height = IntelliInputDialog::getInt("New Shaped Layer", "Height:", 200, 1, paintingArea->getMaxHeight(), 1, &ok2);
101 
102  // Create New Layer
103  if (ok1&&ok2) {
104  paintingArea->addLayer(width, height, 0, 0, IntelliImage::ImageType::SHAPEDIMAGE);
105  UpdateGui();
106  }
107 }
108 
109 // Opens a dialog that allows the user to change Dimension
110 void IntelliPhotoGui::slotChangeDim(){
111  // Stores button value
112  bool ok1, ok2;
113 
114  // "change Dimension" is the title of the window
115  // the next tr is the text to display
116  // Define the standard Value, min, step and ok button
117  int width = IntelliInputDialog::getInt("New Canvas Size", "Width:", 600, 1, 50000, 1, &ok1);
118 
119  int height = IntelliInputDialog::getInt("New Canvas Size", "Height:", 600, 1, 50000, 1, &ok2);
120 
121  // Change dimension
122  if (ok1&&ok2) {
123  paintingArea->setLayerDimensions(width,height);
124  UpdateGui();
125  }
126 }
127 
128 // Opens a dialog that allows the user to delete a Layer
129 void IntelliPhotoGui::slotDeleteLayer(){
130 
131  bool ok1;
132  // "delete Layer" is the title of the window
133  // the next tr is the text to display
134  // Define the standard Value, min, max, step and ok button
135  int layerNumber = IntelliInputDialog::getInt("Delete Layer", "Number:", paintingArea->getNumberOfActiveLayer() + 1, 1, static_cast<int>(paintingArea->layerBundle.size()), 1, &ok1);
136 
137  // Create New Layer
138  if(ok1) {
139  paintingArea->deleteLayer(layerNumber - 1);
140  UpdateGui();
141  }
142 }
143 
144 void IntelliPhotoGui::slotSetActiveAlpha(){
145 
146  bool ok1, ok2;
147  // "Layer to set on" is the title of the window
148  // the next tr is the text to display
149  // Define the standard Value, min, max, step and ok button
150 
151  int layer = IntelliInputDialog::getInt("Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer() + 1, 1, static_cast<int>(paintingArea->layerBundle.size()), 1, &ok1);
152 
153  // "New Alpha" is the title of the window
154  int alpha = IntelliInputDialog::getInt("Layer to set on", "Alpha:", 255, 0, 255, 1, &ok2);
155 
156  if (ok1&&ok2)
157  {
158  paintingArea->setLayerAlpha(layer - 1,alpha);
159  UpdateGui();
160  }
161 }
162 
163 void IntelliPhotoGui::slotSetPolygon(){
164  // Stores button value
165  bool ok1;
166 
167  // "Layer to set on" is the title of the window
168  // the next tr is the text to display
169  // Define the standard Value, min, max, step and ok button
170  int layer = IntelliInputDialog::getInt("Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer() + 1, 1, static_cast<int>(paintingArea->layerBundle.size()), 1, &ok1);
171 
172  if (ok1)
173  {
174  paintingArea->setPolygon(layer - 1);
175  UpdateGui();
176  }
177 }
178 
179 void IntelliPhotoGui::slotPositionMoveUp(){
180  paintingArea->movePositionActive(0,-20);
181  update();
182 }
183 
184 void IntelliPhotoGui::slotPositionMoveDown(){
185  paintingArea->movePositionActive(0,20);
186  update();
187 }
188 
189 void IntelliPhotoGui::slotPositionMoveLeft(){
190  paintingArea->movePositionActive(-20,0);
191  update();
192 }
193 
194 void IntelliPhotoGui::slotPositionMoveRight(){
195  paintingArea->movePositionActive(20,0);
196  update();
197 }
198 
199 void IntelliPhotoGui::slotMoveLayerUp(){
200  paintingArea->moveActiveLayer(1);
201  update();
202 }
203 
204 void IntelliPhotoGui::slotMoveLayerDown(){
205  paintingArea->moveActiveLayer(-1);
206  update();
207 }
208 
209 void IntelliPhotoGui::slotSetActiveLayer(){
210  bool ok1;
211  // "Layer to set on" is the title of the window
212  // the next tr is the text to display
213  // Define the standard Value, min, max, step and ok button
214  int layer = IntelliInputDialog::getInt("Layer to set on", "Layer:", 1, 1, static_cast<int>(paintingArea->layerBundle.size()), 1, &ok1);
215 
216  if(ok1) {
217  paintingArea->setLayerActive(layer - 1);
218  UpdateGui();
219  }
220 }
221 
222 void IntelliPhotoGui::slotUpdateRenderSettingsOn(){
223  paintingArea->setRenderSettings(true);
224  UpdateGui();
225 }
226 
227 void IntelliPhotoGui::slotUpdateRenderSettingsOff(){
228  paintingArea->setRenderSettings(false);
229  UpdateGui();
230 }
231 
232 void IntelliPhotoGui::slotSetFirstColor(){
233  paintingArea->colorPickerSetFirstColor();
234  UpdateGui();
235 }
236 
237 void IntelliPhotoGui::slotSetSecondColor(){
238  paintingArea->colorPickerSetSecondColor();
239  UpdateGui();
240 }
241 
242 void IntelliPhotoGui::slotSwapColor(){
243  paintingArea->colorPickerSwapColors();
244  UpdateGui();
245 }
246 
247 void IntelliPhotoGui::slotCreatePenTool(){
248  PenButton->setChecked(true);
249  paintingArea->createPenTool();
250 }
251 
252 void IntelliPhotoGui::slotCreatePlainTool(){
253  PlainButton->setChecked(true);
254  paintingArea->createPlainTool();
255 }
256 
257 void IntelliPhotoGui::slotCreateLineTool(){
258  LineButton->setChecked(true);
259  paintingArea->createLineTool();
260 }
261 
262 void IntelliPhotoGui::slotCreateRectangleTool(){
263  RectangleButton->setChecked(true);
264  paintingArea->createRectangleTool();
265 }
266 
267 void IntelliPhotoGui::slotCreateCircleTool(){
268  CircleButton->setChecked(true);
269  paintingArea->createCircleTool();
270 }
271 
272 void IntelliPhotoGui::slotCreatePolygonTool(){
273  PolygonButton->setChecked(true);
274  paintingArea->createPolygonTool();
275 }
276 
277 void IntelliPhotoGui::slotCreateFloodFillTool(){
278  FloodFillButton->setChecked(true);
279  paintingArea->createFloodFillTool();
280 }
281 
282 // Open an about dialog
283 void IntelliPhotoGui::slotAboutDialog(){
284  // Window title and text to display
285  QMessageBox::about(this, tr("About Painting"),
286  tr("<p><b>IntelliPhoto - </b>A Pretty basic editor.</p> <br>Developed by Team 7."));
287 }
288 
289 void IntelliPhotoGui::slotEnterPressed(){
290  QString string = EditLineWidth->text();
291  if(string.toInt() > 50) {
292  EditLineWidth->setText("50");
293  }
294  paintingArea->Toolsettings.setLineWidth(string.toInt());
295  string = EditLineInnerAlpha->text();
296  if(string.toInt() > 255) {
297  EditLineInnerAlpha->setText("255");
298  }
299  paintingArea->Toolsettings.setInnerAlpha(string.toInt());
300 }
301 
302 void IntelliPhotoGui::slotResetTools(){
303  CircleButton->setChecked(false);
304  FloodFillButton->setChecked(false);
305  LineButton->setChecked(false);
306  PenButton->setChecked(false);
307  PlainButton->setChecked(false);
308  PolygonButton->setChecked(false);
309  RectangleButton->setChecked(false);
310 }
311 
312 void IntelliPhotoGui::slotSetWidth(){
313  bool ok1;
314  int temp = IntelliInputDialog::getInt("Toolsettings", "Width:", 5, 1, 50, 1, &ok1);
315  if(ok1) {
316  paintingArea->Toolsettings.setLineWidth(temp);
317  EditLineWidth->setText(QString("%1").arg(temp));
318  }
319 }
320 
321 void IntelliPhotoGui::slotSetInnerAlpha(){
322  bool ok1;
323  int temp = IntelliInputDialog::getInt("Toolsettings", "Alpha:", 5, 1, 50, 1, &ok1);
324  if(ok1) {
325  paintingArea->Toolsettings.setInnerAlpha(temp);
326  EditLineInnerAlpha->setText(QString("%1").arg(temp));
327  }
328 }
329 
330 // Define menu actions that call functions
331 void IntelliPhotoGui::createActions(){
332  // Get a list of the supported file formats
333  // QImageWriter is used to write images to files
334  foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
335  QString text = tr("%1...").arg(QString(format).toUpper());
336 
337  // Create an action for each file format
338  QAction*action = new QAction(text, this);
339 
340  // Set an action for each file format
341  action->setData(format);
342 
343  // When clicked call IntelliPhotoGui::save()
344  connect(action, SIGNAL(triggered()), this, SLOT(slotSave()));
345 
346  // Attach each file format option menu item to Save As
347  actionSaveAs.append(action);
348  }
349 
350  //set exporter to actions
351  QAction*pngSaveAction = new QAction("PNG-8", this);
352  pngSaveAction->setData("PNG");
353  // When clicked call IntelliPhotoGui::save()
354  connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(slotSave()));
355  // Attach each PNG in save Menu
356  actionSaveAs.append(pngSaveAction);
357  pngSaveAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
358 
359  // Create exit action and tie to IntelliPhotoGui::close()
360  actionExit = new QAction(tr("&Exit"), this);
361  actionExit->setShortcuts(QKeySequence::Quit);
362  connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
363 
364  actionOpen = new QAction(tr("&Open"), this);
365  actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
366  connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen()));
367 
368  // Create New RASTER Layer action and tie to IntelliPhotoGui::newLayer()
369  actionCreateNewRasterLayer = new QAction(tr("&Raster Image"), this);
370  actionCreateNewRasterLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
371  connect(actionCreateNewRasterLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewRasterLayer()));
372 
373 
374  // Create New SHAPED Layer action and tie to IntelliPhotoGui::newLayer()
375  actionCreateNewShapedLayer = new QAction(tr("&Shaped Image"), this);
376  actionCreateNewShapedLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N + Qt::ALT));
377  connect(actionCreateNewShapedLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewShapedLayer()));
378 
379  // Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
380  actionDeleteLayer = new QAction(tr("&Delete Layer..."), this);
381  actionDeleteLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_D));
382  connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer()));
383 
384  actionChangeDim = new QAction(tr("&Change Dimension"), this);
385  actionChangeDim->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_X));
386  connect(actionChangeDim, SIGNAL(triggered()), this, SLOT(slotChangeDim()));
387  connect(dimCanvas, SIGNAL(clicked()), this, SLOT(slotChangeDim()));
388 
389  actionSetActiveLayer = new QAction(tr("&set Active"), this);
390  actionSetActiveLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A));
391  connect(actionSetActiveLayer, SIGNAL(triggered()), this, SLOT(slotSetActiveLayer()));
392 
393  actionSetActiveAlpha = new QAction(tr("&set Alpha"), this);
394  actionSetActiveAlpha->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_A));
395  connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha()));
396 
397  actionSetPolygon = new QAction(tr("&set new Polygondata"), this);
398  actionSetPolygon->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_P));
399  connect(actionSetPolygon, SIGNAL(triggered()), this, SLOT(slotSetPolygon()));
400 
401  actionMovePositionUp = new QAction(tr("&move Up"), this);
402  actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
403  connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp()));
404 
405  actionMovePositionDown = new QAction(tr("&move Down"), this);
406  actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
407  connect(actionMovePositionDown, SIGNAL(triggered()), this, SLOT(slotPositionMoveDown()));
408 
409  actionMovePositionLeft = new QAction(tr("&move Left"), this);
410  actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
411  connect(actionMovePositionLeft, SIGNAL(triggered()), this, SLOT(slotPositionMoveLeft()));
412 
413  actionMovePositionRight = new QAction(tr("&move Right"), this);
414  actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
415  connect(actionMovePositionRight, SIGNAL(triggered()), this, SLOT(slotPositionMoveRight()));
416 
417  actionMoveLayerUp = new QAction(tr("&move Layer Up"), this);
418  actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
419  connect(actionMoveLayerUp, SIGNAL(triggered()), this, SLOT(slotMoveLayerUp()));
420 
421  actionMoveLayerDown = new QAction(tr("&move Layer Down"), this);
422  actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
423  connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown()));
424 
425  //Create Update RenderSettings Actions here
426  actionUpdateRenderSettingsOn = new QAction(tr("&On"), this);
427  actionUpdateRenderSettingsOn->setShortcut(QKeySequence(Qt::ALT + Qt::SHIFT + +Qt::Key_A));
428  connect(actionUpdateRenderSettingsOn, SIGNAL(triggered()),this, SLOT(slotUpdateRenderSettingsOn()));
429 
430  actionUpdateRenderSettingsOff = new QAction(tr("&Off"), this);
431  actionUpdateRenderSettingsOff->setShortcut(QKeySequence(Qt::ALT + Qt::SHIFT + +Qt::Key_D));
432  connect(actionUpdateRenderSettingsOff, SIGNAL(triggered()),this, SLOT(slotUpdateRenderSettingsOff()));
433 
434  //Create Color Actions here
435  actionColorPickerFirstColor = new QAction(tr("&Main"), this);
436  actionColorPickerFirstColor->setShortcut(QKeySequence(Qt::ALT + Qt::Key_N));
437  connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor()));
438  connect(FirstColorButton, SIGNAL(clicked()), this, SLOT(slotSetFirstColor()));
439 
440  actionColorPickerSecondColor = new QAction(tr("&Secondary"), this);
441  actionColorPickerSecondColor->setShortcut(QKeySequence(Qt::ALT + Qt::Key_M));
442  connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetSecondColor()));
443  connect(SecondColorButton, SIGNAL(clicked()), this, SLOT(slotSetSecondColor()));
444 
445  actionColorSwap = new QAction(tr("&Switch"), this);
446  actionColorSwap->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_S));
447  connect(actionColorSwap, SIGNAL(triggered()), this, SLOT(slotSwapColor()));
448  connect(SwitchColorButton, SIGNAL(clicked()), this, SLOT(slotSwapColor()));
449 
450  //Create Tool actions down here
451  actionCreatePlainTool = new QAction(tr("&Plain"), this);
452  actionCreatePlainTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT + Qt::Key_P));
453  connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
454  connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotCreatePlainTool()));
455 
456 
457  actionCreatePenTool = new QAction(tr("&Pen"),this);
458  actionCreatePenTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT + Qt::Key_S));
459  connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
460  connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool()));
461 
462  actionCreateLineTool = new QAction(tr("&Line"), this);
463  actionCreateLineTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT + Qt::Key_L));
464  connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
465  connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool()));
466 
467  actionCreateCircleTool = new QAction(tr("&Circle"), this);
468  actionCreateCircleTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT + Qt::Key_C));
469  connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
470  connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotCreateCircleTool()));
471 
472  actionCreateRectangleTool = new QAction(tr("&Rectangle"), this);
473  actionCreateRectangleTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT + Qt::Key_R));
474  connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
475  connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotCreateRectangleTool()));
476 
477  actionCreatePolygonTool = new QAction(tr("&Polygon"), this);
478  actionCreatePolygonTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT + Qt::Key_V));
479  connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
480  connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotCreatePolygonTool()));
481 
482  actionCreateFloodFillTool = new QAction(tr("&FloodFill"), this);
483  actionCreateFloodFillTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT + Qt::Key_F));
484  connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
485  connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool()));
486 
487  // Create about action and tie to IntelliPhotoGui::about()
488  actionAboutDialog = new QAction(tr("&About"), this);
489  actionAboutDialog->setShortcut(Qt::Key_F2);
490  connect(actionAboutDialog, SIGNAL(triggered()), this, SLOT(slotAboutDialog()));
491 
492  // Create about Qt action and tie to IntelliPhotoGui::aboutQt()
493  actionAboutQtDialog = new QAction(tr("About &Qt"), this);
494  actionAboutQtDialog->setShortcut(Qt::Key_F3);
495  connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
496 
497  connect(EditLineWidth, SIGNAL(returnPressed()), this, SLOT(slotEnterPressed()));
498  connect(EditLineInnerAlpha, SIGNAL(returnPressed()), this, SLOT(slotEnterPressed()));
499 
500  connect(CircleButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
501  connect(CircleButton, SIGNAL(clicked()), this, SLOT(slotCreateCircleTool()));
502 
503  connect(FloodFillButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
504  connect(FloodFillButton, SIGNAL(clicked()), this, SLOT(slotCreateFloodFillTool()));
505 
506  connect(LineButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
507  connect(LineButton, SIGNAL(clicked()), this, SLOT(slotCreateLineTool()));
508 
509  connect(PenButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
510  connect(PenButton, SIGNAL(clicked()), this, SLOT(slotCreatePenTool()));
511 
512  connect(PlainButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
513  connect(PlainButton, SIGNAL(clicked()), this, SLOT(slotCreatePlainTool()));
514 
515  connect(PolygonButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
516  connect(PolygonButton, SIGNAL(clicked()), this, SLOT(slotCreatePolygonTool()));
517 
518  connect(RectangleButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
519  connect(RectangleButton, SIGNAL(clicked()), this, SLOT(slotCreateRectangleTool()));
520 
521  actionSetWidth = new QAction(tr("&Set Width"),this);
522  actionSetWidth->setShortcut(QKeySequence(Qt::ALT + Qt::Key_W));
523  connect(actionSetWidth, SIGNAL(triggered()), this, SLOT(slotSetWidth()));
524 
525  actionSetInnerAlpha = new QAction(tr("&Set Inner Alpha"),this);
526  actionSetInnerAlpha->setShortcut(QKeySequence(Qt::ALT + Qt::Key_A));
527  connect(actionSetInnerAlpha, SIGNAL(triggered()), this, SLOT(slotSetInnerAlpha()));
528 }
529 
530 // Create the menubar
531 void IntelliPhotoGui::createMenus(){
532  // Create Save As option and the list of file types
533  saveAsMenu = new QMenu(tr("&Save As"), this);
534  foreach (QAction * action, actionSaveAs)
535  saveAsMenu->addAction(action);
536 
537  // Attach all actions to File
538  fileMenu = new QMenu(tr("&File"), this);
539  fileMenu->addAction(actionOpen);
540  fileMenu->addMenu(saveAsMenu);
541  fileMenu->addSeparator();
542  fileMenu->addAction(actionExit);
543 
544  //Attach all actions to Render Settings
545  renderMenu = new QMenu(tr("&Fast Renderer"), this);
546  renderMenu->addAction(actionUpdateRenderSettingsOn);
547  renderMenu->addAction(actionUpdateRenderSettingsOff);
548 
549  //Attach all Layer Creations to Menu
550  layerCreationMenu = new QMenu(tr("&Create new Layer"), this);
551  layerCreationMenu->addAction(actionCreateNewRasterLayer);
552  layerCreationMenu->addAction(actionCreateNewShapedLayer);
553  // Attach all actions to Layer
554  layerMenu = new QMenu(tr("&Layer"), this);
555  layerMenu->addMenu(layerCreationMenu);
556  layerMenu->addSeparator();
557  layerMenu->addAction(actionSetActiveAlpha);
558  layerMenu->addAction(actionSetActiveLayer);
559  layerMenu->addAction(actionSetPolygon);
560  layerMenu->addSeparator();
561  layerMenu->addAction(actionMovePositionUp);
562  layerMenu->addAction(actionMovePositionDown);
563  layerMenu->addAction(actionMovePositionLeft);
564  layerMenu->addAction(actionMovePositionRight);
565  layerMenu->addAction(actionMoveLayerUp);
566  layerMenu->addAction(actionMoveLayerDown);
567  layerMenu->addSeparator();
568  layerMenu->addAction(actionDeleteLayer);
569 
570  //Attach all Color Options
571  colorMenu = new QMenu(tr("&Color"), this);
572  colorMenu->addAction(actionColorPickerFirstColor);
573  colorMenu->addAction(actionColorPickerSecondColor);
574  colorMenu->addAction(actionColorSwap);
575 
576  //Attach all Tool Creation Actions
577  toolCreationMenu = new QMenu(tr("&Drawingtools"), this);
578  toolCreationMenu->addAction(actionCreateCircleTool);
579  toolCreationMenu->addAction(actionCreateFloodFillTool);
580  toolCreationMenu->addAction(actionCreateLineTool);
581  toolCreationMenu->addAction(actionCreatePenTool);
582  toolCreationMenu->addAction(actionCreatePlainTool);
583  toolCreationMenu->addAction(actionCreatePolygonTool);
584  toolCreationMenu->addAction(actionCreateRectangleTool);
585 
586  //Attach all Tool Setting Actions
587  toolSettingsMenu = new QMenu(tr("&Toolsettings"), this);
588  toolSettingsMenu->addAction(actionSetWidth);
589  toolSettingsMenu->addAction(actionSetInnerAlpha);
590 
591  //Attach all Tool Options
592  toolMenu = new QMenu(tr("&Tools"), this);
593  toolMenu->addMenu(toolCreationMenu);
594  toolMenu->addMenu(toolSettingsMenu);
595  toolMenu->addSeparator();
596  toolMenu->addMenu(colorMenu);
597 
598  // Attach all actions to Options
599  optionMenu = new QMenu(tr("&Options"), this);
600  optionMenu->addMenu(layerMenu);
601  optionMenu->addMenu(toolMenu);
602  optionMenu->addSeparator();
603  optionMenu->addMenu(renderMenu);
604  optionMenu->addAction(actionChangeDim);
605 
606  // Attach all actions to Help
607  helpMenu = new QMenu(tr("&Help"), this);
608  helpMenu->addAction(actionAboutDialog);
609  helpMenu->addAction(actionAboutQtDialog);
610 
611  // Add menu items to the menubar
612  menuBar()->addMenu(fileMenu);
613  menuBar()->addMenu(optionMenu);
614  menuBar()->addMenu(helpMenu);
615 }
616 
617 void IntelliPhotoGui::createGui(){
618  // create a central widget to work on
619  centralGuiWidget = new QWidget(this);
620  setCentralWidget(centralGuiWidget);
621 
622  // create the grid for the layout
623  mainLayout = new QGridLayout(centralGuiWidget);
624  centralGuiWidget->setLayout(mainLayout);
625 
626  // create Gui elements
627  // get and set max width and height
628  paintingArea = new PaintingArea(1280, 720);
629  paintingArea->DummyGui = this;
630 
631  preview = QPixmap(":/Icons/Buttons/icons/circle-tool.svg");
632  CircleButton = new QPushButton();
633  CircleButton->setFixedSize(Buttonsize);
634  CircleButton->setIcon(preview);
635  CircleButton->setIconSize(Buttonsize);
636  CircleButton->setCheckable(true);
637 
638  preview = QPixmap(":/Icons/Buttons/icons/flood-fill-tool.svg");
639  FloodFillButton = new QPushButton();
640  FloodFillButton->setFixedSize(Buttonsize);
641  FloodFillButton->setIcon(preview);
642  FloodFillButton->setIconSize(Buttonsize);
643  FloodFillButton->setCheckable(true);
644 
645  preview = QPixmap(":/Icons/Buttons/icons/line-tool.svg");
646  LineButton = new QPushButton();
647  LineButton->setFixedSize(Buttonsize);
648  LineButton->setIcon(preview);
649  LineButton->setIconSize(Buttonsize);
650  LineButton->setCheckable(true);
651 
652  preview = QPixmap(":/Icons/Buttons/icons/pen-tool.svg");
653  PenButton = new QPushButton();
654  PenButton->setFixedSize(Buttonsize);
655  PenButton->setIcon(preview);
656  PenButton->setIconSize(Buttonsize);
657  PenButton->setCheckable(true);
658 
659  preview = QPixmap(":/Icons/Buttons/icons/plain-tool.svg");
660  PlainButton = new QPushButton();
661  PlainButton->setFixedSize(Buttonsize);
662  PlainButton->setIcon(preview);
663  PlainButton->setIconSize(Buttonsize);
664  PlainButton->setCheckable(true);
665 
666  preview = QPixmap(":/Icons/Buttons/icons/polygon-tool.svg");
667  PolygonButton = new QPushButton();
668  PolygonButton->setFixedSize(Buttonsize);
669  PolygonButton->setIcon(preview);
670  PolygonButton->setIconSize(Buttonsize);
671  PolygonButton->setCheckable(true);
672 
673  preview = QPixmap(":/Icons/Buttons/icons/rectangle-tool.svg");
674  RectangleButton = new QPushButton();
675  RectangleButton->setFixedSize(Buttonsize);
676  RectangleButton->setIcon(preview);
677  RectangleButton->setIconSize(Buttonsize);
678  RectangleButton->setCheckable(true);
679 
680  WidthLine = new QLabel();
681  WidthLine->setText("Width");
682  WidthLine->setFixedSize(Buttonsize.width() * 2,(Buttonsize.height() * 2) / 3);
683 
684  EditLineWidth = new QLineEdit();
685  EditLineWidth->setFixedSize(Buttonsize.width() * 2,(Buttonsize.height() * 2) / 3);
686  EditLineWidth->setText("5");
687  ValidatorLineWidth = new QIntValidator();
688  ValidatorLineWidth->setTop(99);
689  ValidatorLineWidth->setBottom(1);
690  EditLineWidth->setValidator(ValidatorLineWidth);
691 
692  innerAlphaLine = new QLabel();
693  innerAlphaLine->setText("Inner Alpha");
694  innerAlphaLine->setFixedSize(Buttonsize.width() * 2,(Buttonsize.height() * 2) / 3);
695 
696  EditLineInnerAlpha = new QLineEdit();
697  EditLineInnerAlpha->setFixedSize(Buttonsize.width() * 2,(Buttonsize.height() * 2) / 3);
698  EditLineInnerAlpha->setText("255");
699  ValidatorInnerAlpha = new QIntValidator();
700  ValidatorInnerAlpha->setTop(999);
701  ValidatorInnerAlpha->setBottom(0);
702  EditLineInnerAlpha->setValidator(ValidatorInnerAlpha);
703 
704  FirstColorButton = new QPushButton();
705  FirstColorButton->setFixedSize(Buttonsize);
706 
707  SecondColorButton = new QPushButton();
708  SecondColorButton->setFixedSize(Buttonsize);
709 
710  preview = QPixmap(":/Icons/Buttons/icons/Wechselpfeile.png");
711  SwitchColorButton = new QPushButton();
712  SwitchColorButton->setFixedSize(Buttonsize.width() * 2,Buttonsize.height());
713  SwitchColorButton->setIcon(preview);
714  SwitchColorButton->setIconSize(QSize(Buttonsize.width() * 2,Buttonsize.height()));
715 
716  ActiveLayerLine = new QLabel();
717  QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer() + 1);
718  ActiveLayerLine->setText(string);
719  ActiveLayerLine->setFixedSize(Buttonsize.width() * 2 + 10,(Buttonsize.height() * 2) / 3);
720 
721  IntelliImage* activePicture = paintingArea->getImageOfActiveLayer();
722  if(activePicture) {
723  preview = preview.fromImage(activePicture->getImageData());
724  }else{
725  QImage tmp(1,1,QImage::Format_ARGB32);
726  tmp.fill(Qt::transparent);
727  preview = preview.fromImage(tmp);
728  }
729 
730  ActiveLayerImageLabel = new QLabel();
731  ActiveLayerImageLabel->setFixedSize(Buttonsize * 2);
732  ActiveLayerImageLabel->setPixmap(preview.scaled(Buttonsize * 2));
733 
734  dimActive = new QPushButton();
735  dimActive->setFixedSize(Buttonsize.width() * 2,Buttonsize.height() / 2);
736  dimActive->setText("0x0");
737 
738  dimCanvas = new QPushButton();
739  dimCanvas->setFixedSize(Buttonsize.width() * 2,Buttonsize.height() / 2);
740  QString String = QString("%1x%2").arg(paintingArea->Canvas->width()).arg(paintingArea->Canvas->height());
741  dimCanvas->setText(String);
742 
743  // set gui elements
744  mainLayout->addWidget(paintingArea,1,1,20,1);
745  mainLayout->addWidget(CircleButton,1,2,1,1);
746  mainLayout->addWidget(FloodFillButton,1,3,1,1);
747  mainLayout->addWidget(LineButton,2,2,1,1);
748  mainLayout->addWidget(PenButton,2,3,1,1);
749  mainLayout->addWidget(PlainButton,3,2,1,1);
750  mainLayout->addWidget(PolygonButton,3,3,1,1);
751  mainLayout->addWidget(RectangleButton,4,2,1,1);
752  mainLayout->addWidget(WidthLine,5,2,1,2);
753  mainLayout->addWidget(EditLineWidth,6,2,1,2);
754  mainLayout->addWidget(innerAlphaLine,7,2,1,2);
755  mainLayout->addWidget(EditLineInnerAlpha,8,2,1,2);
756  mainLayout->addWidget(FirstColorButton,9,2,1,1);
757  mainLayout->addWidget(SecondColorButton,9,3,1,1);
758  mainLayout->addWidget(SwitchColorButton,10,2,1,2);
759  mainLayout->addWidget(ActiveLayerLine,11,2,1,2);
760  mainLayout->addWidget(ActiveLayerImageLabel,12,2,1,2);
761  mainLayout->addWidget(dimActive,13,2,1,2);
762  mainLayout->addWidget(dimCanvas,14,2,1,2);
763  mainLayout->setHorizontalSpacing(0);
764 }
765 
766 void IntelliPhotoGui::setIntelliStyle(){
767  // Set the title
768  setWindowTitle("IntelliPhoto Prototype");
769  // Set style sheet
770  this->setStyleSheet("color: white;" "background-color: rgb(64, 64, 64);" "selection-color: rgb(200, 10, 10);" "selection-background-color: rgb(64, 64, 64);");
771 
772  QString string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name());
773  FirstColorButton->setStyleSheet(string);
774  string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name());
775  SecondColorButton->setStyleSheet(string);
776 }
777 
778 bool IntelliPhotoGui::maybeSave(){
779  // Check for changes since last save
780 #ifdef QT_NO_DEBUG
781  QMessageBox::StandardButton ret;
782 
783  // Painting is the title of the window
784  // Add text and the buttons
785  ret = QMessageBox::warning(this, tr("Painting"),
786  tr("The image has been modified.\n"
787  "Do you want to save your changes?"),
788  QMessageBox::Save | QMessageBox::Discard
789  | QMessageBox::Cancel);
790 
791  // If save button clicked call for file to be saved
792  if (ret == QMessageBox::Save) {
793  return saveFile("png");
794 
795  // If cancel do nothing
796  } else if (ret == QMessageBox::Cancel) {
797  return false;
798  }
799 #endif
800  return true;
801 }
802 
803 bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){
804  // Define path, name and default file type
805  QString initialPath = QDir::currentPath() + "/untitled." + fileFormat;
806 
807  // Get selected file from dialog
808  // Add the proper file formats and extensions
809  QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
810  initialPath,
811  tr("%1 Files (*.%2);;All Files (*)")
812  .arg(QString::fromLatin1(fileFormat.toUpper()))
813  .arg(QString::fromLatin1(fileFormat)), nullptr, QFileDialog::DontUseNativeDialog);
814 
815  // If no file do nothing
816  if (fileName.isEmpty()) {
817  return false;
818  } else {
819  // Call for the file to be saved
820  return paintingArea->save(fileName, fileFormat.constData());
821  }
822 }
823 
824 void IntelliPhotoGui::setDefaultToolValue(){
825  slotEnterPressed();
826 }
827 
829  if(value < 1) {
830  value = 1;
831  }else if(value > 50) {
832  value = 50;
833  }
834  EditLineWidth->setText(QString("%1").arg(value));
835 }
836 
838  QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer() + 1);
839  ActiveLayerLine->setText(string);
840 
841  IntelliImage* activePicture = paintingArea->getImageOfActiveLayer();
842  if(activePicture) {
843  preview = preview.fromImage(activePicture->getImageData());
844  }else{
845  QImage tmp(1,1,QImage::Format_ARGB32);
846  tmp.fill(Qt::transparent);
847  preview = preview.fromImage(tmp);
848  }
849  ActiveLayerImageLabel->setPixmap(preview.scaled(Buttonsize * 2));
850 
851  string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name());
852  FirstColorButton->setStyleSheet(string);
853  string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name());
854  SecondColorButton->setStyleSheet(string);
855 
856  string = QString("%1x%2").arg(paintingArea->Canvas->width()).arg(paintingArea->Canvas->height());
857  dimCanvas->setText(string);
858 
859  if(paintingArea->layerBundle.size() != 0) {
860  string = QString("%1x%2").arg(paintingArea->layerBundle[static_cast<size_t>
861  (paintingArea->getNumberOfActiveLayer())].width).arg(paintingArea->layerBundle[static_cast<size_t>
862  (paintingArea->getNumberOfActiveLayer())].height);
863  dimActive->setText(string);
864  }
865  else{
866  dimActive->setText("0x0");
867  }
868 }
PaintingArea::createCircleTool
void createCircleTool()
Definition: PaintingArea.cpp:221
IntelliColorPicker::getFirstColor
QColor getFirstColor() const
A function to read the primary selected color.
Definition: IntelliColorPicker.cpp:15
PaintingArea::setRenderSettings
void setRenderSettings(bool isFastRenderingOn)
setRenderSettings updates all Images to the new Rendersetting.
Definition: PaintingArea.cpp:34
PaintingArea::getImageOfActiveLayer
IntelliImage * getImageOfActiveLayer()
Definition: PaintingArea.cpp:416
PaintingArea::createRectangleTool
void createRectangleTool()
Definition: PaintingArea.cpp:216
PaintingArea::getMaxWidth
int getMaxWidth()
Definition: PaintingArea.cpp:243
PaintingArea::save
bool save(const QString &filePath, const char *fileFormat)
The save method is used for exporting the current project as one picture.
Definition: PaintingArea.cpp:141
PaintingArea::setLayerAlpha
void setLayerAlpha(int idx, int alpha)
The setAlphaOfLayer method sets the alpha value of a specific layer.
Definition: PaintingArea.cpp:110
PaintingArea::setLayerActive
void setLayerActive(int idx)
The setLayerToActive method marks a specific layer as active.
Definition: PaintingArea.cpp:103
PaintingArea::getMaxHeight
int getMaxHeight()
Definition: PaintingArea.cpp:247
PaintingArea::deleteLayer
void deleteLayer(int idx, bool isTool=false)
The deleteLayer method removes a layer at a given idx.
Definition: PaintingArea.cpp:81
PaintingArea::createPlainTool
void createPlainTool()
Definition: PaintingArea.cpp:206
IntelliPhotoGui::IntelliPhotoGui
IntelliPhotoGui()
The IntelliPhotoGui method is the constructor and is used to create a new instance of the main progra...
Definition: IntelliPhotoGui.cpp:10
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:53
PaintingArea::createPenTool
void createPenTool()
Definition: PaintingArea.cpp:201
IntelliColorPicker::getSecondColor
QColor getSecondColor() const
A function to read the secondary selected color.
Definition: IntelliColorPicker.cpp:19
PaintingArea::createLineTool
void createLineTool()
Definition: PaintingArea.cpp:211
PaintingArea::colorPickerSetSecondColor
void colorPickerSetSecondColor()
The colorPickerSetSecondColor calls the QTColorPicker to determine the secondary drawing color.
Definition: PaintingArea.cpp:192
PaintingArea::colorPickerSetFirstColor
void colorPickerSetFirstColor()
The colorPickerSetFirstColor calls the QTColorPicker to determine the primary drawing color.
Definition: PaintingArea.cpp:187
IntelliInputDialog::getInt
static int getInt(QString Title=nullptr, QString Label=nullptr, int value=5, int minValue=-2147483647, int maxValue=2147483647, int step=1, bool *ok=nullptr)
Definition: IntelliInputDialog.cpp:16
IntelliPhotoGui.h
PaintingArea::getNumberOfActiveLayer
int getNumberOfActiveLayer()
Definition: PaintingArea.cpp:412
IntelliImage::ImageType::SHAPEDIMAGE
@ SHAPEDIMAGE
IntelliPhotoGui::closeEvent
void closeEvent(QCloseEvent *event) override
The closeEvent function handles closing events.
Definition: IntelliPhotoGui.cpp:26
IntelliImage::getImageData
virtual QImage getImageData()
getImageData returns the data of the current image (Note: It will allways return a ARGB32bit QImage!...
Definition: IntelliImage.cpp:134
IntelliPhotoGui::setToolWidth
void setToolWidth(int value)
Definition: IntelliPhotoGui.cpp:828
PaintingArea::open
bool open(const QString &filePath)
The open method is used for loading a picture into the current layer.
Definition: PaintingArea.cpp:129
PaintingArea::createPolygonTool
void createPolygonTool()
Definition: PaintingArea.cpp:225
PaintingArea::moveActiveLayer
void moveActiveLayer(int idx)
The moveActiveLayer moves the active layer to a specific position in the layer stack.
Definition: PaintingArea.cpp:170
PaintingArea::colorPicker
IntelliColorPicker colorPicker
Definition: PaintingArea.h:202
PaintingArea.h
PaintingArea::createFloodFillTool
void createFloodFillTool()
Definition: PaintingArea.cpp:230
IntelliToolsettings::setInnerAlpha
void setInnerAlpha(int innerAlpha)
Definition: IntelliToolsettings.cpp:32
IntelliPhotoGui::UpdateGui
void UpdateGui()
Definition: IntelliPhotoGui.cpp:837
IntelliImage::ImageType::RASTERIMAGE
@ RASTERIMAGE
PaintingArea::Toolsettings
IntelliToolsettings Toolsettings
Definition: PaintingArea.h:201
PaintingArea::setPolygon
void setPolygon(int idx)
setPolygon is used for setting polygondata, it only works on RASTER images
Definition: PaintingArea.cpp:117
IntelliToolsettings::setLineWidth
void setLineWidth(int LineWidth)
Definition: IntelliToolsettings.cpp:18
PaintingArea::colorPickerSwapColors
void colorPickerSwapColors()
The colorPickerSwitchColor swaps the primary color with the secondary drawing color.
Definition: PaintingArea.cpp:197
PaintingArea::movePositionActive
void movePositionActive(int x, int y)
The movePositionActive method moves the active layer to certain position.
Definition: PaintingArea.cpp:164
IntelliImage
An abstract class which manages the basic IntelliImage operations.
Definition: IntelliImage.h:22
PaintingArea::addLayer
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type=IntelliImage::ImageType::RASTERIMAGE)
The addLayer adds a layer to the current project/ painting area.
Definition: PaintingArea.cpp:62