19 setDefaultToolValue();
36 void IntelliPhotoGui::slotOpen(){
44 QString fileName = QFileDialog::getOpenFileName(
this,
45 tr(
"Open File"), QDir::currentPath(),
nullptr,
nullptr, QFileDialog::DontUseNativeDialog);
49 if (!fileName.isEmpty())
50 paintingArea->
open(fileName);
55 void IntelliPhotoGui::slotSave(){
57 QAction*action = qobject_cast<QAction*>(sender());
60 QByteArray fileFormat = action->data().toByteArray();
67 void IntelliPhotoGui::slotCreateNewLayer(){
74 int width = QInputDialog::getInt(
this, tr(
"New Layer"),
77 int height = QInputDialog::getInt(
this, tr(
"New Layer"),
83 int layer = paintingArea->
addLayer(width,height,0,0);
89 void IntelliPhotoGui::slotDeleteLayer(){
96 int layerNumber = QInputDialog::getInt(
this, tr(
"delete Layer"),
106 void IntelliPhotoGui::slotSetActiveAlpha(){
113 int layer = QInputDialog::getInt(
this, tr(
"Layer to set on"),
117 int alpha = QInputDialog::getInt(
this, tr(
"New Alpha"),
119 255,0, 255, 1, &ok2);
127 void IntelliPhotoGui::slotPositionMoveUp(){
132 void IntelliPhotoGui::slotPositionMoveDown(){
137 void IntelliPhotoGui::slotPositionMoveLeft(){
142 void IntelliPhotoGui::slotPositionMoveRight(){
147 void IntelliPhotoGui::slotMoveLayerUp(){
152 void IntelliPhotoGui::slotMoveLayerDown(){
157 void IntelliPhotoGui::slotClearActiveLayer(){
159 bool ok1, ok2, ok3, ok4;
164 int red = QInputDialog::getInt(
this, tr(
"Red Input"),
168 int green = QInputDialog::getInt(
this, tr(
"Green Input"),
170 255,0, 255, 1, &ok2);
172 int blue = QInputDialog::getInt(
this, tr(
"Blue Input"),
174 255,0, 255, 1, &ok3);
176 int alpha = QInputDialog::getInt(
this, tr(
"Alpha Input"),
178 255,0, 255, 1, &ok4);
179 if (ok1&&ok2&&ok3&&ok4)
181 paintingArea->
floodFill(red, green, blue, alpha);
186 void IntelliPhotoGui::slotSetActiveLayer(){
193 int layer = QInputDialog::getInt(
this, tr(
"Layer to set on"),
203 void IntelliPhotoGui::slotSetFirstColor(){
208 void IntelliPhotoGui::slotSetSecondColor(){
213 void IntelliPhotoGui::slotSwapColor(){
218 void IntelliPhotoGui::slotCreatePenTool(){
219 PenButton->setChecked(
true);
223 void IntelliPhotoGui::slotCreatePlainTool(){
224 PlainButton->setChecked(
true);
228 void IntelliPhotoGui::slotCreateLineTool(){
229 LineButton->setChecked(
true);
233 void IntelliPhotoGui::slotCreateRectangleTool(){
234 RectangleButton->setChecked(
true);
238 void IntelliPhotoGui::slotCreateCircleTool(){
239 CircleButton->setChecked(
true);
243 void IntelliPhotoGui::slotCreatePolygonTool(){
244 PolygonButton->setChecked(
true);
248 void IntelliPhotoGui::slotCreateFloodFillTool(){
249 FloodFillButton->setChecked(
true);
254 void IntelliPhotoGui::slotAboutDialog(){
256 QMessageBox::about(
this, tr(
"About Painting"),
257 tr(
"<p><b>IntelliPhoto</b>Pretty basic editor.</p>"));
260 void IntelliPhotoGui::slotEnterPressed(){
261 QString
string = EditLineWidth->text();
262 if(
string.toInt() > 50) {
263 EditLineWidth->setText(
"50");
266 string = EditLineInnerAlpha->text();
267 if(
string.toInt() > 255) {
268 EditLineInnerAlpha->setText(
"255");
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);
284 void IntelliPhotoGui::createActions(){
287 foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
288 QString text = tr(
"%1...").arg(QString(format).toUpper());
291 QAction*action =
new QAction(text,
this);
294 action->setData(format);
297 connect(action, SIGNAL(triggered()),
this, SLOT(slotSave()));
300 actionSaveAs.append(action);
304 QAction*pngSaveAction =
new QAction(
"PNG-8",
this);
305 pngSaveAction->setData(
"PNG");
307 connect(pngSaveAction, SIGNAL(triggered()),
this, SLOT(slotSave()));
309 actionSaveAs.append(pngSaveAction);
312 actionExit =
new QAction(tr(
"&Exit"),
this);
313 actionExit->setShortcuts(QKeySequence::Quit);
314 connect(actionExit, SIGNAL(triggered()),
this, SLOT(close()));
316 actionOpen =
new QAction(tr(
"&Open"),
this);
317 actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
318 connect(actionOpen, SIGNAL(triggered()),
this, SLOT(slotOpen()));
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()));
326 actionDeleteLayer =
new QAction(tr(
"&Delete Layer..."),
this);
327 connect(actionDeleteLayer, SIGNAL(triggered()),
this, SLOT(slotDeleteLayer()));
329 actionSetActiveLayer =
new QAction(tr(
"&set Active"),
this);
330 connect(actionSetActiveLayer, SIGNAL(triggered()),
this, SLOT(slotSetActiveLayer()));
332 actionSetActiveAlpha =
new QAction(tr(
"&set Alpha"),
this);
333 connect(actionSetActiveAlpha, SIGNAL(triggered()),
this, SLOT(slotSetActiveAlpha()));
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()));
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()));
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()));
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()));
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()));
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()));
360 actionColorPickerFirstColor =
new QAction(tr(
"&Main"),
this);
361 connect(actionColorPickerFirstColor, SIGNAL(triggered()),
this, SLOT(slotSetFirstColor()));
362 connect(FirstColorButton, SIGNAL(clicked()),
this, SLOT(slotSetFirstColor()));
364 actionColorPickerSecondColor =
new QAction(tr(
"&Secondary"),
this);
365 connect(actionColorPickerSecondColor, SIGNAL(triggered()),
this, SLOT(slotSetSecondColor()));
366 connect(SecondColorButton, SIGNAL(clicked()),
this, SLOT(slotSetSecondColor()));
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()));
374 actionCreatePlainTool =
new QAction(tr(
"&Plain"),
this);
375 connect(actionCreatePlainTool, SIGNAL(triggered()),
this, SLOT(slotResetTools()));
376 connect(actionCreatePlainTool, SIGNAL(triggered()),
this, SLOT(slotCreatePlainTool()));
379 actionCreatePenTool =
new QAction(tr(
"&Pen"),
this);
380 connect(actionCreatePenTool, SIGNAL(triggered()),
this, SLOT(slotResetTools()));
381 connect(actionCreatePenTool, SIGNAL(triggered()),
this, SLOT(slotCreatePenTool()));
383 actionCreateLineTool =
new QAction(tr(
"&Line"),
this);
384 connect(actionCreateLineTool, SIGNAL(triggered()),
this, SLOT(slotResetTools()));
385 connect(actionCreateLineTool, SIGNAL(triggered()),
this, SLOT(slotCreateLineTool()));
387 actionCreateCircleTool =
new QAction(tr(
"&Circle"),
this);
388 connect(actionCreateCircleTool, SIGNAL(triggered()),
this, SLOT(slotResetTools()));
389 connect(actionCreateCircleTool, SIGNAL(triggered()),
this, SLOT(slotCreateCircleTool()));
391 actionCreateRectangleTool =
new QAction(tr(
"&Rectangle"),
this);
392 connect(actionCreateRectangleTool, SIGNAL(triggered()),
this, SLOT(slotResetTools()));
393 connect(actionCreateRectangleTool, SIGNAL(triggered()),
this, SLOT(slotCreateRectangleTool()));
395 actionCreatePolygonTool =
new QAction(tr(
"&Polygon"),
this);
396 connect(actionCreatePolygonTool, SIGNAL(triggered()),
this, SLOT(slotResetTools()));
397 connect(actionCreatePolygonTool, SIGNAL(triggered()),
this, SLOT(slotCreatePolygonTool()));
399 actionCreateFloodFillTool =
new QAction(tr(
"&FloodFill"),
this);
400 connect(actionCreateFloodFillTool, SIGNAL(triggered()),
this, SLOT(slotResetTools()));
401 connect(actionCreateFloodFillTool, SIGNAL(triggered()),
this, SLOT(slotCreateFloodFillTool()));
404 actionAboutDialog =
new QAction(tr(
"&About"),
this);
405 connect(actionAboutDialog, SIGNAL(triggered()),
this, SLOT(slotAboutDialog()));
408 actionAboutQtDialog =
new QAction(tr(
"About &Qt"),
this);
409 connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
411 connect(EditLineWidth, SIGNAL(returnPressed()),
this, SLOT(slotEnterPressed()));
412 connect(EditLineInnerAlpha, SIGNAL(returnPressed()),
this, SLOT(slotEnterPressed()));
414 connect(CircleButton,SIGNAL(pressed()),
this, SLOT(slotResetTools()));
415 connect(CircleButton, SIGNAL(clicked()),
this, SLOT(slotCreateCircleTool()));
417 connect(FloodFillButton,SIGNAL(pressed()),
this, SLOT(slotResetTools()));
418 connect(FloodFillButton, SIGNAL(clicked()),
this, SLOT(slotCreateFloodFillTool()));
420 connect(LineButton,SIGNAL(pressed()),
this, SLOT(slotResetTools()));
421 connect(LineButton, SIGNAL(clicked()),
this, SLOT(slotCreateLineTool()));
423 connect(PenButton,SIGNAL(pressed()),
this, SLOT(slotResetTools()));
424 connect(PenButton, SIGNAL(clicked()),
this, SLOT(slotCreatePenTool()));
426 connect(PlainButton,SIGNAL(pressed()),
this, SLOT(slotResetTools()));
427 connect(PlainButton, SIGNAL(clicked()),
this, SLOT(slotCreatePlainTool()));
429 connect(PolygonButton,SIGNAL(pressed()),
this, SLOT(slotResetTools()));
430 connect(PolygonButton, SIGNAL(clicked()),
this, SLOT(slotCreatePolygonTool()));
432 connect(RectangleButton,SIGNAL(pressed()),
this, SLOT(slotResetTools()));
433 connect(RectangleButton, SIGNAL(clicked()),
this, SLOT(slotCreateRectangleTool()));
437 void IntelliPhotoGui::createMenus(){
439 saveAsMenu =
new QMenu(tr(
"&Save As"),
this);
440 foreach (QAction *action, actionSaveAs)
441 saveAsMenu->addAction(action);
445 fileMenu =
new QMenu(tr(
"&File"),
this);
446 fileMenu->addAction(actionOpen);
447 fileMenu->addMenu(saveAsMenu);
448 fileMenu->addSeparator();
449 fileMenu->addAction(actionExit);
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);
463 layerMenu =
new QMenu(tr(
"&Layer"),
this);
464 layerMenu->addAction(actionCreateNewLayer);
465 layerMenu->addAction(actionDeleteLayer);
468 colorMenu =
new QMenu(tr(
"&Color"),
this);
469 colorMenu->addAction(actionColorPickerFirstColor);
470 colorMenu->addAction(actionColorPickerSecondColor);
471 colorMenu->addAction(actionColorSwap);
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);
486 helpMenu =
new QMenu(tr(
"&Help"),
this);
487 helpMenu->addAction(actionAboutDialog);
488 helpMenu->addAction(actionAboutQtDialog);
491 menuBar()->addMenu(fileMenu);
492 menuBar()->addMenu(optionMenu);
493 menuBar()->addMenu(layerMenu);
494 menuBar()->addMenu(toolMenu);
495 menuBar()->addMenu(helpMenu);
498 void IntelliPhotoGui::createGui(){
500 centralGuiWidget =
new QWidget(
this);
501 setCentralWidget(centralGuiWidget);
504 mainLayout =
new QGridLayout(centralGuiWidget);
505 centralGuiWidget->setLayout(mainLayout);
509 paintingArea->DumpyGui =
this;
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);
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);
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);
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);
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);
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);
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);
560 WidthLine =
new QLabel();
561 WidthLine->setText(
"Width");
562 WidthLine->setFixedSize(Buttonsize.width(),Buttonsize.height()/3);
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);
572 innerAlphaLine =
new QLabel();
573 innerAlphaLine->setText(
"Inner Alpha");
574 innerAlphaLine->setFixedSize(Buttonsize.width(),Buttonsize.height()/3);
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);
584 FirstColorButton =
new QPushButton();
585 FirstColorButton->setFixedSize(Buttonsize/2);
587 SecondColorButton =
new QPushButton();
588 SecondColorButton->setFixedSize(Buttonsize/2);
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));
596 ActiveLayerLine =
new QLabel();
598 ActiveLayerLine->setText(
string);
599 ActiveLayerLine->setFixedSize(Buttonsize.width()+10,Buttonsize.height()/3);
603 ActiveLayerImageButton =
new QPushButton();
604 ActiveLayerImageButton->setFixedSize(Buttonsize);
605 ActiveLayerImageButton->setIcon(p);
606 ActiveLayerImageButton->setIconSize(Buttonsize);
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);
629 void IntelliPhotoGui::setIntelliStyle(){
631 setWindowTitle(
"IntelliPhoto Prototype");
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)");
637 FirstColorButton->setStyleSheet(
string);
639 SecondColorButton->setStyleSheet(
string);
642 bool IntelliPhotoGui::maybeSave(){
647 QMessageBox::StandardButton ret;
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);
658 if (ret == QMessageBox::Save) {
659 return saveFile(
"png");
662 }
else if (ret == QMessageBox::Cancel) {
669 bool IntelliPhotoGui::saveFile(
const QByteArray &fileFormat){
671 QString initialPath = QDir::currentPath() +
"/untitled." + fileFormat;
675 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save As"),
677 tr(
"%1 Files (*.%2);;All Files (*)")
678 .arg(QString::fromLatin1(fileFormat.toUpper()))
679 .arg(QString::fromLatin1(fileFormat)),
nullptr, QFileDialog::DontUseNativeDialog);
682 if (fileName.isEmpty()) {
686 return paintingArea->
save(fileName, fileFormat.constData());
690 void IntelliPhotoGui::setDefaultToolValue(){
696 ActiveLayerLine->setText(
string);
698 ActiveLayerImageButton->setIcon(p);
699 ActiveLayerImageButton->setIconSize(Buttonsize);
702 FirstColorButton->setStyleSheet(
string);
704 SecondColorButton->setStyleSheet(
string);