mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-12 19:40:28 +02:00
Modularisation
This commit is contained in:
@@ -111,18 +111,15 @@ void IntelliPhotoGui::slotDeleteLayer()
|
||||
paintingArea->deleteLayer(layerNumber);
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotGetColorbar(){
|
||||
void slotCreatePenTool(){
|
||||
|
||||
bool ok1;
|
||||
|
||||
int firstOrSecondColor = QInputDialog::getInt(this, tr("Which Color"),
|
||||
tr("Number:"),
|
||||
1,1, 2, 1, &ok1);
|
||||
|
||||
Tool = paintingArea->getTool();
|
||||
Tool->getColorbar(firstOrSecondColor);
|
||||
}
|
||||
|
||||
void slotCreateFloodFillTool(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void IntelliPhotoGui::slotSetActiveAlpha(){
|
||||
// Stores button value
|
||||
bool ok1, ok2;
|
||||
@@ -218,6 +215,14 @@ void IntelliPhotoGui::slotSetActiveLayer(){
|
||||
};
|
||||
|
||||
|
||||
void IntelliPhotoGui::slotCreatePenTool(){
|
||||
paintingArea->createPenTool();
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotCreateFloodFillTool(){
|
||||
paintingArea->createFloodFillTool();
|
||||
}
|
||||
|
||||
// Open an about dialog
|
||||
void IntelliPhotoGui::slotAboutDialog()
|
||||
{
|
||||
@@ -275,17 +280,10 @@ void IntelliPhotoGui::createActions()
|
||||
actionCreateNewLayer = new QAction(tr("&New Layer..."), this);
|
||||
connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer()));
|
||||
|
||||
|
||||
// Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
|
||||
actionDeleteLayer = new QAction(tr("&Delete Layer..."), this);
|
||||
connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer()));
|
||||
|
||||
actionGetColorbar = new QAction(tr("&Set Color"),this);
|
||||
connect(actionGetColorbar, SIGNAL(triggered()), this, SLOT(slotGetColorbar()));
|
||||
|
||||
actionFloodFill = new QAction(tr("&clear Image"), this);
|
||||
connect(actionFloodFill, SIGNAL(triggered()), this, SLOT(slotClearActiveLayer()));
|
||||
|
||||
actionSetActiveLayer = new QAction(tr("&set Active"), this);
|
||||
connect(actionSetActiveLayer, SIGNAL(triggered()), this, SLOT(slotSetActiveLayer()));
|
||||
|
||||
@@ -316,6 +314,14 @@ void IntelliPhotoGui::createActions()
|
||||
actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
|
||||
connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown()));
|
||||
|
||||
//Create Tool actions down here
|
||||
actionCreateFloodFillTool = new QAction(tr("&Flood Fill"), this);
|
||||
connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool()));
|
||||
|
||||
actionCreatePenTool = new QAction(tr("&Pen"),this);
|
||||
connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool()));
|
||||
|
||||
|
||||
// Create about action and tie to IntelliPhotoGui::about()
|
||||
actionAboutDialog = new QAction(tr("&About"), this);
|
||||
connect(actionAboutDialog, SIGNAL(triggered()), this, SLOT(slotAboutDialog()));
|
||||
@@ -343,7 +349,6 @@ void IntelliPhotoGui::createMenus()
|
||||
|
||||
// Attach all actions to Options
|
||||
optionMenu = new QMenu(tr("&Options"), this);
|
||||
optionMenu->addAction(actionFloodFill);
|
||||
optionMenu->addAction(actionSetActiveLayer);
|
||||
optionMenu->addAction(actionSetActiveAlpha);
|
||||
optionMenu->addAction(actionMovePositionUp);
|
||||
@@ -360,7 +365,8 @@ void IntelliPhotoGui::createMenus()
|
||||
|
||||
//Attach all Tool Options
|
||||
toolMenu = new QMenu(tr("&Tools"), this);
|
||||
toolMenu->addAction(actionGetColorbar);
|
||||
toolMenu->addAction(actionCreatePenTool);
|
||||
toolMenu->addAction(actionCreateFloodFillTool);
|
||||
|
||||
// Attach all actions to Help
|
||||
helpMenu = new QMenu(tr("&Help"), this);
|
||||
|
||||
@@ -33,11 +33,6 @@ private slots:
|
||||
void slotSave();
|
||||
void slotCreateNewLayer();
|
||||
void slotDeleteLayer();
|
||||
|
||||
void slotGetColorbar();
|
||||
|
||||
void slotAboutDialog();
|
||||
|
||||
void slotClearActiveLayer();
|
||||
void slotSetActiveLayer();
|
||||
void slotSetActiveAlpha();
|
||||
@@ -48,6 +43,11 @@ private slots:
|
||||
void slotMoveLayerUp();
|
||||
void slotMoveLayerDown();
|
||||
|
||||
void slotCreatePenTool();
|
||||
void slotCreateFloodFillTool();
|
||||
|
||||
void slotAboutDialog();
|
||||
|
||||
private:
|
||||
// Will tie user actions to functions
|
||||
void createActions();
|
||||
@@ -82,12 +82,12 @@ private:
|
||||
QAction *actionCreateNewLayer;
|
||||
QAction *actionDeleteLayer;
|
||||
|
||||
QAction *actionGetColorbar;
|
||||
QAction *actionCreatePenTool;
|
||||
QAction *actionCreateFloodFillTool;
|
||||
|
||||
QAction *actionAboutDialog;
|
||||
QAction *actionAboutQtDialog;
|
||||
|
||||
QAction* actionFloodFill;
|
||||
QAction* actionSetActiveLayer;
|
||||
QAction* actionSetActiveAlpha;
|
||||
QAction* actionMovePositionUp;
|
||||
|
||||
@@ -25,7 +25,6 @@ SOURCES += \
|
||||
Tool/IntelliTool.cpp \
|
||||
Tool/IntelliToolFloodFillTool.cpp \
|
||||
Tool/IntelliToolPen.cpp \
|
||||
Tool/IntelliToolSetColorTool.cpp \
|
||||
main.cpp
|
||||
|
||||
HEADERS += \
|
||||
@@ -37,8 +36,7 @@ HEADERS += \
|
||||
Layer/PaintingArea.h \
|
||||
Tool/IntelliTool.h \
|
||||
Tool/IntelliToolFloodFillTool.h \
|
||||
Tool/IntelliToolPen.h \
|
||||
Tool/IntelliToolSetColorTool.h
|
||||
Tool/IntelliToolPen.h
|
||||
|
||||
FORMS += \
|
||||
widget.ui
|
||||
|
||||
@@ -11,14 +11,12 @@
|
||||
#include "Image/IntelliRasterImage.h"
|
||||
#include "Image/IntelliShapedImage.h"
|
||||
#include "Tool/IntelliToolPen.h"
|
||||
#include "Tool/IntelliToolSetColorTool.h"
|
||||
#include "Tool/IntelliToolFloodFillTool.h"
|
||||
|
||||
|
||||
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
||||
:QWidget(parent){
|
||||
this->Tool = new IntelliToolFloodFillTool(this);
|
||||
this->ColorTool = new IntelliToolSetColorTool(this);
|
||||
this->Tool = nullptr;
|
||||
this->setUp(maxWidth, maxHeight);
|
||||
//tetsing
|
||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
||||
@@ -37,9 +35,6 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
||||
activeLayer=1;
|
||||
}
|
||||
|
||||
IntelliToolSetColorTool* PaintingArea::getTool(){
|
||||
return ColorTool;
|
||||
}
|
||||
|
||||
void PaintingArea::setUp(int maxWidth, int maxHeight){
|
||||
//set standart parameter
|
||||
@@ -165,11 +160,23 @@ void PaintingArea::slotActivateLayer(int a){
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::createPenTool(){
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolPen(this);
|
||||
}
|
||||
|
||||
void PaintingArea::createFloodFillTool(){
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolFloodFillTool(this);
|
||||
}
|
||||
|
||||
// If a mouse button is pressed check if it was the
|
||||
// left button and if so store the current position
|
||||
// Set that we are currently drawing
|
||||
void PaintingArea::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[activeLayer].widthOffset;
|
||||
int y = event->y()-layerBundle[activeLayer].hightOffset;
|
||||
if(event->button() == Qt::LeftButton){
|
||||
@@ -185,6 +192,8 @@ void PaintingArea::mousePressEvent(QMouseEvent *event)
|
||||
// from the last position to the current
|
||||
void PaintingArea::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[activeLayer].widthOffset;
|
||||
int y = event->y()-layerBundle[activeLayer].hightOffset;
|
||||
Tool->onMouseMoved(x, y);
|
||||
@@ -193,6 +202,8 @@ void PaintingArea::mouseMoveEvent(QMouseEvent *event)
|
||||
// If the button is released we set variables to stop drawing
|
||||
void PaintingArea::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[activeLayer].widthOffset;
|
||||
int y = event->y()-layerBundle[activeLayer].hightOffset;
|
||||
if(event->button() == Qt::LeftButton){
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <QList>
|
||||
#include "Image/IntelliImage.h"
|
||||
#include "Tool/IntelliTool.h"
|
||||
#include "Tool/IntelliToolSetColorTool.h"
|
||||
|
||||
|
||||
struct LayerObject{
|
||||
@@ -33,8 +32,6 @@ class PaintingArea : public QWidget
|
||||
public:
|
||||
PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr);
|
||||
|
||||
IntelliToolSetColorTool* getTool(); //TODO: rename function, when there are more Tools
|
||||
|
||||
// Handles all events
|
||||
bool open(const QString &fileName);
|
||||
bool save(const QString &fileName, const char *fileFormat);
|
||||
@@ -51,6 +48,9 @@ public:
|
||||
// Has the image been modified since last save
|
||||
bool isModified() const { return modified; }
|
||||
|
||||
//create tools
|
||||
void createPenTool();
|
||||
void createFloodFillTool();
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -81,7 +81,6 @@ private:
|
||||
int maxHeight;
|
||||
|
||||
IntelliTool* Tool;
|
||||
IntelliToolSetColorTool* ColorTool;
|
||||
|
||||
std::vector<LayerObject> layerBundle;
|
||||
int activeLayer=-1;
|
||||
|
||||
@@ -1,41 +1,30 @@
|
||||
#include "IntelliToolFloodFillTool.h"
|
||||
#include "Layer/PaintingArea.h"
|
||||
#include "QColorDialog"
|
||||
|
||||
IntelliToolFloodFillTool::IntelliToolFloodFillTool(PaintingArea* Area)
|
||||
:IntelliToolSetColorTool(Area)
|
||||
{
|
||||
Tool = Area->getTool();
|
||||
isPressed = false;
|
||||
:IntelliTool(Area){
|
||||
|
||||
this->color = QColorDialog::getColor(Qt::blue,nullptr,"Flood Fill Color");
|
||||
}
|
||||
|
||||
void IntelliToolFloodFillTool::onMouseLeftPressed(int x, int y){
|
||||
if(!isPressed){
|
||||
isPressed = true;
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
Tool = Area->getTool();
|
||||
this->Canvas->image->floodFill(Tool->getFirstColor());
|
||||
}
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->Canvas->image->floodFill(color);
|
||||
}
|
||||
|
||||
void IntelliToolFloodFillTool::onMouseRightPressed(int x, int y){
|
||||
if(!isPressed){
|
||||
isPressed = true;
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
Tool = Area->getTool();
|
||||
this->Canvas->image->floodFill(Tool->getSecondColor());
|
||||
}
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolFloodFillTool::onMouseRightReleased(int x, int y){
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
if(isPressed) isPressed = false;
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolFloodFillTool::onMouseLeftReleased(int x, int y){
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
if(isPressed) isPressed = false;
|
||||
}
|
||||
|
||||
void IntelliToolFloodFillTool::onMouseMoved(int x, int y){
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
#ifndef INTELLITOOLFLOODFILLTOOL_H
|
||||
#define INTELLITOOLFLOODFILLTOOL_H
|
||||
|
||||
#include "IntelliToolSetColorTool.h"
|
||||
#include "IntelliTool.h"
|
||||
#include "QColor"
|
||||
|
||||
class IntelliToolFloodFillTool : public IntelliToolSetColorTool
|
||||
class IntelliToolFloodFillTool : public IntelliTool
|
||||
{
|
||||
QColor color;
|
||||
public:
|
||||
IntelliToolFloodFillTool(PaintingArea *Area);
|
||||
|
||||
void IntelliToolFloodFillTool::onMouseLeftPressed(int x, int y) override;
|
||||
void IntelliToolFloodFillTool::onMouseLeftReleased(int x, int y) override;
|
||||
void IntelliToolFloodFillTool::onMouseRightPressed(int x, int y) override;
|
||||
void IntelliToolFloodFillTool::onMouseRightReleased(int x, int y) override;
|
||||
void IntelliToolFloodFillTool::onMouseMoved(int x, int y) override;
|
||||
void onMouseLeftPressed(int x, int y) override;
|
||||
void onMouseLeftReleased(int x, int y) override;
|
||||
void onMouseRightPressed(int x, int y) override;
|
||||
void onMouseRightReleased(int x, int y) override;
|
||||
void onMouseMoved(int x, int y) override;
|
||||
|
||||
private:
|
||||
IntelliToolSetColorTool* Tool;
|
||||
bool isPressed;
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLFLOODFILLTOOL_H
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
#include "IntelliToolPen.h"
|
||||
#include "Layer/PaintingArea.h"
|
||||
#include "QDebug"
|
||||
#include "QColorDialog"
|
||||
#include "QInputDialog"
|
||||
|
||||
IntelliToolPen::IntelliToolPen(PaintingArea* Area)
|
||||
:IntelliToolSetColorTool(Area){
|
||||
:IntelliTool(Area){
|
||||
this->color = QColorDialog::getColor(Qt::blue,nullptr,"Flood Fill Color");
|
||||
|
||||
bool ok;
|
||||
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Number:", 1,0, 50, 1, &ok);
|
||||
}
|
||||
|
||||
IntelliToolPen::~IntelliToolPen(){
|
||||
@@ -35,9 +40,7 @@ void IntelliToolPen::onMouseLeftReleased(int x, int y){
|
||||
void IntelliToolPen::onMouseMoved(int x, int y){
|
||||
if(this->drawing){
|
||||
QPoint newPoint(x,y);
|
||||
Tool = Area->getTool();
|
||||
qDebug() << Tool->getFirstColor();
|
||||
this->Canvas->image->drawLine(this->point, newPoint, Tool->getFirstColor(), 2);
|
||||
this->Canvas->image->drawLine(this->point, newPoint, color, penWidth);
|
||||
this->point=newPoint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#ifndef INTELLITOOLPEN_H
|
||||
#define INTELLITOOLPEN_H
|
||||
|
||||
#include"IntelliToolSetColorTool.h"
|
||||
#include"IntelliTool.h"
|
||||
#include"QColor"
|
||||
#include"QPoint"
|
||||
|
||||
class IntelliToolPen : public IntelliToolSetColorTool{
|
||||
class IntelliToolPen : public IntelliTool{
|
||||
QColor color;
|
||||
int penWidth;
|
||||
QPoint point;
|
||||
public:
|
||||
IntelliToolPen(PaintingArea* Area);
|
||||
@@ -17,9 +19,6 @@ public:
|
||||
virtual void onMouseLeftReleased(int x, int y) override;
|
||||
|
||||
virtual void onMouseMoved(int x, int y) override;
|
||||
|
||||
private:
|
||||
IntelliToolSetColorTool* Tool;
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLPEN_H
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
#include "IntelliToolSetColorTool.h"
|
||||
#include "QDebug"
|
||||
|
||||
IntelliToolSetColorTool::IntelliToolSetColorTool(PaintingArea* Area)
|
||||
:IntelliTool(Area){
|
||||
firstColor = {255,0,0,255};
|
||||
secondColor = {0,0,255,255};
|
||||
}
|
||||
|
||||
IntelliToolSetColorTool::~IntelliToolSetColorTool(){
|
||||
|
||||
}
|
||||
|
||||
void IntelliToolSetColorTool::getColorbar(int firstOrSecondColor = 1){
|
||||
QString Titel;
|
||||
QColor newColor;
|
||||
if(firstOrSecondColor == 1){
|
||||
Titel = "Choose first Color";
|
||||
newColor = QColorDialog::getColor(this->firstColor,nullptr,Titel);
|
||||
this->firstColor = newColor;
|
||||
qDebug() << "Firstcolor" << this->firstColor;
|
||||
}
|
||||
else{
|
||||
Titel = "Choose second Color";
|
||||
newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel);
|
||||
this->secondColor = newColor;
|
||||
}
|
||||
}
|
||||
|
||||
QColor IntelliToolSetColorTool::getFirstColor(){
|
||||
return firstColor;
|
||||
}
|
||||
|
||||
QColor IntelliToolSetColorTool::getSecondColor(){
|
||||
return secondColor;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef INTELLITOOLSETCOLORTOOL_H
|
||||
#define INTELLITOOLSETCOLORTOOL_H
|
||||
|
||||
#include"IntelliTool.h"
|
||||
#include"QColor"
|
||||
#include"QPoint"
|
||||
#include"QColorDialog"
|
||||
|
||||
class IntelliToolSetColorTool: public IntelliTool{
|
||||
public:
|
||||
IntelliToolSetColorTool(PaintingArea *Area);
|
||||
virtual ~IntelliToolSetColorTool() override;
|
||||
|
||||
void getColorbar(int firstOrSecondColor) override;
|
||||
|
||||
QColor IntelliToolSetColorTool::getFirstColor();
|
||||
QColor IntelliToolSetColorTool::getSecondColor();
|
||||
|
||||
protected:
|
||||
QColor firstColor;
|
||||
QColor secondColor;
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLSETCOLORTOOL_H
|
||||
Reference in New Issue
Block a user