mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-14 12:20:32 +02:00
Merge branch 'dev' into dev-docs
This commit is contained in:
@@ -8,466 +8,460 @@
|
|||||||
|
|
||||||
// IntelliPhotoGui constructor
|
// IntelliPhotoGui constructor
|
||||||
IntelliPhotoGui::IntelliPhotoGui(){
|
IntelliPhotoGui::IntelliPhotoGui(){
|
||||||
// create Gui elements and lay them out
|
// create Gui elements and lay them out
|
||||||
createGui();
|
createGui();
|
||||||
// Create actions
|
// Create actions
|
||||||
createActions();
|
createActions();
|
||||||
// create Menus
|
// create Menus
|
||||||
createMenus();
|
createMenus();
|
||||||
// set style of the gui
|
// set style of the gui
|
||||||
setIntelliStyle();
|
setIntelliStyle();
|
||||||
// Size the app
|
// Size the app
|
||||||
showMaximized();
|
resize(600,600);
|
||||||
|
showMaximized();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// User tried to close the app
|
// User tried to close the app
|
||||||
void IntelliPhotoGui::closeEvent(QCloseEvent *event){
|
void IntelliPhotoGui::closeEvent(QCloseEvent*event){
|
||||||
// If they try to close maybeSave() returns true
|
// If they try to close maybeSave() returns true
|
||||||
// if no changes have been made and the app closes
|
// if no changes have been made and the app closes
|
||||||
if (maybeSave()) {
|
if (maybeSave()) {
|
||||||
event->accept();
|
event->accept();
|
||||||
} else {
|
} else {
|
||||||
// If there have been changes ignore the event
|
// If there have been changes ignore the event
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the current image has been changed and then
|
// Check if the current image has been changed and then
|
||||||
// open a dialog to open a file
|
// open a dialog to open a file
|
||||||
void IntelliPhotoGui::slotOpen(){
|
void IntelliPhotoGui::slotOpen(){
|
||||||
// Check if changes have been made since last save
|
// Check if changes have been made since last save
|
||||||
// maybeSave() returns true if no changes have been made
|
// maybeSave() returns true if no changes have been made
|
||||||
if (maybeSave()) {
|
if (maybeSave()) {
|
||||||
|
|
||||||
// Get the file to open from a dialog
|
// Get the file to open from a dialog
|
||||||
// tr sets the window title to Open File
|
// tr sets the window title to Open File
|
||||||
// QDir opens the current dirctory
|
// QDir opens the current dirctory
|
||||||
QString fileName = QFileDialog::getOpenFileName(this,
|
QString fileName = QFileDialog::getOpenFileName(this,
|
||||||
tr("Open File"), QDir::currentPath(), nullptr, nullptr, QFileDialog::DontUseNativeDialog);
|
tr("Open File"), QDir::currentPath(), nullptr, nullptr, QFileDialog::DontUseNativeDialog);
|
||||||
|
|
||||||
// If we have a file name load the image and place
|
// If we have a file name load the image and place
|
||||||
// it in the paintingArea
|
// it in the paintingArea
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
paintingArea->open(fileName);
|
paintingArea->open(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the user clicks Save As in the menu
|
// Called when the user clicks Save As in the menu
|
||||||
void IntelliPhotoGui::slotSave(){
|
void IntelliPhotoGui::slotSave(){
|
||||||
// A QAction represents the action of the user clicking
|
// A QAction represents the action of the user clicking
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction*action = qobject_cast<QAction*>(sender());
|
||||||
|
|
||||||
// Stores the array of bytes of the users data
|
// Stores the array of bytes of the users data
|
||||||
QByteArray fileFormat = action->data().toByteArray();
|
QByteArray fileFormat = action->data().toByteArray();
|
||||||
|
|
||||||
// Pass it to be saved
|
// Pass it to be saved
|
||||||
saveFile(fileFormat);
|
saveFile(fileFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opens a dialog that allows the user to create a New Layer
|
// Opens a dialog that allows the user to create a New Layer
|
||||||
void IntelliPhotoGui::slotCreateNewLayer(){
|
void IntelliPhotoGui::slotCreateNewLayer(){
|
||||||
// Stores button value
|
// Stores button value
|
||||||
bool ok1, ok2;
|
bool ok1, ok2;
|
||||||
|
|
||||||
// "New Layer" is the title of the window
|
// "New Layer" is the title of the window
|
||||||
// the next tr is the text to display
|
// the next tr is the text to display
|
||||||
// Define the standard Value, min, max, step and ok button
|
// Define the standard Value, min, max, step and ok button
|
||||||
int width = QInputDialog::getInt(this, tr("New Layer"),
|
int width = QInputDialog::getInt(this, tr("New Layer"),
|
||||||
tr("Width:"),
|
tr("Width:"),
|
||||||
200,1, 500, 1, &ok1);
|
200,1, 500, 1, &ok1);
|
||||||
int height = QInputDialog::getInt(this, tr("New Layer"),
|
int height = QInputDialog::getInt(this, tr("New Layer"),
|
||||||
tr("Height:"),
|
tr("Height:"),
|
||||||
200,1, 500, 1, &ok2);
|
200,1, 500, 1, &ok2);
|
||||||
// Create New Layer
|
// Create New Layer
|
||||||
if (ok1&&ok2)
|
if (ok1&&ok2)
|
||||||
{
|
{
|
||||||
int layer = paintingArea->addLayer(width,height,0,0);
|
int layer = paintingArea->addLayer(width,height,0,0);
|
||||||
paintingArea->slotActivateLayer(layer);
|
paintingArea->slotActivateLayer(layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opens a dialog that allows the user to delete a Layer
|
// Opens a dialog that allows the user to delete a Layer
|
||||||
void IntelliPhotoGui::slotDeleteLayer(){
|
void IntelliPhotoGui::slotDeleteLayer(){
|
||||||
// Stores button value
|
// Stores button value
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
// "delete Layer" is the title of the window
|
|
||||||
// the next tr is the text to display
|
|
||||||
// Define the standard Value, min, max, step and ok button
|
|
||||||
int layerNumber = QInputDialog::getInt(this, tr("delete Layer"),
|
|
||||||
tr("Number:"),
|
|
||||||
1,0, 500, 1, &ok);
|
|
||||||
// Create New Layer
|
|
||||||
if (ok)
|
|
||||||
paintingArea->deleteLayer(layerNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
void slotCreatePenTool(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void slotCreateFloodFillTool(){
|
|
||||||
|
|
||||||
|
// "delete Layer" is the title of the window
|
||||||
|
// the next tr is the text to display
|
||||||
|
// Define the standard Value, min, max, step and ok button
|
||||||
|
int layerNumber = QInputDialog::getInt(this, tr("delete Layer"),
|
||||||
|
tr("Number:"),
|
||||||
|
1,0, 500, 1, &ok);
|
||||||
|
// Create New Layer
|
||||||
|
if (ok)
|
||||||
|
paintingArea->deleteLayer(layerNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotSetActiveAlpha(){
|
void IntelliPhotoGui::slotSetActiveAlpha(){
|
||||||
// Stores button value
|
// Stores button value
|
||||||
bool ok1, ok2;
|
bool ok1, ok2;
|
||||||
|
|
||||||
// "Layer to set on" is the title of the window
|
// "Layer to set on" is the title of the window
|
||||||
// the next tr is the text to display
|
// the next tr is the text to display
|
||||||
// Define the standard Value, min, max, step and ok button
|
// Define the standard Value, min, max, step and ok button
|
||||||
int layer = QInputDialog::getInt(this, tr("Layer to set on"),
|
int layer = QInputDialog::getInt(this, tr("Layer to set on"),
|
||||||
tr("Layer:"),
|
tr("Layer:"),
|
||||||
-1,-1,100,1, &ok1);
|
-1,-1,100,1, &ok1);
|
||||||
// "New Alpha" is the title of the window
|
// "New Alpha" is the title of the window
|
||||||
int alpha = QInputDialog::getInt(this, tr("New Alpha"),
|
int alpha = QInputDialog::getInt(this, tr("New Alpha"),
|
||||||
tr("Alpha:"),
|
tr("Alpha:"),
|
||||||
255,0, 255, 1, &ok2);
|
255,0, 255, 1, &ok2);
|
||||||
if (ok1&&ok2)
|
if (ok1&&ok2)
|
||||||
{
|
{
|
||||||
paintingArea->setAlphaOfLayer(layer,alpha);
|
paintingArea->setAlphaOfLayer(layer,alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotPositionMoveUp(){
|
void IntelliPhotoGui::slotPositionMoveUp(){
|
||||||
paintingArea->movePositionActive(0,-20);
|
paintingArea->movePositionActive(0,-20);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotPositionMoveDown(){
|
void IntelliPhotoGui::slotPositionMoveDown(){
|
||||||
paintingArea->movePositionActive(0,20);
|
paintingArea->movePositionActive(0,20);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotPositionMoveLeft(){
|
void IntelliPhotoGui::slotPositionMoveLeft(){
|
||||||
paintingArea->movePositionActive(-20,0);
|
paintingArea->movePositionActive(-20,0);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotPositionMoveRight(){
|
void IntelliPhotoGui::slotPositionMoveRight(){
|
||||||
paintingArea->movePositionActive(20,0);
|
paintingArea->movePositionActive(20,0);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotMoveLayerUp(){
|
void IntelliPhotoGui::slotMoveLayerUp(){
|
||||||
paintingArea->moveActiveLayer(1);
|
paintingArea->moveActiveLayer(1);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotMoveLayerDown(){
|
void IntelliPhotoGui::slotMoveLayerDown(){
|
||||||
paintingArea->moveActiveLayer(-1);
|
paintingArea->moveActiveLayer(-1);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotClearActiveLayer(){
|
void IntelliPhotoGui::slotClearActiveLayer(){
|
||||||
// Stores button value
|
// Stores button value
|
||||||
bool ok1, ok2, ok3, ok4;
|
bool ok1, ok2, ok3, ok4;
|
||||||
|
|
||||||
// "Red Input" is the title of the window
|
// "Red Input" is the title of the window
|
||||||
// the next tr is the text to display
|
// the next tr is the text to display
|
||||||
// Define the standard Value, min, max, step and ok button
|
// Define the standard Value, min, max, step and ok button
|
||||||
int red = QInputDialog::getInt(this, tr("Red Input"),
|
int red = QInputDialog::getInt(this, tr("Red Input"),
|
||||||
tr("Red:"),
|
tr("Red:"),
|
||||||
255,0, 255,1, &ok1);
|
255,0, 255,1, &ok1);
|
||||||
// "Green Input" is the title of the window
|
// "Green Input" is the title of the window
|
||||||
int green = QInputDialog::getInt(this, tr("Green Input"),
|
int green = QInputDialog::getInt(this, tr("Green Input"),
|
||||||
tr("Green:"),
|
tr("Green:"),
|
||||||
255,0, 255, 1, &ok2);
|
255,0, 255, 1, &ok2);
|
||||||
// "Blue Input" is the title of the window
|
// "Blue Input" is the title of the window
|
||||||
int blue = QInputDialog::getInt(this, tr("Blue Input"),
|
int blue = QInputDialog::getInt(this, tr("Blue Input"),
|
||||||
tr("Blue:"),
|
tr("Blue:"),
|
||||||
255,0, 255, 1, &ok3);
|
255,0, 255, 1, &ok3);
|
||||||
// "Alpha Input" is the title of the window
|
// "Alpha Input" is the title of the window
|
||||||
int alpha = QInputDialog::getInt(this, tr("Alpha Input"),
|
int alpha = QInputDialog::getInt(this, tr("Alpha Input"),
|
||||||
tr("Alpha:"),
|
tr("Alpha:"),
|
||||||
255,0, 255, 1, &ok4);
|
255,0, 255, 1, &ok4);
|
||||||
if (ok1&&ok2&&ok3&&ok4)
|
if (ok1&&ok2&&ok3&&ok4)
|
||||||
{
|
{
|
||||||
paintingArea->floodFill(red, green, blue, alpha);
|
paintingArea->floodFill(red, green, blue, alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotSetActiveLayer(){
|
void IntelliPhotoGui::slotSetActiveLayer(){
|
||||||
// Stores button value
|
// Stores button value
|
||||||
bool ok1;
|
bool ok1;
|
||||||
|
|
||||||
// "Layer to set on" is the title of the window
|
// "Layer to set on" is the title of the window
|
||||||
// the next tr is the text to display
|
// the next tr is the text to display
|
||||||
// Define the standard Value, min, max, step and ok button
|
// Define the standard Value, min, max, step and ok button
|
||||||
int layer = QInputDialog::getInt(this, tr("Layer to set on"),
|
int layer = QInputDialog::getInt(this, tr("Layer to set on"),
|
||||||
tr("Layer:"),
|
tr("Layer:"),
|
||||||
-1,0,255,1, &ok1);
|
-1,0,255,1, &ok1);
|
||||||
if (ok1)
|
if (ok1)
|
||||||
{
|
{
|
||||||
paintingArea->setLayerToActive(layer);
|
paintingArea->setLayerToActive(layer);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotSetFirstColor(){
|
void IntelliPhotoGui::slotSetFirstColor(){
|
||||||
paintingArea->colorPickerSetFirstColor();
|
paintingArea->colorPickerSetFirstColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotSetSecondColor(){
|
void IntelliPhotoGui::slotSetSecondColor(){
|
||||||
paintingArea->colorPickerSetSecondColor();
|
paintingArea->colorPickerSetSecondColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotSwitchColor(){
|
void IntelliPhotoGui::slotSwitchColor(){
|
||||||
paintingArea->colorPickerSwitchColor();
|
paintingArea->colorPickerSwitchColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotCreatePenTool(){
|
void IntelliPhotoGui::slotCreatePenTool(){
|
||||||
paintingArea->createPenTool();
|
paintingArea->createPenTool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotCreatePlainTool(){
|
void IntelliPhotoGui::slotCreatePlainTool(){
|
||||||
paintingArea->createPlainTool();
|
paintingArea->createPlainTool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotCreateLineTool(){
|
void IntelliPhotoGui::slotCreateLineTool(){
|
||||||
paintingArea->createLineTool();
|
paintingArea->createLineTool();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open an about dialog
|
// Open an about dialog
|
||||||
void IntelliPhotoGui::slotAboutDialog(){
|
void IntelliPhotoGui::slotAboutDialog(){
|
||||||
// Window title and text to display
|
// Window title and text to display
|
||||||
QMessageBox::about(this, tr("About Painting"),
|
QMessageBox::about(this, tr("About Painting"),
|
||||||
tr("<p><b>IntelliPhoto</b>Pretty basic editor.</p>"));
|
tr("<p><b>IntelliPhoto</b>Pretty basic editor.</p>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define menu actions that call functions
|
// Define menu actions that call functions
|
||||||
void IntelliPhotoGui::createActions(){
|
void IntelliPhotoGui::createActions(){
|
||||||
// Get a list of the supported file formats
|
// Get a list of the supported file formats
|
||||||
// QImageWriter is used to write images to files
|
// QImageWriter is used to write images to files
|
||||||
foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
|
foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
|
||||||
QString text = tr("%1...").arg(QString(format).toUpper());
|
QString text = tr("%1...").arg(QString(format).toUpper());
|
||||||
|
|
||||||
// Create an action for each file format
|
// Create an action for each file format
|
||||||
QAction *action = new QAction(text, this);
|
QAction*action = new QAction(text, this);
|
||||||
|
|
||||||
// Set an action for each file format
|
// Set an action for each file format
|
||||||
action->setData(format);
|
action->setData(format);
|
||||||
|
|
||||||
// When clicked call IntelliPhotoGui::save()
|
// When clicked call IntelliPhotoGui::save()
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(slotSave()));
|
connect(action, SIGNAL(triggered()), this, SLOT(slotSave()));
|
||||||
|
|
||||||
// Attach each file format option menu item to Save As
|
// Attach each file format option menu item to Save As
|
||||||
actionSaveAs.append(action);
|
actionSaveAs.append(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set exporter to actions
|
//set exporter to actions
|
||||||
QAction *pngSaveAction = new QAction("PNG-8", this);
|
QAction*pngSaveAction = new QAction("PNG-8", this);
|
||||||
pngSaveAction->setData("PNG");
|
pngSaveAction->setData("PNG");
|
||||||
// When clicked call IntelliPhotoGui::save()
|
// When clicked call IntelliPhotoGui::save()
|
||||||
connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(slotSave()));
|
connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(slotSave()));
|
||||||
// Attach each PNG in save Menu
|
// Attach each PNG in save Menu
|
||||||
actionSaveAs.append(pngSaveAction);
|
actionSaveAs.append(pngSaveAction);
|
||||||
|
|
||||||
// Create exit action and tie to IntelliPhotoGui::close()
|
// Create exit action and tie to IntelliPhotoGui::close()
|
||||||
actionExit = new QAction(tr("&Exit"), this);
|
actionExit = new QAction(tr("&Exit"), this);
|
||||||
actionExit->setShortcuts(QKeySequence::Quit);
|
actionExit->setShortcuts(QKeySequence::Quit);
|
||||||
connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
|
connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
|
|
||||||
actionOpen = new QAction(tr("&Open"), this);
|
actionOpen = new QAction(tr("&Open"), this);
|
||||||
actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
|
actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
|
||||||
connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen()));
|
connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen()));
|
||||||
|
|
||||||
// Create New Layer action and tie to IntelliPhotoGui::newLayer()
|
// Create New Layer action and tie to IntelliPhotoGui::newLayer()
|
||||||
actionCreateNewLayer = new QAction(tr("&New Layer..."), this);
|
actionCreateNewLayer = new QAction(tr("&New Layer..."), this);
|
||||||
actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
||||||
connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer()));
|
connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer()));
|
||||||
|
|
||||||
// Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
|
// Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
|
||||||
actionDeleteLayer = new QAction(tr("&Delete Layer..."), this);
|
actionDeleteLayer = new QAction(tr("&Delete Layer..."), this);
|
||||||
connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer()));
|
connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer()));
|
||||||
|
|
||||||
actionSetActiveLayer = new QAction(tr("&set Active"), this);
|
actionSetActiveLayer = new QAction(tr("&set Active"), this);
|
||||||
connect(actionSetActiveLayer, SIGNAL(triggered()), this, SLOT(slotSetActiveLayer()));
|
connect(actionSetActiveLayer, SIGNAL(triggered()), this, SLOT(slotSetActiveLayer()));
|
||||||
|
|
||||||
actionSetActiveAlpha = new QAction(tr("&set Alpha"), this);
|
actionSetActiveAlpha = new QAction(tr("&set Alpha"), this);
|
||||||
connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha()));
|
connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha()));
|
||||||
|
|
||||||
actionMovePositionUp = new QAction(tr("&move Up"), this);
|
actionMovePositionUp = new QAction(tr("&move Up"), this);
|
||||||
actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
|
actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
|
||||||
connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp()));
|
connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp()));
|
||||||
|
|
||||||
actionMovePositionDown = new QAction(tr("&move Down"), this);
|
actionMovePositionDown = new QAction(tr("&move Down"), this);
|
||||||
actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
|
actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
|
||||||
connect(actionMovePositionDown, SIGNAL(triggered()), this, SLOT(slotPositionMoveDown()));
|
connect(actionMovePositionDown, SIGNAL(triggered()), this, SLOT(slotPositionMoveDown()));
|
||||||
|
|
||||||
actionMovePositionLeft = new QAction(tr("&move Left"), this);
|
actionMovePositionLeft = new QAction(tr("&move Left"), this);
|
||||||
actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
|
actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
|
||||||
connect(actionMovePositionLeft, SIGNAL(triggered()), this, SLOT(slotPositionMoveLeft()));
|
connect(actionMovePositionLeft, SIGNAL(triggered()), this, SLOT(slotPositionMoveLeft()));
|
||||||
|
|
||||||
actionMovePositionRight = new QAction(tr("&move Right"), this);
|
actionMovePositionRight = new QAction(tr("&move Right"), this);
|
||||||
actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
|
actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
|
||||||
connect(actionMovePositionRight, SIGNAL(triggered()), this, SLOT(slotPositionMoveRight()));
|
connect(actionMovePositionRight, SIGNAL(triggered()), this, SLOT(slotPositionMoveRight()));
|
||||||
|
|
||||||
actionMoveLayerUp = new QAction(tr("&move Layer Up"), this);
|
actionMoveLayerUp = new QAction(tr("&move Layer Up"), this);
|
||||||
actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
|
actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
|
||||||
connect(actionMoveLayerUp, SIGNAL(triggered()), this, SLOT(slotMoveLayerUp()));
|
connect(actionMoveLayerUp, SIGNAL(triggered()), this, SLOT(slotMoveLayerUp()));
|
||||||
|
|
||||||
actionMoveLayerDown= new QAction(tr("&move Layer Down"), this);
|
actionMoveLayerDown= new QAction(tr("&move Layer Down"), this);
|
||||||
actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
|
actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
|
||||||
connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown()));
|
connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown()));
|
||||||
|
|
||||||
//Create Color Actions here
|
//Create Color Actions here
|
||||||
actionColorPickerFirstColor = new QAction(tr("&Main"), this);
|
actionColorPickerFirstColor = new QAction(tr("&Main"), this);
|
||||||
connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor()));
|
connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor()));
|
||||||
|
|
||||||
actionColorPickerSecondColor = new QAction(tr("&Secondary"), this);
|
actionColorPickerSecondColor = new QAction(tr("&Secondary"), this);
|
||||||
connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetSecondColor()));
|
connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetSecondColor()));
|
||||||
|
|
||||||
actionColorSwitch = new QAction(tr("&Switch"), this);
|
actionColorSwitch = new QAction(tr("&Switch"), this);
|
||||||
actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
|
actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
|
||||||
connect(actionColorSwitch, SIGNAL(triggered()), this, SLOT(slotSwitchColor()));
|
connect(actionColorSwitch, SIGNAL(triggered()), this, SLOT(slotSwitchColor()));
|
||||||
|
|
||||||
//Create Tool actions down here
|
//Create Tool actions down here
|
||||||
actionCreatePlainTool = new QAction(tr("&Plain"), this);
|
actionCreatePlainTool = new QAction(tr("&Plain"), this);
|
||||||
connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotCreatePlainTool()));
|
connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotCreatePlainTool()));
|
||||||
|
|
||||||
actionCreatePenTool = new QAction(tr("&Pen"),this);
|
actionCreatePenTool = new QAction(tr("&Pen"),this);
|
||||||
connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool()));
|
connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool()));
|
||||||
|
|
||||||
actionCreateLineTool = new QAction(tr("&Line"), this);
|
actionCreateLineTool = new QAction(tr("&Line"), this);
|
||||||
connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool()));
|
connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool()));
|
||||||
|
|
||||||
// Create about action and tie to IntelliPhotoGui::about()
|
// Create about action and tie to IntelliPhotoGui::about()
|
||||||
actionAboutDialog = new QAction(tr("&About"), this);
|
actionAboutDialog = new QAction(tr("&About"), this);
|
||||||
connect(actionAboutDialog, SIGNAL(triggered()), this, SLOT(slotAboutDialog()));
|
connect(actionAboutDialog, SIGNAL(triggered()), this, SLOT(slotAboutDialog()));
|
||||||
|
|
||||||
// Create about Qt action and tie to IntelliPhotoGui::aboutQt()
|
// Create about Qt action and tie to IntelliPhotoGui::aboutQt()
|
||||||
actionAboutQtDialog = new QAction(tr("About &Qt"), this);
|
actionAboutQtDialog = new QAction(tr("About &Qt"), this);
|
||||||
connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the menubar
|
// Create the menubar
|
||||||
void IntelliPhotoGui::createMenus(){
|
void IntelliPhotoGui::createMenus(){
|
||||||
// Create Save As option and the list of file types
|
// Create Save As option and the list of file types
|
||||||
saveAsMenu = new QMenu(tr("&Save As"), this);
|
saveAsMenu = new QMenu(tr("&Save As"), this);
|
||||||
foreach (QAction *action, actionSaveAs)
|
foreach (QAction *action, actionSaveAs)
|
||||||
saveAsMenu->addAction(action);
|
saveAsMenu->addAction(action);
|
||||||
|
|
||||||
|
|
||||||
// Attach all actions to File
|
// Attach all actions to File
|
||||||
fileMenu = new QMenu(tr("&File"), this);
|
fileMenu = new QMenu(tr("&File"), this);
|
||||||
fileMenu->addAction(actionOpen);
|
fileMenu->addAction(actionOpen);
|
||||||
fileMenu->addMenu(saveAsMenu);
|
fileMenu->addMenu(saveAsMenu);
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
fileMenu->addAction(actionExit);
|
fileMenu->addAction(actionExit);
|
||||||
|
|
||||||
// Attach all actions to Options
|
// Attach all actions to Options
|
||||||
optionMenu = new QMenu(tr("&Options"), this);
|
optionMenu = new QMenu(tr("&Options"), this);
|
||||||
optionMenu->addAction(actionSetActiveLayer);
|
optionMenu->addAction(actionSetActiveLayer);
|
||||||
optionMenu->addAction(actionSetActiveAlpha);
|
optionMenu->addAction(actionSetActiveAlpha);
|
||||||
optionMenu->addAction(actionMovePositionUp);
|
optionMenu->addAction(actionMovePositionUp);
|
||||||
optionMenu->addAction(actionMovePositionDown);
|
optionMenu->addAction(actionMovePositionDown);
|
||||||
optionMenu->addAction(actionMovePositionLeft);
|
optionMenu->addAction(actionMovePositionLeft);
|
||||||
optionMenu->addAction(actionMovePositionRight);
|
optionMenu->addAction(actionMovePositionRight);
|
||||||
optionMenu->addAction(actionMoveLayerUp);
|
optionMenu->addAction(actionMoveLayerUp);
|
||||||
optionMenu->addAction(actionMoveLayerDown);
|
optionMenu->addAction(actionMoveLayerDown);
|
||||||
|
|
||||||
// Attach all actions to Layer
|
// Attach all actions to Layer
|
||||||
layerMenu = new QMenu(tr("&Layer"), this);
|
layerMenu = new QMenu(tr("&Layer"), this);
|
||||||
layerMenu->addAction(actionCreateNewLayer);
|
layerMenu->addAction(actionCreateNewLayer);
|
||||||
layerMenu->addAction(actionDeleteLayer);
|
layerMenu->addAction(actionDeleteLayer);
|
||||||
|
|
||||||
//Attach all Color Options
|
//Attach all Color Options
|
||||||
colorMenu = new QMenu(tr("&Color"), this);
|
colorMenu = new QMenu(tr("&Color"), this);
|
||||||
colorMenu->addAction(actionColorPickerFirstColor);
|
colorMenu->addAction(actionColorPickerFirstColor);
|
||||||
colorMenu->addAction(actionColorPickerSecondColor);
|
colorMenu->addAction(actionColorPickerSecondColor);
|
||||||
colorMenu->addAction(actionColorSwitch);
|
colorMenu->addAction(actionColorSwitch);
|
||||||
|
|
||||||
//Attach all Tool Options
|
//Attach all Tool Options
|
||||||
toolMenu = new QMenu(tr("&Tools"), this);
|
toolMenu = new QMenu(tr("&Tools"), this);
|
||||||
toolMenu->addAction(actionCreatePenTool);
|
toolMenu->addAction(actionCreatePenTool);
|
||||||
toolMenu->addAction(actionCreatePlainTool);
|
toolMenu->addAction(actionCreatePlainTool);
|
||||||
toolMenu->addAction(actionCreateLineTool);
|
toolMenu->addAction(actionCreateLineTool);
|
||||||
toolMenu->addSeparator();
|
toolMenu->addSeparator();
|
||||||
toolMenu->addMenu(colorMenu);
|
toolMenu->addMenu(colorMenu);
|
||||||
|
|
||||||
// Attach all actions to Help
|
// Attach all actions to Help
|
||||||
helpMenu = new QMenu(tr("&Help"), this);
|
helpMenu = new QMenu(tr("&Help"), this);
|
||||||
helpMenu->addAction(actionAboutDialog);
|
helpMenu->addAction(actionAboutDialog);
|
||||||
helpMenu->addAction(actionAboutQtDialog);
|
helpMenu->addAction(actionAboutQtDialog);
|
||||||
|
|
||||||
// Add menu items to the menubar
|
// Add menu items to the menubar
|
||||||
menuBar()->addMenu(fileMenu);
|
menuBar()->addMenu(fileMenu);
|
||||||
menuBar()->addMenu(optionMenu);
|
menuBar()->addMenu(optionMenu);
|
||||||
menuBar()->addMenu(layerMenu);
|
menuBar()->addMenu(layerMenu);
|
||||||
menuBar()->addMenu(toolMenu);
|
menuBar()->addMenu(toolMenu);
|
||||||
menuBar()->addMenu(helpMenu);
|
menuBar()->addMenu(helpMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::createGui(){
|
void IntelliPhotoGui::createGui(){
|
||||||
// create a central widget to work on
|
// create a central widget to work on
|
||||||
centralGuiWidget = new QWidget(this);
|
centralGuiWidget = new QWidget(this);
|
||||||
setCentralWidget(centralGuiWidget);
|
setCentralWidget(centralGuiWidget);
|
||||||
|
|
||||||
// create the grid for the layout
|
// create the grid for the layout
|
||||||
mainLayout = new QGridLayout(centralGuiWidget);
|
mainLayout = new QGridLayout(centralGuiWidget);
|
||||||
centralGuiWidget->setLayout(mainLayout);
|
centralGuiWidget->setLayout(mainLayout);
|
||||||
|
|
||||||
// create Gui elements
|
// create Gui elements
|
||||||
paintingArea = new PaintingArea();
|
paintingArea = new PaintingArea();
|
||||||
|
|
||||||
// set gui elements
|
// set gui elements
|
||||||
mainLayout->addWidget(paintingArea);
|
mainLayout->addWidget(paintingArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::setIntelliStyle(){
|
void IntelliPhotoGui::setIntelliStyle(){
|
||||||
// Set the title
|
// Set the title
|
||||||
setWindowTitle("IntelliPhoto Prototype");
|
setWindowTitle("IntelliPhoto Prototype");
|
||||||
// Set style sheet
|
// Set style sheet
|
||||||
this->setStyleSheet("background-color:rgb(64,64,64)");
|
this->setStyleSheet("background-color:rgb(64,64,64)");
|
||||||
this->centralGuiWidget->setStyleSheet("color:rgb(255,255,255)");
|
this->centralGuiWidget->setStyleSheet("color:rgb(255,255,255)");
|
||||||
this->menuBar()->setStyleSheet("color:rgb(255,255,255)");
|
this->menuBar()->setStyleSheet("color:rgb(255,255,255)");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IntelliPhotoGui::maybeSave(){
|
bool IntelliPhotoGui::maybeSave(){
|
||||||
// Check for changes since last save
|
// Check for changes since last save
|
||||||
|
|
||||||
// TODO insert variable for modified status here to make an save exit message
|
// TODO insert variable for modified status here to make an save exit message
|
||||||
if (false) {
|
if (false) {
|
||||||
QMessageBox::StandardButton ret;
|
QMessageBox::StandardButton ret;
|
||||||
|
|
||||||
// Painting is the title of the window
|
// Painting is the title of the window
|
||||||
// Add text and the buttons
|
// Add text and the buttons
|
||||||
ret = QMessageBox::warning(this, tr("Painting"),
|
ret = QMessageBox::warning(this, tr("Painting"),
|
||||||
tr("The image has been modified.\n"
|
tr("The image has been modified.\n"
|
||||||
"Do you want to save your changes?"),
|
"Do you want to save your changes?"),
|
||||||
QMessageBox::Save | QMessageBox::Discard
|
QMessageBox::Save | QMessageBox::Discard
|
||||||
| QMessageBox::Cancel);
|
| QMessageBox::Cancel);
|
||||||
|
|
||||||
// If save button clicked call for file to be saved
|
// If save button clicked call for file to be saved
|
||||||
if (ret == QMessageBox::Save) {
|
if (ret == QMessageBox::Save) {
|
||||||
return saveFile("png");
|
return saveFile("png");
|
||||||
|
|
||||||
// If cancel do nothing
|
// If cancel do nothing
|
||||||
} else if (ret == QMessageBox::Cancel) {
|
} else if (ret == QMessageBox::Cancel) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){
|
bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){
|
||||||
// Define path, name and default file type
|
// Define path, name and default file type
|
||||||
QString initialPath = QDir::currentPath() + "/untitled." + fileFormat;
|
QString initialPath = QDir::currentPath() + "/untitled." + fileFormat;
|
||||||
|
|
||||||
// Get selected file from dialog
|
// Get selected file from dialog
|
||||||
// Add the proper file formats and extensions
|
// Add the proper file formats and extensions
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
|
||||||
initialPath,
|
initialPath,
|
||||||
tr("%1 Files (*.%2);;All Files (*)")
|
tr("%1 Files (*.%2);;All Files (*)")
|
||||||
.arg(QString::fromLatin1(fileFormat.toUpper()))
|
.arg(QString::fromLatin1(fileFormat.toUpper()))
|
||||||
.arg(QString::fromLatin1(fileFormat)), nullptr, QFileDialog::DontUseNativeDialog);
|
.arg(QString::fromLatin1(fileFormat)), nullptr, QFileDialog::DontUseNativeDialog);
|
||||||
|
|
||||||
// If no file do nothing
|
// If no file do nothing
|
||||||
if (fileName.isEmpty()) {
|
if (fileName.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// Call for the file to be saved
|
// Call for the file to be saved
|
||||||
return paintingArea->save(fileName, fileFormat.constData());
|
return paintingArea->save(fileName, fileFormat.constData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ private:
|
|||||||
// set style of the GUI
|
// set style of the GUI
|
||||||
void setIntelliStyle();
|
void setIntelliStyle();
|
||||||
|
|
||||||
|
|
||||||
// Will check if changes have occurred since last save
|
// Will check if changes have occurred since last save
|
||||||
bool maybeSave();
|
bool maybeSave();
|
||||||
// Opens the Save dialog and saves
|
// Opens the Save dialog and saves
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ SOURCES += \
|
|||||||
Tool/IntelliToolLine.cpp \
|
Tool/IntelliToolLine.cpp \
|
||||||
Tool/IntelliToolPen.cpp \
|
Tool/IntelliToolPen.cpp \
|
||||||
Tool/IntelliToolPlain.cpp \
|
Tool/IntelliToolPlain.cpp \
|
||||||
|
Tool/IntelliToolPolygon.cpp \
|
||||||
Tool/IntelliToolRectangle.cpp \
|
Tool/IntelliToolRectangle.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
@@ -46,11 +47,11 @@ HEADERS += \
|
|||||||
Tool/IntelliToolLine.h \
|
Tool/IntelliToolLine.h \
|
||||||
Tool/IntelliToolPen.h \
|
Tool/IntelliToolPen.h \
|
||||||
Tool/IntelliToolPlain.h \
|
Tool/IntelliToolPlain.h \
|
||||||
Tool/IntelliToolRectangle.h \
|
Tool/IntelliToolPolygon.h \
|
||||||
Tool/intellitoolcircle.h
|
Tool/IntelliToolRectangle.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
widget.ui
|
mainwindow.ui
|
||||||
|
|
||||||
QMAKE_CXXFLAGS
|
QMAKE_CXXFLAGS
|
||||||
QMAKE_LFLAGS
|
QMAKE_LFLAGS
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "Tool/IntelliToolCircle.h"
|
#include "Tool/IntelliToolCircle.h"
|
||||||
#include "Tool/IntelliToolRectangle.h"
|
#include "Tool/IntelliToolRectangle.h"
|
||||||
#include "Tool/IntelliToolFloodFill.h"
|
#include "Tool/IntelliToolFloodFill.h"
|
||||||
|
#include "Tool/IntelliToolPolygon.h"
|
||||||
|
|
||||||
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
||||||
:QWidget(parent){
|
:QWidget(parent){
|
||||||
@@ -24,7 +25,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
|||||||
this->Tool = new IntelliToolFloodFill(this, &colorPicker);
|
this->Tool = new IntelliToolFloodFill(this, &colorPicker);
|
||||||
this->setUp(maxWidth, maxHeight);
|
this->setUp(maxWidth, maxHeight);
|
||||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
||||||
layerBundle[0].image->drawPlain(QColor(255,0,0,255));
|
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
|
||||||
std::vector<QPoint> polygon;
|
std::vector<QPoint> polygon;
|
||||||
polygon.push_back(QPoint(100,000));
|
polygon.push_back(QPoint(100,000));
|
||||||
polygon.push_back(QPoint(200,100));
|
polygon.push_back(QPoint(200,100));
|
||||||
@@ -36,7 +37,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
|||||||
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
|
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
|
||||||
layerBundle[1].alpha=200;
|
layerBundle[1].alpha=200;
|
||||||
|
|
||||||
activeLayer=1;
|
activeLayer=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaintingArea::~PaintingArea(){
|
PaintingArea::~PaintingArea(){
|
||||||
@@ -193,6 +194,14 @@ void PaintingArea::createLineTool(){
|
|||||||
Tool = new IntelliToolLine(this, &colorPicker);
|
Tool = new IntelliToolLine(this, &colorPicker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PaintingArea::getWidthActiveLayer(){
|
||||||
|
return layerBundle.operator[](activeLayer).width;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PaintingArea::getHeightActiveLayer(){
|
||||||
|
return layerBundle.operator[](activeLayer).hight;
|
||||||
|
}
|
||||||
|
|
||||||
// If a mouse button is pressed check if it was the
|
// If a mouse button is pressed check if it was the
|
||||||
// left button and if so store the current position
|
// left button and if so store the current position
|
||||||
// Set that we are currently drawing
|
// Set that we are currently drawing
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ public:
|
|||||||
void createPlainTool();
|
void createPlainTool();
|
||||||
void createLineTool();
|
void createLineTool();
|
||||||
|
|
||||||
|
//get Width and Height of active Layer
|
||||||
|
int getWidthActiveLayer();
|
||||||
|
int getHeightActiveLayer();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Events to handle
|
// Events to handle
|
||||||
void slotActivateLayer(int a);
|
void slotActivateLayer(int a);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){
|
|||||||
void IntelliToolLine::onMouseLeftPressed(int x, int y){
|
void IntelliToolLine::onMouseLeftPressed(int x, int y){
|
||||||
IntelliTool::onMouseLeftPressed(x,y);
|
IntelliTool::onMouseLeftPressed(x,y);
|
||||||
this->start=QPoint(x,y);
|
this->start=QPoint(x,y);
|
||||||
this->Canvas->image->drawLine(start, start, colorPicker->getFirstColor(),lineWidth);
|
this->Canvas->image->drawPoint(start, colorPicker->getFirstColor(),lineWidth);
|
||||||
Canvas->image->calculateVisiblity();
|
Canvas->image->calculateVisiblity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
106
src/Tool/IntelliToolPolygon.cpp
Normal file
106
src/Tool/IntelliToolPolygon.cpp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include "IntelliToolPolygon.h"
|
||||||
|
#include "Layer/PaintingArea.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QCursor>
|
||||||
|
|
||||||
|
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||||
|
:IntelliTool(Area, colorPicker){
|
||||||
|
lineWidth = 5;
|
||||||
|
isDrawing = false;
|
||||||
|
PointIsNearStart = false;
|
||||||
|
drawingPoint.setX(0);
|
||||||
|
drawingPoint.setY(0);
|
||||||
|
Point.setX(0);
|
||||||
|
Point.setY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||||
|
if(!isDrawing){
|
||||||
|
width = Area->getWidthActiveLayer();
|
||||||
|
height = Area->getHeightActiveLayer();
|
||||||
|
}
|
||||||
|
if(!isDrawing && x > 0 && y > 0 && x < width && y < height){
|
||||||
|
isDrawing = true;
|
||||||
|
drawingPoint.setX(x);
|
||||||
|
drawingPoint.setY(y);
|
||||||
|
QPointList.push_back(drawingPoint);
|
||||||
|
IntelliTool::onMouseLeftPressed(x,y);
|
||||||
|
this->Canvas->image->drawPlain(Qt::transparent);
|
||||||
|
this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth);
|
||||||
|
this->Canvas->image->calculateVisiblity();
|
||||||
|
}
|
||||||
|
else if(isDrawing && isNearStart(x,y,QPointList.front())){
|
||||||
|
PointIsNearStart = isNearStart(x,y,QPointList.front());
|
||||||
|
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
|
||||||
|
this->Canvas->image->calculateVisiblity();
|
||||||
|
}
|
||||||
|
else if(isDrawing){
|
||||||
|
drawingPoint.setX(x);
|
||||||
|
drawingPoint.setY(y);
|
||||||
|
QPointList.push_back(drawingPoint);
|
||||||
|
this->Canvas->image->drawLine(QPointList.operator[](QPointList.size() - 2), QPointList.back(), colorPicker->getFirstColor(), lineWidth);
|
||||||
|
this->Canvas->image->calculateVisiblity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolPolygon::onMouseRightPressed(int x, int y){
|
||||||
|
isDrawing = false;
|
||||||
|
PointIsNearStart = false;
|
||||||
|
QPointList.clear();
|
||||||
|
IntelliTool::onMouseRightPressed(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
||||||
|
if(PointIsNearStart && QPointList.size() > 1){
|
||||||
|
this->Canvas->image->calculateVisiblity();
|
||||||
|
PointIsNearStart = false;
|
||||||
|
isDrawing = false;
|
||||||
|
Triangles = IntelliHelper::calculateTriangles(QPointList);
|
||||||
|
for(int i = 0; i < width; i++){
|
||||||
|
for(int j = 0; j < height; j++){
|
||||||
|
Point.setX(i);
|
||||||
|
Point.setY(j);
|
||||||
|
if(IntelliHelper::isInPolygon(Triangles,Point)){
|
||||||
|
this->Canvas->image->drawPixel(QPoint(i,j), colorPicker->getFirstColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QPointList.clear();
|
||||||
|
IntelliTool::onMouseLeftReleased(x,y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolPolygon::onMouseRightReleased(int x, int y){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolPolygon::onWheelScrolled(int value){
|
||||||
|
if(!isDrawing){
|
||||||
|
if(lineWidth + value < 10){
|
||||||
|
lineWidth += value;
|
||||||
|
}
|
||||||
|
if(lineWidth < 1){
|
||||||
|
lineWidth = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolPolygon::onMouseMoved(int x, int y){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
|
||||||
|
bool isNear = false;
|
||||||
|
int StartX = Startpoint.x();
|
||||||
|
int StartY = Startpoint.y();
|
||||||
|
int valueToNear = 10;
|
||||||
|
|
||||||
|
for(int i = StartX - valueToNear; i < StartX + valueToNear; i++){
|
||||||
|
for(int j = StartY - valueToNear; j < StartY + valueToNear; j++){
|
||||||
|
if((i == x) && (j == y)){
|
||||||
|
isNear = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isNear;
|
||||||
|
}
|
||||||
79
src/Tool/IntelliToolPolygon.h
Normal file
79
src/Tool/IntelliToolPolygon.h
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#ifndef INTELLITOOLPOLYGON_H
|
||||||
|
#define INTELLITOOLPOLYGON_H
|
||||||
|
|
||||||
|
#include "IntelliTool.h"
|
||||||
|
#include "IntelliHelper/IntelliHelper.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <QPoint>
|
||||||
|
/*!
|
||||||
|
* \brief The IntelliToolPolygon managed the Drawing of Polygonforms
|
||||||
|
*/
|
||||||
|
class IntelliToolPolygon : public IntelliTool
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* \brief IntelliToolPolygon Constructor Define the Tool-intern Parameters
|
||||||
|
* \param Area
|
||||||
|
* \param colorPicker
|
||||||
|
*/
|
||||||
|
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||||
|
|
||||||
|
virtual void onMouseLeftPressed(int x, int y) override;
|
||||||
|
virtual void onMouseLeftReleased(int x, int y) override;
|
||||||
|
virtual void onMouseRightPressed(int x, int y) override;
|
||||||
|
virtual void onMouseRightReleased(int x, int y) override;
|
||||||
|
|
||||||
|
virtual void onWheelScrolled(int value) override;
|
||||||
|
|
||||||
|
virtual void onMouseMoved(int x, int y) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*!
|
||||||
|
* \brief isNearStart
|
||||||
|
* \param x
|
||||||
|
* \param y
|
||||||
|
* \param Startpoint
|
||||||
|
* \return true : Near Startpoint, else false
|
||||||
|
*/
|
||||||
|
bool isNearStart(int x, int y, QPoint Startpoint);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief lineWidth of the Drawing Polygon
|
||||||
|
*/
|
||||||
|
int lineWidth;
|
||||||
|
/*!
|
||||||
|
* \brief width of the active Layer
|
||||||
|
*/
|
||||||
|
int width;
|
||||||
|
/*!
|
||||||
|
* \brief height of the active Layer
|
||||||
|
*/
|
||||||
|
int height;
|
||||||
|
/*!
|
||||||
|
* \brief isDrawing true while drawing, else false
|
||||||
|
*/
|
||||||
|
bool isDrawing;
|
||||||
|
/*!
|
||||||
|
* \brief PointIsNearStart true, when last click near Startpoint, else false
|
||||||
|
*/
|
||||||
|
bool PointIsNearStart;
|
||||||
|
/*!
|
||||||
|
* \brief drawingPoint Current Point after Left-Click
|
||||||
|
*/
|
||||||
|
QPoint drawingPoint;
|
||||||
|
/*!
|
||||||
|
* \brief Point Needed to look, if Point is in Polygon
|
||||||
|
*/
|
||||||
|
QPoint Point;
|
||||||
|
/*!
|
||||||
|
* \brief QPointList List of all Points of the Polygon
|
||||||
|
*/
|
||||||
|
std::vector<QPoint> QPointList;
|
||||||
|
/*!
|
||||||
|
* \brief Triangles Transformed QPointList into triangulated Form of the Polygon
|
||||||
|
*/
|
||||||
|
std::vector<Triangle> Triangles;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INTELLITOOLPOLYGON_H
|
||||||
23
src/mainwindow.ui
Normal file
23
src/mainwindow.ui
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>542</width>
|
||||||
|
<height>459</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>IntelliPhoto</string>
|
||||||
|
</property>
|
||||||
|
<property name="animated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget"/>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>Widget</class>
|
|
||||||
<widget class="QWidget" name="Widget">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>360</width>
|
|
||||||
<height>206</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Widget</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
||||||
Reference in New Issue
Block a user