diff --git a/src/Painting/GUI/IntelliPhotoGui.cpp b/src/Painting/GUI/IntelliPhotoGui.cpp index 350293d..4a96e0e 100644 --- a/src/Painting/GUI/IntelliPhotoGui.cpp +++ b/src/Painting/GUI/IntelliPhotoGui.cpp @@ -133,22 +133,22 @@ void IntelliPhotoGui::slotSetActiveAlpha(){ } void IntelliPhotoGui::slotPositionMoveUp(){ - paintingArea->movePositionActive(0,-2); + paintingArea->movePositionActive(0,-20); update(); } void IntelliPhotoGui::slotPositionMoveDown(){ - paintingArea->movePositionActive(0,2); + paintingArea->movePositionActive(0,20); update(); } void IntelliPhotoGui::slotPositionMoveLeft(){ - paintingArea->movePositionActive(-2,0); + paintingArea->movePositionActive(-20,0); update(); } void IntelliPhotoGui::slotPositionMoveRight(){ - paintingArea->movePositionActive(2,0); + paintingArea->movePositionActive(20,0); update(); } @@ -269,10 +269,6 @@ void IntelliPhotoGui::createActions() actionDeleteLayer = new QAction(tr("&Delete Layer..."), this); connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer())); - // Delete Active Layer action and tie to paintingArea::deleteActiveLayerLayer() - actionDeleteActiveLayer = new QAction(tr("&Delete active Layer"), this); - connect(actionDeleteActiveLayer, SIGNAL(triggered()), paintingArea, SLOT(deleteActiveLayer())); - actionFloodFill = new QAction(tr("&clear Image"), this); connect(actionFloodFill, SIGNAL(triggered()), this, SLOT(slotClearActiveLayer())); @@ -347,7 +343,6 @@ void IntelliPhotoGui::createMenus() layerMenu = new QMenu(tr("&Layer"), this); layerMenu->addAction(actionCreateNewLayer); layerMenu->addAction(actionDeleteLayer); - layerMenu->addAction(actionDeleteActiveLayer); //Attach all Tool Options toolMenu = new QMenu(tr("&Tools"), this); diff --git a/src/Painting/GUI/IntelliPhotoGui.h b/src/Painting/GUI/IntelliPhotoGui.h index 87b529f..9a8241c 100644 --- a/src/Painting/GUI/IntelliPhotoGui.h +++ b/src/Painting/GUI/IntelliPhotoGui.h @@ -75,7 +75,6 @@ private: QAction *actionCreateNewLayer; QAction *actionDeleteLayer; - QAction *actionDeleteActiveLayer; QAction *actionAboutDialog; QAction *actionAboutQtDialog; diff --git a/src/Painting/Image/IntelliImage.cpp b/src/Painting/Image/IntelliImage.cpp index 814aa36..d9f5a48 100644 --- a/src/Painting/Image/IntelliImage.cpp +++ b/src/Painting/Image/IntelliImage.cpp @@ -50,9 +50,6 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ // Draw a line from the last registered point to the current painter.drawPoint(p1); - - // Call to update the rectangular space where we drew - //update(QRect(p1, p2)); } void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){ @@ -69,5 +66,4 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co void IntelliImage::floodFill(const QColor& color){ imageData.fill(color); - } diff --git a/src/Painting/Image/IntelliRasterImage.cpp b/src/Painting/Image/IntelliRasterImage.cpp index 6e4bc15..d92260f 100644 --- a/src/Painting/Image/IntelliRasterImage.cpp +++ b/src/Painting/Image/IntelliRasterImage.cpp @@ -31,7 +31,7 @@ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ for(int y = 0; y #include +#include #include -#include "string.h" + #include "PaintingArea.h" #include "Image/IntelliRasterImage.h" #include "Image/IntelliShapedImage.h" - -#include -#include +#include "Tool/IntelliToolPen.h" PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ + this->Tool = new IntelliToolPen(this); this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); @@ -160,7 +163,13 @@ void PaintingArea::slotActivateLayer(int a){ // Set that we are currently drawing void PaintingArea::mousePressEvent(QMouseEvent *event) { - //TODO implement in tool + int x = (float)layerBundle[activeLayer].width/(float)width()*event->x()+layerBundle[activeLayer].widthOffset; + int y = (float)layerBundle[activeLayer].hight/(float)height()*event->y()+layerBundle[activeLayer].hightOffset; + if(event->button() == Qt::LeftButton){ + Tool->onMouseLeftPressed(x, y); + }else if(event->button() == Qt::RightButton){ + Tool->onMouseRightPressed(x, y); + } } @@ -169,13 +178,21 @@ void PaintingArea::mousePressEvent(QMouseEvent *event) // from the last position to the current void PaintingArea::mouseMoveEvent(QMouseEvent *event) { - //TODO implement in Tool + int x = (float)layerBundle[activeLayer].width/(float)width()*event->x()+layerBundle[activeLayer].widthOffset; + int y = (float)layerBundle[activeLayer].hight/(float)height()*event->y()+layerBundle[activeLayer].hightOffset; + Tool->onMouseMoved(x, y); } // If the button is released we set variables to stop drawing void PaintingArea::mouseReleaseEvent(QMouseEvent *event) { - //TODO implement in tool + int x = (float)layerBundle[activeLayer].width/(float)width()*event->x()+layerBundle[activeLayer].widthOffset; + int y = (float)layerBundle[activeLayer].hight/(float)height()*event->y()+layerBundle[activeLayer].hightOffset; + if(event->button() == Qt::LeftButton){ + Tool->onMouseLeftReleased(x, y); + }else if(event->button() == Qt::RightButton){ + Tool->onMouseRightReleased(x, y); + } } // QPainter provides functions to draw on the widget @@ -235,7 +252,7 @@ void PaintingArea::assembleLayers(bool forSaving){ if(layer.hightOffset+y>=maxHeight) break; for(int x=0; x=maxWidth) break; + if(layer.widthOffset+x>=maxWidth) break; clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.hightOffset+y); clr_1=cpy.pixelColor(x,y); float t = static_cast(clr_1.alpha())/255.f; @@ -257,7 +274,7 @@ void PaintingArea::assembleLayers(bool forSaving){ void PaintingArea::createTempLayerAfter(int idx){ if(idx>=0){ LayerObject newLayer; - newLayer.alpha = layerBundle[idx].alpha; + newLayer.alpha = 255; newLayer.hight = layerBundle[idx].hight; newLayer.width = layerBundle[idx].width; newLayer.hightOffset = layerBundle[idx].hightOffset; diff --git a/src/Painting/Layer/PaintingArea.h b/src/Painting/Layer/PaintingArea.h index ead05da..7623551 100644 --- a/src/Painting/Layer/PaintingArea.h +++ b/src/Painting/Layer/PaintingArea.h @@ -4,11 +4,11 @@ #include #include -#include"Image/IntelliImage.h" -#include"Tool/IntelliTool.h" #include #include #include +#include"Image/IntelliImage.h" +#include"Tool/IntelliTool.h" struct LayerObject{ @@ -77,6 +77,8 @@ private: int maxWidth; int maxHeight; + IntelliTool* Tool; + std::vector layerBundle; int activeLayer=-1; diff --git a/src/Painting/Tool/IntelliTool.cpp b/src/Painting/Tool/IntelliTool.cpp index 046e7be..404250d 100644 --- a/src/Painting/Tool/IntelliTool.cpp +++ b/src/Painting/Tool/IntelliTool.cpp @@ -12,12 +12,24 @@ IntelliTool::~IntelliTool(){ void IntelliTool::onMouseRightPressed(int x, int y){ - this->drawing=true; - //create drawing layer - this->createToolLayer(); + if(drawing){ + drawing=false; + this->deleteToolLayer(); + } } void IntelliTool::onMouseRightReleased(int x, int y){ + //optional for tool +} + +void IntelliTool::onMouseLeftPressed(int x, int y){ + this->drawing=true; + //create drawing layer + this->createToolLayer(); + +} + +void IntelliTool::onMouseLeftReleased(int x, int y){ if(drawing){ drawing=false; this->mergeToolLayer(); @@ -25,17 +37,6 @@ void IntelliTool::onMouseRightReleased(int x, int y){ } } -void IntelliTool::onMouseLeftPressed(int x, int y){ - if(drawing){ - drawing=false; - this->deleteToolLayer(); - } -} - -void IntelliTool::onMouseLeftReleased(int x, int y){ - //optional for tool -} - void IntelliTool::onMouseMoved(int x, int y){ //optional for tool } diff --git a/src/Painting/Tool/IntelliToolPen.cpp b/src/Painting/Tool/IntelliToolPen.cpp new file mode 100644 index 0000000..ca66584 --- /dev/null +++ b/src/Painting/Tool/IntelliToolPen.cpp @@ -0,0 +1,42 @@ +#include"IntelliToolPen.h" +#include"Layer/PaintingArea.h" +#include"QDebug" + +IntelliToolPen::IntelliToolPen(PaintingArea* Area) + :IntelliTool(Area){ + +} + +IntelliToolPen::~IntelliToolPen(){ + +} + +void IntelliToolPen::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); + //implement in here + this->point=QPoint(x,y); + this->Canvas->image->drawPixel(point, QColor(255,0,0,255)); +} + +void IntelliToolPen::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); + //implemnt in here +} + +void IntelliToolPen::onMouseLeftPressed(int x, int y){ + //implement in here + IntelliTool::onMouseLeftPressed(x,y); +} + +void IntelliToolPen::onMouseLeftReleased(int x, int y){ + //implement in here + IntelliTool::onMouseLeftReleased(x,y); +} + +void IntelliToolPen::onMouseMoved(int x, int y){ + if(this->drawing){ + QPoint newPoint(x,y); + this->Canvas->image->drawLine(this->point, newPoint, QColor(255,0,0,255), 2); + this->point=newPoint; + } +} diff --git a/src/Painting/Tool/IntelliToolPen.h b/src/Painting/Tool/IntelliToolPen.h new file mode 100644 index 0000000..a08ecc6 --- /dev/null +++ b/src/Painting/Tool/IntelliToolPen.h @@ -0,0 +1,23 @@ +#ifndef INTELLITOOLPEN_H +#define INTELLITOOLPEN_H + +#include"IntelliTool.h" +#include"QColor" +#include"QPoint" + +class IntelliToolPen : public IntelliTool{ + QColor clr; + QPoint point; +public: + IntelliToolPen(PaintingArea* Area); + virtual ~IntelliToolPen() override; + + virtual void onMouseRightPressed(int x, int y) override; + virtual void onMouseRightReleased(int x, int y) override; + virtual void onMouseLeftPressed(int x, int y) override; + virtual void onMouseLeftReleased(int x, int y) override; + + virtual void onMouseMoved(int x, int y) override; +}; + +#endif // INTELLITOOLPEN_H