39 void IntelliPhotoGui::slotOpen(){
47 QString fileName = QFileDialog::getOpenFileName(
this,
48 tr(
"Open File"), QDir::currentPath(),
nullptr,
nullptr, QFileDialog::DontUseNativeDialog);
52 if (!fileName.isEmpty())
53 paintingArea->
open(fileName);
58 void IntelliPhotoGui::slotSave(){
60 QAction*action = qobject_cast<QAction*>(sender());
63 QByteArray fileFormat = action->data().toByteArray();
70 void IntelliPhotoGui::slotCreateNewLayer(){
77 int width = QInputDialog::getInt(
this, tr(
"New Layer"),
80 int height = QInputDialog::getInt(
this, tr(
"New Layer"),
86 int layer = paintingArea->
addLayer(width,height,0,0);
92 void IntelliPhotoGui::slotDeleteLayer(){
99 int layerNumber = QInputDialog::getInt(
this, tr(
"delete Layer"),
107 void IntelliPhotoGui::slotSetActiveAlpha(){
114 int layer = QInputDialog::getInt(
this, tr(
"Layer to set on"),
118 int alpha = QInputDialog::getInt(
this, tr(
"New Alpha"),
120 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);
185 void IntelliPhotoGui::slotSetActiveLayer(){
192 int layer = QInputDialog::getInt(
this, tr(
"Layer to set on"),
201 void IntelliPhotoGui::slotSetFirstColor(){
205 void IntelliPhotoGui::slotSetSecondColor(){
209 void IntelliPhotoGui::slotSwitchColor(){
213 void IntelliPhotoGui::slotCreatePenTool(){
217 void IntelliPhotoGui::slotCreatePlainTool(){
221 void IntelliPhotoGui::slotCreateLineTool(){
225 void IntelliPhotoGui::slotCreateRectangleTool(){
229 void IntelliPhotoGui::slotCreateCircleTool(){
233 void IntelliPhotoGui::slotCreatePolygonTool(){
237 void IntelliPhotoGui::slotCreateFloodFillTool(){
242 void IntelliPhotoGui::slotAboutDialog(){
244 QMessageBox::about(
this, tr(
"About Painting"),
245 tr(
"<p><b>IntelliPhoto</b>Pretty basic editor.</p>"));
249 void IntelliPhotoGui::createActions(){
252 foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
253 QString text = tr(
"%1...").arg(QString(format).toUpper());
256 QAction*action =
new QAction(text,
this);
259 action->setData(format);
262 connect(action, SIGNAL(triggered()),
this, SLOT(slotSave()));
265 actionSaveAs.append(action);
269 QAction*pngSaveAction =
new QAction(
"PNG-8",
this);
270 pngSaveAction->setData(
"PNG");
272 connect(pngSaveAction, SIGNAL(triggered()),
this, SLOT(slotSave()));
274 actionSaveAs.append(pngSaveAction);
277 actionExit =
new QAction(tr(
"&Exit"),
this);
278 actionExit->setShortcuts(QKeySequence::Quit);
279 connect(actionExit, SIGNAL(triggered()),
this, SLOT(close()));
281 actionOpen =
new QAction(tr(
"&Open"),
this);
282 actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
283 connect(actionOpen, SIGNAL(triggered()),
this, SLOT(slotOpen()));
286 actionCreateNewLayer =
new QAction(tr(
"&New Layer..."),
this);
287 actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
288 connect(actionCreateNewLayer, SIGNAL(triggered()),
this, SLOT(slotCreateNewLayer()));
291 actionDeleteLayer =
new QAction(tr(
"&Delete Layer..."),
this);
292 connect(actionDeleteLayer, SIGNAL(triggered()),
this, SLOT(slotDeleteLayer()));
294 actionSetActiveLayer =
new QAction(tr(
"&set Active"),
this);
295 connect(actionSetActiveLayer, SIGNAL(triggered()),
this, SLOT(slotSetActiveLayer()));
297 actionSetActiveAlpha =
new QAction(tr(
"&set Alpha"),
this);
298 connect(actionSetActiveAlpha, SIGNAL(triggered()),
this, SLOT(slotSetActiveAlpha()));
300 actionMovePositionUp =
new QAction(tr(
"&move Up"),
this);
301 actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
302 connect(actionMovePositionUp, SIGNAL(triggered()),
this, SLOT(slotPositionMoveUp()));
304 actionMovePositionDown =
new QAction(tr(
"&move Down"),
this);
305 actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
306 connect(actionMovePositionDown, SIGNAL(triggered()),
this, SLOT(slotPositionMoveDown()));
308 actionMovePositionLeft =
new QAction(tr(
"&move Left"),
this);
309 actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
310 connect(actionMovePositionLeft, SIGNAL(triggered()),
this, SLOT(slotPositionMoveLeft()));
312 actionMovePositionRight =
new QAction(tr(
"&move Right"),
this);
313 actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
314 connect(actionMovePositionRight, SIGNAL(triggered()),
this, SLOT(slotPositionMoveRight()));
316 actionMoveLayerUp =
new QAction(tr(
"&move Layer Up"),
this);
317 actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
318 connect(actionMoveLayerUp, SIGNAL(triggered()),
this, SLOT(slotMoveLayerUp()));
320 actionMoveLayerDown=
new QAction(tr(
"&move Layer Down"),
this);
321 actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
322 connect(actionMoveLayerDown, SIGNAL(triggered()),
this, SLOT(slotMoveLayerDown()));
325 actionColorPickerFirstColor =
new QAction(tr(
"&Main"),
this);
326 connect(actionColorPickerFirstColor, SIGNAL(triggered()),
this, SLOT(slotSetFirstColor()));
328 actionColorPickerSecondColor =
new QAction(tr(
"&Secondary"),
this);
329 connect(actionColorPickerSecondColor, SIGNAL(triggered()),
this, SLOT(slotSetSecondColor()));
331 actionColorSwitch =
new QAction(tr(
"&Switch"),
this);
332 actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
333 connect(actionColorSwitch, SIGNAL(triggered()),
this, SLOT(slotSwitchColor()));
336 actionCreatePlainTool =
new QAction(tr(
"&Plain"),
this);
337 connect(actionCreatePlainTool, SIGNAL(triggered()),
this, SLOT(slotCreatePlainTool()));
339 actionCreatePenTool =
new QAction(tr(
"&Pen"),
this);
340 connect(actionCreatePenTool, SIGNAL(triggered()),
this, SLOT(slotCreatePenTool()));
342 actionCreateLineTool =
new QAction(tr(
"&Line"),
this);
343 connect(actionCreateLineTool, SIGNAL(triggered()),
this, SLOT(slotCreateLineTool()));
345 actionCreateCircleTool =
new QAction(tr(
"&Circle"),
this);
346 connect(actionCreateCircleTool, SIGNAL(triggered()),
this, SLOT(slotCreateCircleTool()));
348 actionCreateRectangleTool =
new QAction(tr(
"&Rectangle"),
this);
349 connect(actionCreateRectangleTool, SIGNAL(triggered()),
this, SLOT(slotCreateRectangleTool()));
351 actionCreatePolygonTool =
new QAction(tr(
"&Polygon"),
this);
352 connect(actionCreatePolygonTool, SIGNAL(triggered()),
this, SLOT(slotCreatePolygonTool()));
354 actionCreateFloodFillTool =
new QAction(tr(
"&FloodFill"),
this);
355 connect(actionCreateFloodFillTool, SIGNAL(triggered()),
this, SLOT(slotCreateFloodFillTool()));
358 actionAboutDialog =
new QAction(tr(
"&About"),
this);
359 connect(actionAboutDialog, SIGNAL(triggered()),
this, SLOT(slotAboutDialog()));
362 actionAboutQtDialog =
new QAction(tr(
"About &Qt"),
this);
363 connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
367 void IntelliPhotoGui::createMenus(){
369 saveAsMenu =
new QMenu(tr(
"&Save As"),
this);
370 foreach (QAction *action, actionSaveAs)
371 saveAsMenu->addAction(action);
375 fileMenu =
new QMenu(tr(
"&File"),
this);
376 fileMenu->addAction(actionOpen);
377 fileMenu->addMenu(saveAsMenu);
378 fileMenu->addSeparator();
379 fileMenu->addAction(actionExit);
382 optionMenu =
new QMenu(tr(
"&Options"),
this);
383 optionMenu->addAction(actionSetActiveLayer);
384 optionMenu->addAction(actionSetActiveAlpha);
385 optionMenu->addAction(actionMovePositionUp);
386 optionMenu->addAction(actionMovePositionDown);
387 optionMenu->addAction(actionMovePositionLeft);
388 optionMenu->addAction(actionMovePositionRight);
389 optionMenu->addAction(actionMoveLayerUp);
390 optionMenu->addAction(actionMoveLayerDown);
393 layerMenu =
new QMenu(tr(
"&Layer"),
this);
394 layerMenu->addAction(actionCreateNewLayer);
395 layerMenu->addAction(actionDeleteLayer);
398 colorMenu =
new QMenu(tr(
"&Color"),
this);
399 colorMenu->addAction(actionColorPickerFirstColor);
400 colorMenu->addAction(actionColorPickerSecondColor);
401 colorMenu->addAction(actionColorSwitch);
404 toolMenu =
new QMenu(tr(
"&Tools"),
this);
405 toolMenu->addAction(actionCreatePenTool);
406 toolMenu->addAction(actionCreatePlainTool);
407 toolMenu->addAction(actionCreateLineTool);
408 toolMenu->addAction(actionCreateRectangleTool);
409 toolMenu->addAction(actionCreateCircleTool);
410 toolMenu->addAction(actionCreatePolygonTool);
411 toolMenu->addAction(actionCreateFloodFillTool);
412 toolMenu->addSeparator();
413 toolMenu->addMenu(colorMenu);
416 helpMenu =
new QMenu(tr(
"&Help"),
this);
417 helpMenu->addAction(actionAboutDialog);
418 helpMenu->addAction(actionAboutQtDialog);
421 menuBar()->addMenu(fileMenu);
422 menuBar()->addMenu(optionMenu);
423 menuBar()->addMenu(layerMenu);
424 menuBar()->addMenu(toolMenu);
425 menuBar()->addMenu(helpMenu);
428 void IntelliPhotoGui::createGui(){
430 centralGuiWidget =
new QWidget(
this);
431 setCentralWidget(centralGuiWidget);
434 mainLayout =
new QGridLayout(centralGuiWidget);
435 centralGuiWidget->setLayout(mainLayout);
441 mainLayout->addWidget(paintingArea);
444 void IntelliPhotoGui::setIntelliStyle(){
446 setWindowTitle(
"IntelliPhoto Prototype");
448 this->setStyleSheet(
"background-color:rgb(64,64,64)");
449 this->centralGuiWidget->setStyleSheet(
"color:rgb(255,255,255)");
450 this->menuBar()->setStyleSheet(
"color:rgb(255,255,255)");
453 bool IntelliPhotoGui::maybeSave(){
458 QMessageBox::StandardButton ret;
462 ret = QMessageBox::warning(
this, tr(
"Painting"),
463 tr(
"The image has been modified.\n"
464 "Do you want to save your changes?"),
465 QMessageBox::Save | QMessageBox::Discard
466 | QMessageBox::Cancel);
469 if (ret == QMessageBox::Save) {
470 return saveFile(
"png");
473 }
else if (ret == QMessageBox::Cancel) {
480 bool IntelliPhotoGui::saveFile(
const QByteArray &fileFormat){
482 QString initialPath = QDir::currentPath() +
"/untitled." + fileFormat;
486 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save As"),
488 tr(
"%1 Files (*.%2);;All Files (*)")
489 .arg(QString::fromLatin1(fileFormat.toUpper()))
490 .arg(QString::fromLatin1(fileFormat)),
nullptr, QFileDialog::DontUseNativeDialog);
493 if (fileName.isEmpty()) {
497 return paintingArea->
save(fileName, fileFormat.constData());