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(){
226 void IntelliPhotoGui::slotAboutDialog(){
228 QMessageBox::about(
this, tr(
"About Painting"),
229 tr(
"<p><b>IntelliPhoto</b>Pretty basic editor.</p>"));
233 void IntelliPhotoGui::createActions(){
236 foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
237 QString text = tr(
"%1...").arg(QString(format).toUpper());
240 QAction*action =
new QAction(text,
this);
243 action->setData(format);
246 connect(action, SIGNAL(triggered()),
this, SLOT(slotSave()));
249 actionSaveAs.append(action);
253 QAction*pngSaveAction =
new QAction(
"PNG-8",
this);
254 pngSaveAction->setData(
"PNG");
256 connect(pngSaveAction, SIGNAL(triggered()),
this, SLOT(slotSave()));
258 actionSaveAs.append(pngSaveAction);
261 actionExit =
new QAction(tr(
"&Exit"),
this);
262 actionExit->setShortcuts(QKeySequence::Quit);
263 connect(actionExit, SIGNAL(triggered()),
this, SLOT(close()));
265 actionOpen =
new QAction(tr(
"&Open"),
this);
266 actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
267 connect(actionOpen, SIGNAL(triggered()),
this, SLOT(slotOpen()));
270 actionCreateNewLayer =
new QAction(tr(
"&New Layer..."),
this);
271 actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
272 connect(actionCreateNewLayer, SIGNAL(triggered()),
this, SLOT(slotCreateNewLayer()));
275 actionDeleteLayer =
new QAction(tr(
"&Delete Layer..."),
this);
276 connect(actionDeleteLayer, SIGNAL(triggered()),
this, SLOT(slotDeleteLayer()));
278 actionSetActiveLayer =
new QAction(tr(
"&set Active"),
this);
279 connect(actionSetActiveLayer, SIGNAL(triggered()),
this, SLOT(slotSetActiveLayer()));
281 actionSetActiveAlpha =
new QAction(tr(
"&set Alpha"),
this);
282 connect(actionSetActiveAlpha, SIGNAL(triggered()),
this, SLOT(slotSetActiveAlpha()));
284 actionMovePositionUp =
new QAction(tr(
"&move Up"),
this);
285 actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
286 connect(actionMovePositionUp, SIGNAL(triggered()),
this, SLOT(slotPositionMoveUp()));
288 actionMovePositionDown =
new QAction(tr(
"&move Down"),
this);
289 actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
290 connect(actionMovePositionDown, SIGNAL(triggered()),
this, SLOT(slotPositionMoveDown()));
292 actionMovePositionLeft =
new QAction(tr(
"&move Left"),
this);
293 actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
294 connect(actionMovePositionLeft, SIGNAL(triggered()),
this, SLOT(slotPositionMoveLeft()));
296 actionMovePositionRight =
new QAction(tr(
"&move Right"),
this);
297 actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
298 connect(actionMovePositionRight, SIGNAL(triggered()),
this, SLOT(slotPositionMoveRight()));
300 actionMoveLayerUp =
new QAction(tr(
"&move Layer Up"),
this);
301 actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
302 connect(actionMoveLayerUp, SIGNAL(triggered()),
this, SLOT(slotMoveLayerUp()));
304 actionMoveLayerDown=
new QAction(tr(
"&move Layer Down"),
this);
305 actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
306 connect(actionMoveLayerDown, SIGNAL(triggered()),
this, SLOT(slotMoveLayerDown()));
309 actionColorPickerFirstColor =
new QAction(tr(
"&Main"),
this);
310 connect(actionColorPickerFirstColor, SIGNAL(triggered()),
this, SLOT(slotSetFirstColor()));
312 actionColorPickerSecondColor =
new QAction(tr(
"&Secondary"),
this);
313 connect(actionColorPickerSecondColor, SIGNAL(triggered()),
this, SLOT(slotSetSecondColor()));
315 actionColorSwitch =
new QAction(tr(
"&Switch"),
this);
316 actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
317 connect(actionColorSwitch, SIGNAL(triggered()),
this, SLOT(slotSwitchColor()));
320 actionCreatePlainTool =
new QAction(tr(
"&Plain"),
this);
321 connect(actionCreatePlainTool, SIGNAL(triggered()),
this, SLOT(slotCreatePlainTool()));
323 actionCreatePenTool =
new QAction(tr(
"&Pen"),
this);
324 connect(actionCreatePenTool, SIGNAL(triggered()),
this, SLOT(slotCreatePenTool()));
326 actionCreateLineTool =
new QAction(tr(
"&Line"),
this);
327 connect(actionCreateLineTool, SIGNAL(triggered()),
this, SLOT(slotCreateLineTool()));
330 actionAboutDialog =
new QAction(tr(
"&About"),
this);
331 connect(actionAboutDialog, SIGNAL(triggered()),
this, SLOT(slotAboutDialog()));
334 actionAboutQtDialog =
new QAction(tr(
"About &Qt"),
this);
335 connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
339 void IntelliPhotoGui::createMenus(){
341 saveAsMenu =
new QMenu(tr(
"&Save As"),
this);
342 foreach (QAction *action, actionSaveAs)
343 saveAsMenu->addAction(action);
347 fileMenu =
new QMenu(tr(
"&File"),
this);
348 fileMenu->addAction(actionOpen);
349 fileMenu->addMenu(saveAsMenu);
350 fileMenu->addSeparator();
351 fileMenu->addAction(actionExit);
354 optionMenu =
new QMenu(tr(
"&Options"),
this);
355 optionMenu->addAction(actionSetActiveLayer);
356 optionMenu->addAction(actionSetActiveAlpha);
357 optionMenu->addAction(actionMovePositionUp);
358 optionMenu->addAction(actionMovePositionDown);
359 optionMenu->addAction(actionMovePositionLeft);
360 optionMenu->addAction(actionMovePositionRight);
361 optionMenu->addAction(actionMoveLayerUp);
362 optionMenu->addAction(actionMoveLayerDown);
365 layerMenu =
new QMenu(tr(
"&Layer"),
this);
366 layerMenu->addAction(actionCreateNewLayer);
367 layerMenu->addAction(actionDeleteLayer);
370 colorMenu =
new QMenu(tr(
"&Color"),
this);
371 colorMenu->addAction(actionColorPickerFirstColor);
372 colorMenu->addAction(actionColorPickerSecondColor);
373 colorMenu->addAction(actionColorSwitch);
376 toolMenu =
new QMenu(tr(
"&Tools"),
this);
377 toolMenu->addAction(actionCreatePenTool);
378 toolMenu->addAction(actionCreatePlainTool);
379 toolMenu->addAction(actionCreateLineTool);
380 toolMenu->addSeparator();
381 toolMenu->addMenu(colorMenu);
384 helpMenu =
new QMenu(tr(
"&Help"),
this);
385 helpMenu->addAction(actionAboutDialog);
386 helpMenu->addAction(actionAboutQtDialog);
389 menuBar()->addMenu(fileMenu);
390 menuBar()->addMenu(optionMenu);
391 menuBar()->addMenu(layerMenu);
392 menuBar()->addMenu(toolMenu);
393 menuBar()->addMenu(helpMenu);
396 void IntelliPhotoGui::createGui(){
398 centralGuiWidget =
new QWidget(
this);
399 setCentralWidget(centralGuiWidget);
402 mainLayout =
new QGridLayout(centralGuiWidget);
403 centralGuiWidget->setLayout(mainLayout);
409 mainLayout->addWidget(paintingArea);
412 void IntelliPhotoGui::setIntelliStyle(){
414 setWindowTitle(
"IntelliPhoto Prototype");
416 this->setStyleSheet(
"background-color:rgb(64,64,64)");
417 this->centralGuiWidget->setStyleSheet(
"color:rgb(255,255,255)");
418 this->menuBar()->setStyleSheet(
"color:rgb(255,255,255)");
421 bool IntelliPhotoGui::maybeSave(){
426 QMessageBox::StandardButton ret;
430 ret = QMessageBox::warning(
this, tr(
"Painting"),
431 tr(
"The image has been modified.\n"
432 "Do you want to save your changes?"),
433 QMessageBox::Save | QMessageBox::Discard
434 | QMessageBox::Cancel);
437 if (ret == QMessageBox::Save) {
438 return saveFile(
"png");
441 }
else if (ret == QMessageBox::Cancel) {
448 bool IntelliPhotoGui::saveFile(
const QByteArray &fileFormat){
450 QString initialPath = QDir::currentPath() +
"/untitled." + fileFormat;
454 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save As"),
456 tr(
"%1 Files (*.%2);;All Files (*)")
457 .arg(QString::fromLatin1(fileFormat.toUpper()))
458 .arg(QString::fromLatin1(fileFormat)),
nullptr, QFileDialog::DontUseNativeDialog);
461 if (fileName.isEmpty()) {
465 return paintingArea->
save(fileName, fileFormat.constData());