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  }
52 }
53 
54 // Called when the user clicks Save As in the menu
55 void IntelliPhotoGui::slotSave(){
56  // A QAction represents the action of the user clicking
57  QAction*action = qobject_cast<QAction*>(sender());
58 
59  // Stores the array of bytes of the users data
60  QByteArray fileFormat = action->data().toByteArray();
61 
62  // Pass it to be saved
63  saveFile(fileFormat);
64 }
65 
66 // Opens a dialog that allows the user to create a New Layer
67 void IntelliPhotoGui::slotCreateNewLayer(){
68  // Stores button value
69  bool ok1, ok2;
70 
71  // "New Layer" is the title of the window
72  // the next tr is the text to display
73  // Define the standard Value, min, max, step and ok button
74  int width = QInputDialog::getInt(this, tr("New Layer"),
75  tr("Width:"),
76  200,1, 500, 1, &ok1);
77  int height = QInputDialog::getInt(this, tr("New Layer"),
78  tr("Height:"),
79  200,1, 500, 1, &ok2);
80  // Create New Layer
81  if (ok1&&ok2)
82  {
83  int layer = paintingArea->addLayer(width,height,0,0);
84  UpdateGui();
85  }
86 }
87 
88 // Opens a dialog that allows the user to delete a Layer
89 void IntelliPhotoGui::slotDeleteLayer(){
90  // Stores button value
91  bool ok;
92 
93  // "delete Layer" is the title of the window
94  // the next tr is the text to display
95  // Define the standard Value, min, max, step and ok button
96  int layerNumber = QInputDialog::getInt(this, tr("delete Layer"),
97  tr("Number:"),
98  paintingArea->getNumberOfActiveLayer(),0, 500, 1, &ok);
99  // Create New Layer
100  if (ok) {
101  paintingArea->deleteLayer(layerNumber);
102  UpdateGui();
103  }
104 }
105 
106 void IntelliPhotoGui::slotSetActiveAlpha(){
107  // Stores button value
108  bool ok1, ok2;
109 
110  // "Layer to set on" 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 layer = QInputDialog::getInt(this, tr("Layer to set on"),
114  tr("Layer:"),
115  -1,-1,100,1, &ok1);
116  // "New Alpha" is the title of the window
117  int alpha = QInputDialog::getInt(this, tr("New Alpha"),
118  tr("Alpha:"),
119  255,0, 255, 1, &ok2);
120  if (ok1&&ok2)
121  {
122  paintingArea->setLayerAlpha(layer,alpha);
123  UpdateGui();
124  }
125 }
126 
127 void IntelliPhotoGui::slotPositionMoveUp(){
128  paintingArea->movePositionActive(0,-20);
129  update();
130 }
131 
132 void IntelliPhotoGui::slotPositionMoveDown(){
133  paintingArea->movePositionActive(0,20);
134  update();
135 }
136 
137 void IntelliPhotoGui::slotPositionMoveLeft(){
138  paintingArea->movePositionActive(-20,0);
139  update();
140 }
141 
142 void IntelliPhotoGui::slotPositionMoveRight(){
143  paintingArea->movePositionActive(20,0);
144  update();
145 }
146 
147 void IntelliPhotoGui::slotMoveLayerUp(){
148  paintingArea->moveActiveLayer(1);
149  update();
150 }
151 
152 void IntelliPhotoGui::slotMoveLayerDown(){
153  paintingArea->moveActiveLayer(-1);
154  update();
155 }
156 
157 void IntelliPhotoGui::slotClearActiveLayer(){
158  // Stores button value
159  bool ok1, ok2, ok3, ok4;
160 
161  // "Red Input" is the title of the window
162  // the next tr is the text to display
163  // Define the standard Value, min, max, step and ok button
164  int red = QInputDialog::getInt(this, tr("Red Input"),
165  tr("Red:"),
166  255,0, 255,1, &ok1);
167  // "Green Input" is the title of the window
168  int green = QInputDialog::getInt(this, tr("Green Input"),
169  tr("Green:"),
170  255,0, 255, 1, &ok2);
171  // "Blue Input" is the title of the window
172  int blue = QInputDialog::getInt(this, tr("Blue Input"),
173  tr("Blue:"),
174  255,0, 255, 1, &ok3);
175  // "Alpha Input" is the title of the window
176  int alpha = QInputDialog::getInt(this, tr("Alpha Input"),
177  tr("Alpha:"),
178  255,0, 255, 1, &ok4);
179  if (ok1&&ok2&&ok3&&ok4)
180  {
181  paintingArea->floodFill(red, green, blue, alpha);
182  UpdateGui();
183  }
184 }
185 
186 void IntelliPhotoGui::slotSetActiveLayer(){
187  // Stores button value
188  bool ok1;
189 
190  // "Layer to set on" is the title of the window
191  // the next tr is the text to display
192  // Define the standard Value, min, max, step and ok button
193  int layer = QInputDialog::getInt(this, tr("Layer to set on"),
194  tr("Layer:"),
195  -1,0,255,1, &ok1);
196  if (ok1)
197  {
198  paintingArea->setLayerActive(layer);
199  UpdateGui();
200  }
201 }
202 
203 void IntelliPhotoGui::slotSetFirstColor(){
204  paintingArea->colorPickerSetFirstColor();
205  UpdateGui();
206 }
207 
208 void IntelliPhotoGui::slotSetSecondColor(){
209  paintingArea->colorPickerSetSecondColor();
210  UpdateGui();
211 }
212 
213 void IntelliPhotoGui::slotSwapColor(){
214  paintingArea->colorPickerSwapColors();
215  UpdateGui();
216 }
217 
218 void IntelliPhotoGui::slotCreatePenTool(){
219  PenButton->setChecked(true);
220  paintingArea->createPenTool();
221 }
222 
223 void IntelliPhotoGui::slotCreatePlainTool(){
224  PlainButton->setChecked(true);
225  paintingArea->createPlainTool();
226 }
227 
228 void IntelliPhotoGui::slotCreateLineTool(){
229  LineButton->setChecked(true);
230  paintingArea->createLineTool();
231 }
232 
233 void IntelliPhotoGui::slotCreateRectangleTool(){
234  RectangleButton->setChecked(true);
235  paintingArea->createRectangleTool();
236 }
237 
238 void IntelliPhotoGui::slotCreateCircleTool(){
239  CircleButton->setChecked(true);
240  paintingArea->createCircleTool();
241 }
242 
243 void IntelliPhotoGui::slotCreatePolygonTool(){
244  PolygonButton->setChecked(true);
245  paintingArea->createPolygonTool();
246 }
247 
248 void IntelliPhotoGui::slotCreateFloodFillTool(){
249  FloodFillButton->setChecked(true);
250  paintingArea->createFloodFillTool();
251 }
252 
253 // Open an about dialog
254 void IntelliPhotoGui::slotAboutDialog(){
255  // Window title and text to display
256  QMessageBox::about(this, tr("About Painting"),
257  tr("<p><b>IntelliPhoto</b>Pretty basic editor.</p>"));
258 }
259 
260 void IntelliPhotoGui::slotEnterPressed(){
261  QString string = EditLineWidth->text();
262  if(string.toInt() > 50) {
263  EditLineWidth->setText("50");
264  }
265  paintingArea->Toolsettings.setLineWidth(string.toInt());
266  string = EditLineInnerAlpha->text();
267  if(string.toInt() > 255) {
268  EditLineInnerAlpha->setText("255");
269  }
270  paintingArea->Toolsettings.setInnerAlpha(string.toInt());
271 }
272 
273 void IntelliPhotoGui::slotResetTools(){
274  CircleButton->setChecked(false);
275  FloodFillButton->setChecked(false);
276  LineButton->setChecked(false);
277  PenButton->setChecked(false);
278  PlainButton->setChecked(false);
279  PolygonButton->setChecked(false);
280  RectangleButton->setChecked(false);
281 }
282 
283 // Define menu actions that call functions
284 void IntelliPhotoGui::createActions(){
285  // Get a list of the supported file formats
286  // QImageWriter is used to write images to files
287  foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
288  QString text = tr("%1...").arg(QString(format).toUpper());
289 
290  // Create an action for each file format
291  QAction*action = new QAction(text, this);
292 
293  // Set an action for each file format
294  action->setData(format);
295 
296  // When clicked call IntelliPhotoGui::save()
297  connect(action, SIGNAL(triggered()), this, SLOT(slotSave()));
298 
299  // Attach each file format option menu item to Save As
300  actionSaveAs.append(action);
301  }
302 
303  //set exporter to actions
304  QAction*pngSaveAction = new QAction("PNG-8", this);
305  pngSaveAction->setData("PNG");
306  // When clicked call IntelliPhotoGui::save()
307  connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(slotSave()));
308  // Attach each PNG in save Menu
309  actionSaveAs.append(pngSaveAction);
310 
311  // Create exit action and tie to IntelliPhotoGui::close()
312  actionExit = new QAction(tr("&Exit"), this);
313  actionExit->setShortcuts(QKeySequence::Quit);
314  connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
315 
316  actionOpen = new QAction(tr("&Open"), this);
317  actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
318  connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen()));
319 
320  // Create New Layer action and tie to IntelliPhotoGui::newLayer()
321  actionCreateNewLayer = new QAction(tr("&New Layer..."), this);
322  actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
323  connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer()));
324 
325  // Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
326  actionDeleteLayer = new QAction(tr("&Delete Layer..."), this);
327  connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer()));
328 
329  actionSetActiveLayer = new QAction(tr("&set Active"), this);
330  connect(actionSetActiveLayer, SIGNAL(triggered()), this, SLOT(slotSetActiveLayer()));
331 
332  actionSetActiveAlpha = new QAction(tr("&set Alpha"), this);
333  connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha()));
334 
335  actionMovePositionUp = new QAction(tr("&move Up"), this);
336  actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
337  connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp()));
338 
339  actionMovePositionDown = new QAction(tr("&move Down"), this);
340  actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
341  connect(actionMovePositionDown, SIGNAL(triggered()), this, SLOT(slotPositionMoveDown()));
342 
343  actionMovePositionLeft = new QAction(tr("&move Left"), this);
344  actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
345  connect(actionMovePositionLeft, SIGNAL(triggered()), this, SLOT(slotPositionMoveLeft()));
346 
347  actionMovePositionRight = new QAction(tr("&move Right"), this);
348  actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
349  connect(actionMovePositionRight, SIGNAL(triggered()), this, SLOT(slotPositionMoveRight()));
350 
351  actionMoveLayerUp = new QAction(tr("&move Layer Up"), this);
352  actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
353  connect(actionMoveLayerUp, SIGNAL(triggered()), this, SLOT(slotMoveLayerUp()));
354 
355  actionMoveLayerDown= new QAction(tr("&move Layer Down"), this);
356  actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
357  connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown()));
358 
359  //Create Color Actions here
360  actionColorPickerFirstColor = new QAction(tr("&Main"), this);
361  connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor()));
362  connect(FirstColorButton, SIGNAL(clicked()), this, SLOT(slotSetFirstColor()));
363 
364  actionColorPickerSecondColor = new QAction(tr("&Secondary"), this);
365  connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetSecondColor()));
366  connect(SecondColorButton, SIGNAL(clicked()), this, SLOT(slotSetSecondColor()));
367 
368  actionColorSwap = new QAction(tr("&Switch"), this);
369  actionColorSwap->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
370  connect(actionColorSwap, SIGNAL(triggered()), this, SLOT(slotSwapColor()));
371  connect(SwitchColorButton, SIGNAL(clicked()), this, SLOT(slotSwapColor()));
372 
373  //Create Tool actions down here
374  actionCreatePlainTool = new QAction(tr("&Plain"), this);
375  connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
376  connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotCreatePlainTool()));
377 
378 
379  actionCreatePenTool = new QAction(tr("&Pen"),this);
380  connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
381  connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool()));
382 
383  actionCreateLineTool = new QAction(tr("&Line"), this);
384  connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
385  connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool()));
386 
387  actionCreateCircleTool = new QAction(tr("&Circle"), this);
388  connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
389  connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotCreateCircleTool()));
390 
391  actionCreateRectangleTool = new QAction(tr("&Rectangle"), this);
392  connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
393  connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotCreateRectangleTool()));
394 
395  actionCreatePolygonTool = new QAction(tr("&Polygon"), this);
396  connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
397  connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotCreatePolygonTool()));
398 
399  actionCreateFloodFillTool = new QAction(tr("&FloodFill"), this);
400  connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotResetTools()));
401  connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool()));
402 
403  // Create about action and tie to IntelliPhotoGui::about()
404  actionAboutDialog = new QAction(tr("&About"), this);
405  connect(actionAboutDialog, SIGNAL(triggered()), this, SLOT(slotAboutDialog()));
406 
407  // Create about Qt action and tie to IntelliPhotoGui::aboutQt()
408  actionAboutQtDialog = new QAction(tr("About &Qt"), this);
409  connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
410 
411  connect(EditLineWidth, SIGNAL(returnPressed()), this, SLOT(slotEnterPressed()));
412  connect(EditLineInnerAlpha, SIGNAL(returnPressed()), this, SLOT(slotEnterPressed()));
413 
414  connect(CircleButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
415  connect(CircleButton, SIGNAL(clicked()), this, SLOT(slotCreateCircleTool()));
416 
417  connect(FloodFillButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
418  connect(FloodFillButton, SIGNAL(clicked()), this, SLOT(slotCreateFloodFillTool()));
419 
420  connect(LineButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
421  connect(LineButton, SIGNAL(clicked()), this, SLOT(slotCreateLineTool()));
422 
423  connect(PenButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
424  connect(PenButton, SIGNAL(clicked()), this, SLOT(slotCreatePenTool()));
425 
426  connect(PlainButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
427  connect(PlainButton, SIGNAL(clicked()), this, SLOT(slotCreatePlainTool()));
428 
429  connect(PolygonButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
430  connect(PolygonButton, SIGNAL(clicked()), this, SLOT(slotCreatePolygonTool()));
431 
432  connect(RectangleButton,SIGNAL(pressed()), this, SLOT(slotResetTools()));
433  connect(RectangleButton, SIGNAL(clicked()), this, SLOT(slotCreateRectangleTool()));
434 }
435 
436 // Create the menubar
437 void IntelliPhotoGui::createMenus(){
438  // Create Save As option and the list of file types
439  saveAsMenu = new QMenu(tr("&Save As"), this);
440  foreach (QAction *action, actionSaveAs)
441  saveAsMenu->addAction(action);
442 
443 
444  // Attach all actions to File
445  fileMenu = new QMenu(tr("&File"), this);
446  fileMenu->addAction(actionOpen);
447  fileMenu->addMenu(saveAsMenu);
448  fileMenu->addSeparator();
449  fileMenu->addAction(actionExit);
450 
451  // Attach all actions to Options
452  optionMenu = new QMenu(tr("&Options"), this);
453  optionMenu->addAction(actionSetActiveLayer);
454  optionMenu->addAction(actionSetActiveAlpha);
455  optionMenu->addAction(actionMovePositionUp);
456  optionMenu->addAction(actionMovePositionDown);
457  optionMenu->addAction(actionMovePositionLeft);
458  optionMenu->addAction(actionMovePositionRight);
459  optionMenu->addAction(actionMoveLayerUp);
460  optionMenu->addAction(actionMoveLayerDown);
461 
462  // Attach all actions to Layer
463  layerMenu = new QMenu(tr("&Layer"), this);
464  layerMenu->addAction(actionCreateNewLayer);
465  layerMenu->addAction(actionDeleteLayer);
466 
467  //Attach all Color Options
468  colorMenu = new QMenu(tr("&Color"), this);
469  colorMenu->addAction(actionColorPickerFirstColor);
470  colorMenu->addAction(actionColorPickerSecondColor);
471  colorMenu->addAction(actionColorSwap);
472 
473  //Attach all Tool Options
474  toolMenu = new QMenu(tr("&Tools"), this);
475  toolMenu->addAction(actionCreateCircleTool);
476  toolMenu->addAction(actionCreateFloodFillTool);
477  toolMenu->addAction(actionCreateLineTool);
478  toolMenu->addAction(actionCreatePenTool);
479  toolMenu->addAction(actionCreatePlainTool);
480  toolMenu->addAction(actionCreatePolygonTool);
481  toolMenu->addAction(actionCreateRectangleTool);
482  toolMenu->addSeparator();
483  toolMenu->addMenu(colorMenu);
484 
485  // Attach all actions to Help
486  helpMenu = new QMenu(tr("&Help"), this);
487  helpMenu->addAction(actionAboutDialog);
488  helpMenu->addAction(actionAboutQtDialog);
489 
490  // Add menu items to the menubar
491  menuBar()->addMenu(fileMenu);
492  menuBar()->addMenu(optionMenu);
493  menuBar()->addMenu(layerMenu);
494  menuBar()->addMenu(toolMenu);
495  menuBar()->addMenu(helpMenu);
496 }
497 
498 void IntelliPhotoGui::createGui(){
499  // create a central widget to work on
500  centralGuiWidget = new QWidget(this);
501  setCentralWidget(centralGuiWidget);
502 
503  // create the grid for the layout
504  mainLayout = new QGridLayout(centralGuiWidget);
505  centralGuiWidget->setLayout(mainLayout);
506 
507  // create Gui elements
508  paintingArea = new PaintingArea();
509  paintingArea->DumpyGui = this;
510 
511  p = QPixmap(":/Icons/Buttons/icons/circle-tool.svg");
512  CircleButton = new QPushButton();
513  CircleButton->setFixedSize(Buttonsize);
514  CircleButton->setIcon(p);
515  CircleButton->setIconSize(Buttonsize);
516  CircleButton->setCheckable(true);
517 
518  p = QPixmap(":/Icons/Buttons/icons/flood-fill-tool.svg");
519  FloodFillButton = new QPushButton();
520  FloodFillButton->setFixedSize(Buttonsize);
521  FloodFillButton->setIcon(p);
522  FloodFillButton->setIconSize(Buttonsize);
523  FloodFillButton->setCheckable(true);
524 
525  p = QPixmap(":/Icons/Buttons/icons/icon.png");
526  LineButton = new QPushButton();
527  LineButton->setFixedSize(Buttonsize);
528  LineButton->setIcon(p);
529  LineButton->setIconSize(Buttonsize);
530  LineButton->setCheckable(true);
531 
532  p = QPixmap(":/Icons/Buttons/icons/pen-tool.svg");
533  PenButton = new QPushButton();
534  PenButton->setFixedSize(Buttonsize);
535  PenButton->setIcon(p);
536  PenButton->setIconSize(Buttonsize);
537  PenButton->setCheckable(true);
538 
539  p = QPixmap(":/Icons/Buttons/icons/icon.png");
540  PlainButton = new QPushButton();
541  PlainButton->setFixedSize(Buttonsize);
542  PlainButton->setIcon(p);
543  PlainButton->setIconSize(Buttonsize);
544  PlainButton->setCheckable(true);
545 
546  p = QPixmap(":/Icons/Buttons/icons/polygon-tool.svg");
547  PolygonButton = new QPushButton();
548  PolygonButton->setFixedSize(Buttonsize);
549  PolygonButton->setIcon(p);
550  PolygonButton->setIconSize(Buttonsize);
551  PolygonButton->setCheckable(true);
552 
553  p = QPixmap(":/Icons/Buttons/icons/rectangle-tool.svg");
554  RectangleButton = new QPushButton();
555  RectangleButton->setFixedSize(Buttonsize);
556  RectangleButton->setIcon(p);
557  RectangleButton->setIconSize(Buttonsize);
558  RectangleButton->setCheckable(true);
559 
560  WidthLine = new QLabel();
561  WidthLine->setText("Width");
562  WidthLine->setFixedSize(Buttonsize.width(),Buttonsize.height()/3);
563 
564  EditLineWidth = new QLineEdit();
565  EditLineWidth->setFixedSize(Buttonsize.width(),Buttonsize.height()/3);
566  EditLineWidth->setText("5");
567  ValidatorLineWidth = new QIntValidator();
568  ValidatorLineWidth->setTop(99);
569  ValidatorLineWidth->setBottom(1);
570  EditLineWidth->setValidator(ValidatorLineWidth);
571 
572  innerAlphaLine = new QLabel();
573  innerAlphaLine->setText("Inner Alpha");
574  innerAlphaLine->setFixedSize(Buttonsize.width(),Buttonsize.height()/3);
575 
576  EditLineInnerAlpha = new QLineEdit();
577  EditLineInnerAlpha->setFixedSize(Buttonsize.width(),Buttonsize.height()/3);
578  EditLineInnerAlpha->setText("255");
579  ValidatorInnerAlpha = new QIntValidator();
580  ValidatorInnerAlpha->setTop(999);
581  ValidatorInnerAlpha->setBottom(0);
582  EditLineInnerAlpha->setValidator(ValidatorInnerAlpha);
583 
584  FirstColorButton = new QPushButton();
585  FirstColorButton->setFixedSize(Buttonsize/2);
586 
587  SecondColorButton = new QPushButton();
588  SecondColorButton->setFixedSize(Buttonsize/2);
589 
590  p = QPixmap(":/Icons/Buttons/icons/Wechselpfeile.png");
591  SwitchColorButton = new QPushButton();
592  SwitchColorButton->setFixedSize(Buttonsize.width(),Buttonsize.height()/2);
593  SwitchColorButton->setIcon(p);
594  SwitchColorButton->setIconSize(QSize(Buttonsize.width(),Buttonsize.height()/2));
595 
596  ActiveLayerLine = new QLabel();
597  QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer());
598  ActiveLayerLine->setText(string);
599  ActiveLayerLine->setFixedSize(Buttonsize.width()+10,Buttonsize.height()/3);
600 
601  p = p.fromImage(paintingArea->getImageOfActiveLayer()->getImageData());
602 
603  ActiveLayerImageButton = new QPushButton();
604  ActiveLayerImageButton->setFixedSize(Buttonsize);
605  ActiveLayerImageButton->setIcon(p);
606  ActiveLayerImageButton->setIconSize(Buttonsize);
607 
608  // set gui elements
609 
610  mainLayout->addWidget(paintingArea,1,1,20,1);
611  mainLayout->addWidget(CircleButton,1,2,1,2);
612  mainLayout->addWidget(FloodFillButton,2,2,1,2);
613  mainLayout->addWidget(LineButton,3,2,1,2);
614  mainLayout->addWidget(PenButton,4,2,1,2);
615  mainLayout->addWidget(PlainButton,5,2,1,2);
616  mainLayout->addWidget(PolygonButton,6,2,1,2);
617  mainLayout->addWidget(RectangleButton,7,2,1,2);
618  mainLayout->addWidget(WidthLine,8,2,1,2);
619  mainLayout->addWidget(EditLineWidth,9,2,1,2);
620  mainLayout->addWidget(innerAlphaLine,10,2,1,2);
621  mainLayout->addWidget(EditLineInnerAlpha,11,2,1,2);
622  mainLayout->addWidget(FirstColorButton,12,2,1,1);
623  mainLayout->addWidget(SecondColorButton,12,3,1,1);
624  mainLayout->addWidget(SwitchColorButton,13,2,1,2);
625  mainLayout->addWidget(ActiveLayerLine,14,2,1,2);
626  mainLayout->addWidget(ActiveLayerImageButton,15,2,1,2);
627 }
628 
629 void IntelliPhotoGui::setIntelliStyle(){
630  // Set the title
631  setWindowTitle("IntelliPhoto Prototype");
632  // Set style sheet
633  this->setStyleSheet("background-color:rgb(64,64,64)");
634  this->centralGuiWidget->setStyleSheet("color:rgb(255,255,255)");
635  this->menuBar()->setStyleSheet("color:rgb(255,255,255)");
636  QString string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name());
637  FirstColorButton->setStyleSheet(string);
638  string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name());
639  SecondColorButton->setStyleSheet(string);
640 }
641 
642 bool IntelliPhotoGui::maybeSave(){
643  // Check for changes since last save
644 
645  // TODO insert variable for modified status here to make an save exit message
646  if (false) {
647  QMessageBox::StandardButton ret;
648 
649  // Painting is the title of the window
650  // Add text and the buttons
651  ret = QMessageBox::warning(this, tr("Painting"),
652  tr("The image has been modified.\n"
653  "Do you want to save your changes?"),
654  QMessageBox::Save | QMessageBox::Discard
655  | QMessageBox::Cancel);
656 
657  // If save button clicked call for file to be saved
658  if (ret == QMessageBox::Save) {
659  return saveFile("png");
660 
661  // If cancel do nothing
662  } else if (ret == QMessageBox::Cancel) {
663  return false;
664  }
665  }
666  return true;
667 }
668 
669 bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){
670  // Define path, name and default file type
671  QString initialPath = QDir::currentPath() + "/untitled." + fileFormat;
672 
673  // Get selected file from dialog
674  // Add the proper file formats and extensions
675  QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
676  initialPath,
677  tr("%1 Files (*.%2);;All Files (*)")
678  .arg(QString::fromLatin1(fileFormat.toUpper()))
679  .arg(QString::fromLatin1(fileFormat)), nullptr, QFileDialog::DontUseNativeDialog);
680 
681  // If no file do nothing
682  if (fileName.isEmpty()) {
683  return false;
684  } else {
685  // Call for the file to be saved
686  return paintingArea->save(fileName, fileFormat.constData());
687  }
688 }
689 
690 void IntelliPhotoGui::setDefaultToolValue(){
691  slotEnterPressed();
692 }
693 
695  QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer());
696  ActiveLayerLine->setText(string);
697  p = p.fromImage(paintingArea->getImageOfActiveLayer()->getImageData());
698  ActiveLayerImageButton->setIcon(p);
699  ActiveLayerImageButton->setIconSize(Buttonsize);
700 
701  string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name());
702  FirstColorButton->setStyleSheet(string);
703  string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name());
704  SecondColorButton->setStyleSheet(string);
705 }
PaintingArea::createCircleTool
void createCircleTool()
Definition: PaintingArea.cpp:222
PaintingArea::getImageOfActiveLayer
IntelliImage * getImageOfActiveLayer()
Definition: PaintingArea.cpp:406
PaintingArea::createRectangleTool
void createRectangleTool()
Definition: PaintingArea.cpp:217
IntelliToolsettings::setLineWidth
void setLineWidth()
Definition: IntelliToolsettings.cpp:19
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:115
PaintingArea::setLayerAlpha
void setLayerAlpha(int idx, int alpha)
The setAlphaOfLayer method sets the alpha value of a specific layer.
Definition: PaintingArea.cpp:96
PaintingArea::setLayerActive
void setLayerActive(int idx)
The setLayerToActive method marks a specific layer as active.
Definition: PaintingArea.cpp:90
PaintingArea::floodFill
void floodFill(int r, int g, int b, int a)
The floodFill method fills a the active layer with a given color.
Definition: PaintingArea.cpp:139
IntelliColorPicker::getSecondColor
QColor getSecondColor()
A function to read the secondary selected color.
Definition: IntelliColorPicker.cpp:20
PaintingArea::deleteLayer
void deleteLayer(int idx)
The deleteLayer method removes a layer at a given idx.
Definition: PaintingArea.cpp:74
PaintingArea::createPlainTool
void createPlainTool()
Definition: PaintingArea.cpp:207
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:37
PaintingArea::createPenTool
void createPenTool()
Definition: PaintingArea.cpp:202
PaintingArea::createLineTool
void createLineTool()
Definition: PaintingArea.cpp:212
PaintingArea::colorPickerSetSecondColor
void colorPickerSetSecondColor()
The colorPickerSetSecondColor calls the QTColorPicker to determine the secondary drawing color.
Definition: PaintingArea.cpp:193
PaintingArea::colorPickerSetFirstColor
void colorPickerSetFirstColor()
The colorPickerSetFirstColor calls the QTColorPicker to determine the primary drawing color.
Definition: PaintingArea.cpp:188
IntelliPhotoGui.h
PaintingArea::getNumberOfActiveLayer
int getNumberOfActiveLayer()
Definition: PaintingArea.cpp:402
IntelliPhotoGui::closeEvent
void closeEvent(QCloseEvent *event) override
Definition: IntelliPhotoGui.cpp:23
IntelliImage::getImageData
virtual QImage getImageData()
getImageData returns the data of the current image.
Definition: IntelliImage.cpp:123
PaintingArea::open
bool open(const QString &filePath)
The open method is used for loading a picture into the current layer.
Definition: PaintingArea.cpp:103
PaintingArea::createPolygonTool
void createPolygonTool()
Definition: PaintingArea.cpp:226
PaintingArea::moveActiveLayer
void moveActiveLayer(int idx)
The moveActiveLayer moves the active layer to a specific position in the layer stack.
Definition: PaintingArea.cpp:160
PaintingArea::colorPicker
IntelliColorPicker colorPicker
Definition: PaintingArea.h:175
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:231
IntelliPhotoGui::UpdateGui
void UpdateGui()
Definition: IntelliPhotoGui.cpp:694
PaintingArea::Toolsettings
IntelliToolsettings Toolsettings
Definition: PaintingArea.h:174
PaintingArea::colorPickerSwapColors
void colorPickerSwapColors()
The colorPickerSwitchColor swaps the primary color with the secondary drawing color.
Definition: PaintingArea.cpp:198
PaintingArea::movePositionActive
void movePositionActive(int x, int y)
The movePositionActive method moves the active layer to certain position.
Definition: PaintingArea.cpp:148
IntelliToolsettings::setInnerAlpha
void setInnerAlpha()
Definition: IntelliToolsettings.cpp:37
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:56