37 void IntelliPhotoGui::slotOpen(){
45 QString fileName = QFileDialog::getOpenFileName(
this,
46 tr(
"Open File"), QDir::currentPath(),
nullptr,
nullptr, QFileDialog::DontUseNativeDialog);
50 if (!fileName.isEmpty())
51 paintingArea->
open(fileName);
56 void IntelliPhotoGui::slotSave(){
58 QAction *action = qobject_cast<QAction *>(sender());
61 QByteArray fileFormat = action->data().toByteArray();
68 void IntelliPhotoGui::slotCreateNewLayer(){
75 int width = QInputDialog::getInt(
this, tr(
"New Layer"),
78 int height = QInputDialog::getInt(
this, tr(
"New Layer"),
84 int layer = paintingArea->
addLayer(width,height,0,0);
90 void IntelliPhotoGui::slotDeleteLayer(){
97 int layerNumber = QInputDialog::getInt(
this, tr(
"delete Layer"),
113 void IntelliPhotoGui::slotSetActiveAlpha(){
120 int layer = QInputDialog::getInt(
this, tr(
"Layer to set on"),
124 int alpha = QInputDialog::getInt(
this, tr(
"New Alpha"),
126 255,0, 255, 1, &ok2);
133 void IntelliPhotoGui::slotPositionMoveUp(){
138 void IntelliPhotoGui::slotPositionMoveDown(){
143 void IntelliPhotoGui::slotPositionMoveLeft(){
148 void IntelliPhotoGui::slotPositionMoveRight(){
153 void IntelliPhotoGui::slotMoveLayerUp(){
158 void IntelliPhotoGui::slotMoveLayerDown(){
163 void IntelliPhotoGui::slotClearActiveLayer(){
165 bool ok1, ok2, ok3, ok4;
170 int red = QInputDialog::getInt(
this, tr(
"Red Input"),
174 int green = QInputDialog::getInt(
this, tr(
"Green Input"),
176 255,0, 255, 1, &ok2);
178 int blue = QInputDialog::getInt(
this, tr(
"Blue Input"),
180 255,0, 255, 1, &ok3);
182 int alpha = QInputDialog::getInt(
this, tr(
"Alpha Input"),
184 255,0, 255, 1, &ok4);
185 if (ok1&&ok2&&ok3&&ok4)
187 paintingArea->
floodFill(red, green, blue, alpha);
191 void IntelliPhotoGui::slotSetActiveLayer(){
198 int layer = QInputDialog::getInt(
this, tr(
"Layer to set on"),
207 void IntelliPhotoGui::slotSetFirstColor(){
211 void IntelliPhotoGui::slotSetSecondColor(){
215 void IntelliPhotoGui::slotSwitchColor(){
219 void IntelliPhotoGui::slotCreatePenTool(){
223 void IntelliPhotoGui::slotCreatePlainTool(){
227 void IntelliPhotoGui::slotCreateLineTool(){
232 void IntelliPhotoGui::slotAboutDialog(){
234 QMessageBox::about(
this, tr(
"About Painting"),
235 tr(
"<p><b>IntelliPhoto</b>Pretty basic editor.</p>"));
239 void IntelliPhotoGui::createActions(){
242 foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
243 QString text = tr(
"%1...").arg(QString(format).toUpper());
246 QAction *action =
new QAction(text,
this);
249 action->setData(format);
252 connect(action, SIGNAL(triggered()),
this, SLOT(slotSave()));
255 actionSaveAs.append(action);
259 QAction *pngSaveAction =
new QAction(
"PNG-8",
this);
260 pngSaveAction->setData(
"PNG");
262 connect(pngSaveAction, SIGNAL(triggered()),
this, SLOT(slotSave()));
264 actionSaveAs.append(pngSaveAction);
267 actionExit =
new QAction(tr(
"&Exit"),
this);
268 actionExit->setShortcuts(QKeySequence::Quit);
269 connect(actionExit, SIGNAL(triggered()),
this, SLOT(close()));
271 actionOpen =
new QAction(tr(
"&Open"),
this);
272 actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
273 connect(actionOpen, SIGNAL(triggered()),
this, SLOT(slotOpen()));
276 actionCreateNewLayer =
new QAction(tr(
"&New Layer..."),
this);
277 actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
278 connect(actionCreateNewLayer, SIGNAL(triggered()),
this, SLOT(slotCreateNewLayer()));
281 actionDeleteLayer =
new QAction(tr(
"&Delete Layer..."),
this);
282 connect(actionDeleteLayer, SIGNAL(triggered()),
this, SLOT(slotDeleteLayer()));
284 actionSetActiveLayer =
new QAction(tr(
"&set Active"),
this);
285 connect(actionSetActiveLayer, SIGNAL(triggered()),
this, SLOT(slotSetActiveLayer()));
287 actionSetActiveAlpha =
new QAction(tr(
"&set Alpha"),
this);
288 connect(actionSetActiveAlpha, SIGNAL(triggered()),
this, SLOT(slotSetActiveAlpha()));
290 actionMovePositionUp =
new QAction(tr(
"&move Up"),
this);
291 actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
292 connect(actionMovePositionUp, SIGNAL(triggered()),
this, SLOT(slotPositionMoveUp()));
294 actionMovePositionDown =
new QAction(tr(
"&move Down"),
this);
295 actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
296 connect(actionMovePositionDown, SIGNAL(triggered()),
this, SLOT(slotPositionMoveDown()));
298 actionMovePositionLeft =
new QAction(tr(
"&move Left"),
this);
299 actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
300 connect(actionMovePositionLeft, SIGNAL(triggered()),
this, SLOT(slotPositionMoveLeft()));
302 actionMovePositionRight =
new QAction(tr(
"&move Right"),
this);
303 actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
304 connect(actionMovePositionRight, SIGNAL(triggered()),
this, SLOT(slotPositionMoveRight()));
306 actionMoveLayerUp =
new QAction(tr(
"&move Layer Up"),
this);
307 actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
308 connect(actionMoveLayerUp, SIGNAL(triggered()),
this, SLOT(slotMoveLayerUp()));
310 actionMoveLayerDown=
new QAction(tr(
"&move Layer Down"),
this);
311 actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
312 connect(actionMoveLayerDown, SIGNAL(triggered()),
this, SLOT(slotMoveLayerDown()));
315 actionColorPickerFirstColor =
new QAction(tr(
"&Main"),
this);
316 connect(actionColorPickerFirstColor, SIGNAL(triggered()),
this, SLOT(slotSetFirstColor()));
318 actionColorPickerSecondColor =
new QAction(tr(
"&Secondary"),
this);
319 connect(actionColorPickerSecondColor, SIGNAL(triggered()),
this, SLOT(slotSetSecondColor()));
321 actionColorSwitch =
new QAction(tr(
"&Switch"),
this);
322 actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
323 connect(actionColorSwitch, SIGNAL(triggered()),
this, SLOT(slotSwitchColor()));
326 actionCreatePlainTool =
new QAction(tr(
"&Plain"),
this);
327 connect(actionCreatePlainTool, SIGNAL(triggered()),
this, SLOT(slotCreatePlainTool()));
329 actionCreatePenTool =
new QAction(tr(
"&Pen"),
this);
330 connect(actionCreatePenTool, SIGNAL(triggered()),
this, SLOT(slotCreatePenTool()));
332 actionCreateLineTool =
new QAction(tr(
"&Line"),
this);
333 connect(actionCreateLineTool, SIGNAL(triggered()),
this, SLOT(slotCreateLineTool()));
336 actionAboutDialog =
new QAction(tr(
"&About"),
this);
337 connect(actionAboutDialog, SIGNAL(triggered()),
this, SLOT(slotAboutDialog()));
340 actionAboutQtDialog =
new QAction(tr(
"About &Qt"),
this);
341 connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
345 void IntelliPhotoGui::createMenus(){
347 saveAsMenu =
new QMenu(tr(
"&Save As"),
this);
348 foreach (QAction *action, actionSaveAs)
349 saveAsMenu->addAction(action);
353 fileMenu =
new QMenu(tr(
"&File"),
this);
354 fileMenu->addAction(actionOpen);
355 fileMenu->addMenu(saveAsMenu);
356 fileMenu->addSeparator();
357 fileMenu->addAction(actionExit);
360 optionMenu =
new QMenu(tr(
"&Options"),
this);
361 optionMenu->addAction(actionSetActiveLayer);
362 optionMenu->addAction(actionSetActiveAlpha);
363 optionMenu->addAction(actionMovePositionUp);
364 optionMenu->addAction(actionMovePositionDown);
365 optionMenu->addAction(actionMovePositionLeft);
366 optionMenu->addAction(actionMovePositionRight);
367 optionMenu->addAction(actionMoveLayerUp);
368 optionMenu->addAction(actionMoveLayerDown);
371 layerMenu =
new QMenu(tr(
"&Layer"),
this);
372 layerMenu->addAction(actionCreateNewLayer);
373 layerMenu->addAction(actionDeleteLayer);
376 colorMenu =
new QMenu(tr(
"&Color"),
this);
377 colorMenu->addAction(actionColorPickerFirstColor);
378 colorMenu->addAction(actionColorPickerSecondColor);
379 colorMenu->addAction(actionColorSwitch);
382 toolMenu =
new QMenu(tr(
"&Tools"),
this);
383 toolMenu->addAction(actionCreatePenTool);
384 toolMenu->addAction(actionCreatePlainTool);
385 toolMenu->addAction(actionCreateLineTool);
386 toolMenu->addSeparator();
387 toolMenu->addMenu(colorMenu);
390 helpMenu =
new QMenu(tr(
"&Help"),
this);
391 helpMenu->addAction(actionAboutDialog);
392 helpMenu->addAction(actionAboutQtDialog);
395 menuBar()->addMenu(fileMenu);
396 menuBar()->addMenu(optionMenu);
397 menuBar()->addMenu(layerMenu);
398 menuBar()->addMenu(toolMenu);
399 menuBar()->addMenu(helpMenu);
402 void IntelliPhotoGui::createGui(){
404 centralGuiWidget =
new QWidget(
this);
405 setCentralWidget(centralGuiWidget);
408 mainLayout =
new QGridLayout(centralGuiWidget);
409 centralGuiWidget->setLayout(mainLayout);
415 mainLayout->addWidget(paintingArea);
418 void IntelliPhotoGui::setIntelliStyle(){
420 setWindowTitle(
"IntelliPhoto Prototype");
422 this->setStyleSheet(
"background-color:rgb(64,64,64)");
423 this->centralGuiWidget->setStyleSheet(
"color:rgb(255,255,255)");
424 this->menuBar()->setStyleSheet(
"color:rgb(255,255,255)");
427 bool IntelliPhotoGui::maybeSave(){
432 QMessageBox::StandardButton ret;
436 ret = QMessageBox::warning(
this, tr(
"Painting"),
437 tr(
"The image has been modified.\n"
438 "Do you want to save your changes?"),
439 QMessageBox::Save | QMessageBox::Discard
440 | QMessageBox::Cancel);
443 if (ret == QMessageBox::Save) {
444 return saveFile(
"png");
447 }
else if (ret == QMessageBox::Cancel) {
454 bool IntelliPhotoGui::saveFile(
const QByteArray &fileFormat){
456 QString initialPath = QDir::currentPath() +
"/untitled." + fileFormat;
460 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save As"),
462 tr(
"%1 Files (*.%2);;All Files (*)")
463 .arg(QString::fromLatin1(fileFormat.toUpper()))
464 .arg(QString::fromLatin1(fileFormat)),
nullptr, QFileDialog::DontUseNativeDialog);
467 if (fileName.isEmpty()) {
471 return paintingArea->
save(fileName, fileFormat.constData());