39 void IntelliPhotoGui::slotOpen(){
47 QString fileName = QFileDialog::getOpenFileName(
this,
48 tr(
"Open File"), QDir::currentPath());
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"),
115 void IntelliPhotoGui::slotSetActiveAlpha(){
122 int layer = QInputDialog::getInt(
this, tr(
"Layer to set on"),
126 int alpha = QInputDialog::getInt(
this, tr(
"New Alpha"),
128 255,0, 255, 1, &ok2);
135 void IntelliPhotoGui::slotPositionMoveUp(){
140 void IntelliPhotoGui::slotPositionMoveDown(){
145 void IntelliPhotoGui::slotPositionMoveLeft(){
150 void IntelliPhotoGui::slotPositionMoveRight(){
155 void IntelliPhotoGui::slotMoveLayerUp(){
160 void IntelliPhotoGui::slotMoveLayerDown(){
165 void IntelliPhotoGui::slotClearActiveLayer(){
167 bool ok1, ok2, ok3, ok4;
172 int red = QInputDialog::getInt(
this, tr(
"Red Input"),
176 int green = QInputDialog::getInt(
this, tr(
"Green Input"),
178 255,0, 255, 1, &ok2);
180 int blue = QInputDialog::getInt(
this, tr(
"Blue Input"),
182 255,0, 255, 1, &ok3);
184 int alpha = QInputDialog::getInt(
this, tr(
"Alpha Input"),
186 255,0, 255, 1, &ok4);
187 if (ok1&&ok2&&ok3&&ok4)
189 paintingArea->
floodFill(red, green, blue, alpha);
193 void IntelliPhotoGui::slotSetActiveLayer(){
200 int layer = QInputDialog::getInt(
this, tr(
"Layer to set on"),
209 void IntelliPhotoGui::slotSetFirstColor(){
213 void IntelliPhotoGui::slotSetSecondColor(){
217 void IntelliPhotoGui::slotSwitchColor(){
221 void IntelliPhotoGui::slotCreatePenTool(){
225 void IntelliPhotoGui::slotCreatePlainTool(){
229 void IntelliPhotoGui::slotCreateLineTool(){
234 void IntelliPhotoGui::slotAboutDialog(){
236 QMessageBox::about(
this, tr(
"About Painting"),
237 tr(
"<p><b>IntelliPhoto</b> Some nice ass looking software</p>"));
241 void IntelliPhotoGui::createActions(){
244 foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
245 QString text = tr(
"%1...").arg(QString(format).toUpper());
248 QAction *action =
new QAction(text,
this);
251 action->setData(format);
254 connect(action, SIGNAL(triggered()),
this, SLOT(slotSave()));
257 actionSaveAs.append(action);
261 QAction *pngSaveAction =
new QAction(
"PNG-8",
this);
262 pngSaveAction->setData(
"PNG");
264 connect(pngSaveAction, SIGNAL(triggered()),
this, SLOT(slotSave()));
266 actionSaveAs.append(pngSaveAction);
269 actionExit =
new QAction(tr(
"&Exit"),
this);
270 actionExit->setShortcuts(QKeySequence::Quit);
271 connect(actionExit, SIGNAL(triggered()),
this, SLOT(close()));
273 actionOpen =
new QAction(tr(
"&Open"),
this);
274 actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
275 connect(actionOpen, SIGNAL(triggered()),
this, SLOT(slotOpen()));
278 actionCreateNewLayer =
new QAction(tr(
"&New Layer..."),
this);
279 connect(actionCreateNewLayer, SIGNAL(triggered()),
this, SLOT(slotCreateNewLayer()));
282 actionDeleteLayer =
new QAction(tr(
"&Delete Layer..."),
this);
283 connect(actionDeleteLayer, SIGNAL(triggered()),
this, SLOT(slotDeleteLayer()));
285 actionSetActiveLayer =
new QAction(tr(
"&set Active"),
this);
286 connect(actionSetActiveLayer, SIGNAL(triggered()),
this, SLOT(slotSetActiveLayer()));
288 actionSetActiveAlpha =
new QAction(tr(
"&set Alpha"),
this);
289 connect(actionSetActiveAlpha, SIGNAL(triggered()),
this, SLOT(slotSetActiveAlpha()));
291 actionMovePositionUp =
new QAction(tr(
"&move Up"),
this);
292 actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
293 connect(actionMovePositionUp, SIGNAL(triggered()),
this, SLOT(slotPositionMoveUp()));
295 actionMovePositionDown =
new QAction(tr(
"&move Down"),
this);
296 actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
297 connect(actionMovePositionDown, SIGNAL(triggered()),
this, SLOT(slotPositionMoveDown()));
299 actionMovePositionLeft =
new QAction(tr(
"&move Left"),
this);
300 actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
301 connect(actionMovePositionLeft, SIGNAL(triggered()),
this, SLOT(slotPositionMoveLeft()));
303 actionMovePositionRight =
new QAction(tr(
"&move Right"),
this);
304 actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
305 connect(actionMovePositionRight, SIGNAL(triggered()),
this, SLOT(slotPositionMoveRight()));
307 actionMoveLayerUp =
new QAction(tr(
"&move Layer Up"),
this);
308 actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
309 connect(actionMoveLayerUp, SIGNAL(triggered()),
this, SLOT(slotMoveLayerUp()));
311 actionMoveLayerDown=
new QAction(tr(
"&move Layer Down"),
this);
312 actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
313 connect(actionMoveLayerDown, SIGNAL(triggered()),
this, SLOT(slotMoveLayerDown()));
316 actionColorPickerFirstColor =
new QAction(tr(
"&Main"),
this);
317 connect(actionColorPickerFirstColor, SIGNAL(triggered()),
this, SLOT(slotSetFirstColor()));
319 actionColorPickerSecondColor =
new QAction(tr(
"&Secondary"),
this);
320 connect(actionColorPickerSecondColor, SIGNAL(triggered()),
this, SLOT(slotSetFirstColor()));
322 actionColorSwitch =
new QAction(tr(
"&Switch"),
this);
323 actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
324 connect(actionColorSwitch, SIGNAL(triggered()),
this, SLOT(slotSwitchColor()));
327 actionCreatePlainTool =
new QAction(tr(
"&Plain"),
this);
328 connect(actionCreatePlainTool, SIGNAL(triggered()),
this, SLOT(slotCreatePlainTool()));
330 actionCreatePenTool =
new QAction(tr(
"&Pen"),
this);
331 connect(actionCreatePenTool, SIGNAL(triggered()),
this, SLOT(slotCreatePenTool()));
333 actionCreateLineTool =
new QAction(tr(
"&Line"),
this);
334 connect(actionCreateLineTool, SIGNAL(triggered()),
this, SLOT(slotCreateLineTool()));
337 actionAboutDialog =
new QAction(tr(
"&About"),
this);
338 connect(actionAboutDialog, SIGNAL(triggered()),
this, SLOT(slotAboutDialog()));
341 actionAboutQtDialog =
new QAction(tr(
"About &Qt"),
this);
342 connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
346 void IntelliPhotoGui::createMenus(){
348 saveAsMenu =
new QMenu(tr(
"&Save As"),
this);
349 foreach (QAction *action, actionSaveAs)
350 saveAsMenu->addAction(action);
354 fileMenu =
new QMenu(tr(
"&File"),
this);
355 fileMenu->addAction(actionOpen);
356 fileMenu->addMenu(saveAsMenu);
357 fileMenu->addSeparator();
358 fileMenu->addAction(actionExit);
361 optionMenu =
new QMenu(tr(
"&Options"),
this);
362 optionMenu->addAction(actionSetActiveLayer);
363 optionMenu->addAction(actionSetActiveAlpha);
364 optionMenu->addAction(actionMovePositionUp);
365 optionMenu->addAction(actionMovePositionDown);
366 optionMenu->addAction(actionMovePositionLeft);
367 optionMenu->addAction(actionMovePositionRight);
368 optionMenu->addAction(actionMoveLayerUp);
369 optionMenu->addAction(actionMoveLayerDown);
372 layerMenu =
new QMenu(tr(
"&Layer"),
this);
373 layerMenu->addAction(actionCreateNewLayer);
374 layerMenu->addAction(actionDeleteLayer);
377 colorMenu =
new QMenu(tr(
"&Color"),
this);
378 colorMenu->addAction(actionColorPickerFirstColor);
379 colorMenu->addAction(actionColorPickerSecondColor);
380 colorMenu->addAction(actionColorSwitch);
383 toolMenu =
new QMenu(tr(
"&Tools"),
this);
384 toolMenu->addAction(actionCreatePenTool);
385 toolMenu->addAction(actionCreatePlainTool);
386 toolMenu->addAction(actionCreateLineTool);
387 toolMenu->addSeparator();
388 toolMenu->addMenu(colorMenu);
391 helpMenu =
new QMenu(tr(
"&Help"),
this);
392 helpMenu->addAction(actionAboutDialog);
393 helpMenu->addAction(actionAboutQtDialog);
396 menuBar()->addMenu(fileMenu);
397 menuBar()->addMenu(optionMenu);
398 menuBar()->addMenu(layerMenu);
399 menuBar()->addMenu(toolMenu);
400 menuBar()->addMenu(helpMenu);
403 void IntelliPhotoGui::createGui(){
405 centralGuiWidget =
new QWidget(
this);
406 setCentralWidget(centralGuiWidget);
409 mainLayout =
new QGridLayout(centralGuiWidget);
410 centralGuiWidget->setLayout(mainLayout);
416 mainLayout->addWidget(paintingArea);
419 void IntelliPhotoGui::setIntelliStyle(){
421 setWindowTitle(
"IntelliPhoto Prototype");
423 this->setStyleSheet(
"background-color:rgb(64,64,64)");
424 this->centralGuiWidget->setStyleSheet(
"color:rgb(255,255,255)");
425 this->menuBar()->setStyleSheet(
"color:rgb(255,255,255)");
428 bool IntelliPhotoGui::maybeSave(){
433 QMessageBox::StandardButton ret;
437 ret = QMessageBox::warning(
this, tr(
"Painting"),
438 tr(
"The image has been modified.\n"
439 "Do you want to save your changes?"),
440 QMessageBox::Save | QMessageBox::Discard
441 | QMessageBox::Cancel);
444 if (ret == QMessageBox::Save) {
445 return saveFile(
"png");
448 }
else if (ret == QMessageBox::Cancel) {
455 bool IntelliPhotoGui::saveFile(
const QByteArray &fileFormat){
457 QString initialPath = QDir::currentPath() +
"/untitled." + fileFormat;
461 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save As"),
463 tr(
"%1 Files (*.%2);;All Files (*)")
464 .arg(QString::fromLatin1(fileFormat.toUpper()))
465 .arg(QString::fromLatin1(fileFormat)));
468 if (fileName.isEmpty()) {
472 return paintingArea->
save(fileName, fileFormat.constData());