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