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