mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-15 21:00:37 +02:00
Tool structure- input bug
This commit is contained in:
@@ -133,22 +133,22 @@ void IntelliPhotoGui::slotSetActiveAlpha(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotPositionMoveUp(){
|
void IntelliPhotoGui::slotPositionMoveUp(){
|
||||||
paintingArea->movePositionActive(0,-2);
|
paintingArea->movePositionActive(0,-20);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotPositionMoveDown(){
|
void IntelliPhotoGui::slotPositionMoveDown(){
|
||||||
paintingArea->movePositionActive(0,2);
|
paintingArea->movePositionActive(0,20);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotPositionMoveLeft(){
|
void IntelliPhotoGui::slotPositionMoveLeft(){
|
||||||
paintingArea->movePositionActive(-2,0);
|
paintingArea->movePositionActive(-20,0);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotPositionMoveRight(){
|
void IntelliPhotoGui::slotPositionMoveRight(){
|
||||||
paintingArea->movePositionActive(2,0);
|
paintingArea->movePositionActive(20,0);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,10 +269,6 @@ void IntelliPhotoGui::createActions()
|
|||||||
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()));
|
||||||
|
|
||||||
// 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);
|
actionFloodFill = new QAction(tr("&clear Image"), this);
|
||||||
connect(actionFloodFill, SIGNAL(triggered()), this, SLOT(slotClearActiveLayer()));
|
connect(actionFloodFill, SIGNAL(triggered()), this, SLOT(slotClearActiveLayer()));
|
||||||
|
|
||||||
@@ -347,7 +343,6 @@ void IntelliPhotoGui::createMenus()
|
|||||||
layerMenu = new QMenu(tr("&Layer"), this);
|
layerMenu = new QMenu(tr("&Layer"), this);
|
||||||
layerMenu->addAction(actionCreateNewLayer);
|
layerMenu->addAction(actionCreateNewLayer);
|
||||||
layerMenu->addAction(actionDeleteLayer);
|
layerMenu->addAction(actionDeleteLayer);
|
||||||
layerMenu->addAction(actionDeleteActiveLayer);
|
|
||||||
|
|
||||||
//Attach all Tool Options
|
//Attach all Tool Options
|
||||||
toolMenu = new QMenu(tr("&Tools"), this);
|
toolMenu = new QMenu(tr("&Tools"), this);
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ private:
|
|||||||
|
|
||||||
QAction *actionCreateNewLayer;
|
QAction *actionCreateNewLayer;
|
||||||
QAction *actionDeleteLayer;
|
QAction *actionDeleteLayer;
|
||||||
QAction *actionDeleteActiveLayer;
|
|
||||||
|
|
||||||
QAction *actionAboutDialog;
|
QAction *actionAboutDialog;
|
||||||
QAction *actionAboutQtDialog;
|
QAction *actionAboutQtDialog;
|
||||||
|
|||||||
@@ -50,9 +50,6 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
|
|||||||
|
|
||||||
// Draw a line from the last registered point to the current
|
// Draw a line from the last registered point to the current
|
||||||
painter.drawPoint(p1);
|
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){
|
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){
|
void IntelliImage::floodFill(const QColor& color){
|
||||||
imageData.fill(color);
|
imageData.fill(color);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
|
|||||||
for(int y = 0; y<copy.height(); y++){
|
for(int y = 0; y<copy.height(); y++){
|
||||||
for(int x = 0; x<copy.width(); x++){
|
for(int x = 0; x<copy.width(); x++){
|
||||||
QColor clr = copy.pixelColor(x,y);
|
QColor clr = copy.pixelColor(x,y);
|
||||||
clr.setAlpha(alpha);
|
clr.setAlpha(std::min(alpha, clr.alpha()));
|
||||||
copy.setPixelColor(x,y, clr);
|
copy.setPixelColor(x,y, clr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ SOURCES += \
|
|||||||
IntelliHelper/IntelliHelper.cpp \
|
IntelliHelper/IntelliHelper.cpp \
|
||||||
Layer/PaintingArea.cpp \
|
Layer/PaintingArea.cpp \
|
||||||
Tool/IntelliTool.cpp \
|
Tool/IntelliTool.cpp \
|
||||||
|
Tool/IntelliToolPen.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
@@ -32,7 +33,8 @@ HEADERS += \
|
|||||||
Image/IntelliShapedImage.h \
|
Image/IntelliShapedImage.h \
|
||||||
IntelliHelper/IntelliHelper.h \
|
IntelliHelper/IntelliHelper.h \
|
||||||
Layer/PaintingArea.h \
|
Layer/PaintingArea.h \
|
||||||
Tool/IntelliTool.h
|
Tool/IntelliTool.h \
|
||||||
|
Tool/IntelliToolPen.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
widget.ui
|
widget.ui
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
// ---------- PaintingArea.cpp ----------
|
// ---------- PaintingArea.cpp ----------
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
#include <QPoint>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include "string.h"
|
|
||||||
#include "PaintingArea.h"
|
#include "PaintingArea.h"
|
||||||
#include "Image/IntelliRasterImage.h"
|
#include "Image/IntelliRasterImage.h"
|
||||||
#include "Image/IntelliShapedImage.h"
|
#include "Image/IntelliShapedImage.h"
|
||||||
|
#include "Tool/IntelliToolPen.h"
|
||||||
#include <vector>
|
|
||||||
#include <QPoint>
|
|
||||||
|
|
||||||
|
|
||||||
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
||||||
:QWidget(parent){
|
:QWidget(parent){
|
||||||
|
this->Tool = new IntelliToolPen(this);
|
||||||
this->setUp(maxWidth, maxHeight);
|
this->setUp(maxWidth, maxHeight);
|
||||||
//tetsing
|
//tetsing
|
||||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
||||||
@@ -160,7 +163,13 @@ void PaintingArea::slotActivateLayer(int a){
|
|||||||
// Set that we are currently drawing
|
// Set that we are currently drawing
|
||||||
void PaintingArea::mousePressEvent(QMouseEvent *event)
|
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
|
// from the last position to the current
|
||||||
void PaintingArea::mouseMoveEvent(QMouseEvent *event)
|
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
|
// If the button is released we set variables to stop drawing
|
||||||
void PaintingArea::mouseReleaseEvent(QMouseEvent *event)
|
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
|
// QPainter provides functions to draw on the widget
|
||||||
@@ -235,7 +252,7 @@ void PaintingArea::assembleLayers(bool forSaving){
|
|||||||
if(layer.hightOffset+y>=maxHeight) break;
|
if(layer.hightOffset+y>=maxHeight) break;
|
||||||
for(int x=0; x<layer.width; x++){
|
for(int x=0; x<layer.width; x++){
|
||||||
if(layer.widthOffset+x<0) continue;
|
if(layer.widthOffset+x<0) continue;
|
||||||
if(layer.hightOffset+y>=maxWidth) break;
|
if(layer.widthOffset+x>=maxWidth) break;
|
||||||
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.hightOffset+y);
|
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.hightOffset+y);
|
||||||
clr_1=cpy.pixelColor(x,y);
|
clr_1=cpy.pixelColor(x,y);
|
||||||
float t = static_cast<float>(clr_1.alpha())/255.f;
|
float t = static_cast<float>(clr_1.alpha())/255.f;
|
||||||
@@ -257,7 +274,7 @@ void PaintingArea::assembleLayers(bool forSaving){
|
|||||||
void PaintingArea::createTempLayerAfter(int idx){
|
void PaintingArea::createTempLayerAfter(int idx){
|
||||||
if(idx>=0){
|
if(idx>=0){
|
||||||
LayerObject newLayer;
|
LayerObject newLayer;
|
||||||
newLayer.alpha = layerBundle[idx].alpha;
|
newLayer.alpha = 255;
|
||||||
newLayer.hight = layerBundle[idx].hight;
|
newLayer.hight = layerBundle[idx].hight;
|
||||||
newLayer.width = layerBundle[idx].width;
|
newLayer.width = layerBundle[idx].width;
|
||||||
newLayer.hightOffset = layerBundle[idx].hightOffset;
|
newLayer.hightOffset = layerBundle[idx].hightOffset;
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include"Image/IntelliImage.h"
|
|
||||||
#include"Tool/IntelliTool.h"
|
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include"Image/IntelliImage.h"
|
||||||
|
#include"Tool/IntelliTool.h"
|
||||||
|
|
||||||
|
|
||||||
struct LayerObject{
|
struct LayerObject{
|
||||||
@@ -77,6 +77,8 @@ private:
|
|||||||
int maxWidth;
|
int maxWidth;
|
||||||
int maxHeight;
|
int maxHeight;
|
||||||
|
|
||||||
|
IntelliTool* Tool;
|
||||||
|
|
||||||
std::vector<LayerObject> layerBundle;
|
std::vector<LayerObject> layerBundle;
|
||||||
int activeLayer=-1;
|
int activeLayer=-1;
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,24 @@ IntelliTool::~IntelliTool(){
|
|||||||
|
|
||||||
|
|
||||||
void IntelliTool::onMouseRightPressed(int x, int y){
|
void IntelliTool::onMouseRightPressed(int x, int y){
|
||||||
this->drawing=true;
|
if(drawing){
|
||||||
//create drawing layer
|
drawing=false;
|
||||||
this->createToolLayer();
|
this->deleteToolLayer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliTool::onMouseRightReleased(int x, int y){
|
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){
|
if(drawing){
|
||||||
drawing=false;
|
drawing=false;
|
||||||
this->mergeToolLayer();
|
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){
|
void IntelliTool::onMouseMoved(int x, int y){
|
||||||
//optional for tool
|
//optional for tool
|
||||||
}
|
}
|
||||||
|
|||||||
42
src/Painting/Tool/IntelliToolPen.cpp
Normal file
42
src/Painting/Tool/IntelliToolPen.cpp
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/Painting/Tool/IntelliToolPen.h
Normal file
23
src/Painting/Tool/IntelliToolPen.h
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user