Merge branch 'BugFixes' into 'dev'

Bug fixes

See merge request creyd/intelliphoto!26
This commit is contained in:
Bastian Schindler
2020-01-07 15:05:47 +00:00
13 changed files with 98 additions and 26 deletions

View File

@@ -402,13 +402,13 @@ void IntelliPhotoGui::createMenus(){
//Attach all Tool Options
toolMenu = new QMenu(tr("&Tools"), this);
toolMenu->addAction(actionCreateCircleTool);
toolMenu->addAction(actionCreateFloodFillTool);
toolMenu->addAction(actionCreateLineTool);
toolMenu->addAction(actionCreatePenTool);
toolMenu->addAction(actionCreatePlainTool);
toolMenu->addAction(actionCreateLineTool);
toolMenu->addAction(actionCreatePolygonTool);
toolMenu->addAction(actionCreateRectangleTool);
toolMenu->addAction(actionCreateCircleTool);
toolMenu->addAction(actionCreatePolygonTool);
toolMenu->addAction(actionCreateFloodFillTool);
toolMenu->addSeparator();
toolMenu->addMenu(colorMenu);

View File

@@ -20,7 +20,7 @@
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
: QWidget(parent){
this->Tool = nullptr;
this->Tool = nullptr;
this->setLayerDimensions(maxWidth, maxHeight);
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
@@ -145,11 +145,21 @@ void PaintingArea::floodFill(int r, int g, int b, int a){
}
void PaintingArea::movePositionActive(int x, int y){
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
if(Tool->getIsDrawing()){
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
}
void PaintingArea::moveActiveLayer(int idx){
if(Tool->getIsDrawing()){
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
if(idx==1) {
this->selectLayerUp();
}else if(idx==-1) {
@@ -158,6 +168,11 @@ void PaintingArea::moveActiveLayer(int idx){
}
void PaintingArea::slotActivateLayer(int a){
if(Tool->getIsDrawing()){
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
if(a>=0 && a < static_cast<int>(layerBundle.size())) {
this->setLayerActive(a);
}
@@ -262,11 +277,13 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){
}
void PaintingArea::wheelEvent(QWheelEvent*event){
QPoint numDegrees = event->angleDelta() / 8;
if(!numDegrees.isNull()) {
QPoint numSteps = numDegrees / 15;
Tool->onWheelScrolled(numSteps.y()* -1);
}
if(this->Tool != nullptr){
QPoint numDegrees = event->angleDelta() / 8;
if(!numDegrees.isNull()) {
QPoint numSteps = numDegrees / 15;
Tool->onWheelScrolled(numSteps.y()* -1);
}
}
}
// QPainter provides functions to draw on the widget
@@ -353,3 +370,16 @@ void PaintingArea::createTempTopLayer(int idx){
layerBundle.insert(layerBundle.begin()+idx+1,newLayer);
}
}
IntelliTool* PaintingArea::copyActiveTool(){
switch(Tool->getTooltype()){
case IntelliTool::Tooltype::CIRCLE: return new IntelliToolCircle(this,&colorPicker);
case IntelliTool::Tooltype::FLOODFILL: return new IntelliToolFloodFill(this,&colorPicker);
case IntelliTool::Tooltype::LINE: return new IntelliToolLine(this,&colorPicker);
case IntelliTool::Tooltype::PEN: return new IntelliToolPen(this,&colorPicker);
case IntelliTool::Tooltype::PLAIN: return new IntelliToolPlainTool(this,&colorPicker);
case IntelliTool::Tooltype::POLYGON: return new IntelliToolPolygon(this,&colorPicker);
case IntelliTool::Tooltype::RECTANGLE: return new IntelliToolRectangle(this,&colorPicker);
default: return nullptr;
}
}

View File

@@ -190,6 +190,7 @@ private:
void setLayerDimensions(int maxWidth, int maxHeight);
void selectLayerUp();
void selectLayerDown();
IntelliTool* copyActiveTool();
QImage* Canvas;
int maxWidth;

View File

@@ -79,3 +79,11 @@ void IntelliTool::deleteToolLayer(){
Area->deleteLayer(Area->activeLayer+1);
this->Canvas=nullptr;
}
IntelliTool::Tooltype IntelliTool::getTooltype(){
return ActiveType;
}
bool IntelliTool::getIsDrawing(){
return isDrawing;
}

View File

@@ -11,6 +11,16 @@ class PaintingArea;
* \brief An abstract class that manages the basic events, like mouse clicks or scrolls events.
*/
class IntelliTool {
public:
enum class Tooltype{
CIRCLE,
FLOODFILL,
LINE,
PEN,
PLAIN,
POLYGON,
RECTANGLE
};
private:
/*!
* \brief A function that creates a layer to draw on.
@@ -32,6 +42,8 @@ protected:
*/
PaintingArea* Area;
Tooltype ActiveType;
/*!
* \brief A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
*/
@@ -106,6 +118,9 @@ virtual void onWheelScrolled(int value);
*/
virtual void onMouseMoved(int x, int y);
Tooltype getTooltype();
bool getIsDrawing();
};
#endif

View File

@@ -7,10 +7,11 @@ IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* col
: IntelliTool(Area, colorPicker){
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
this->ActiveType = Tooltype::CIRCLE;
}
IntelliToolCircle::~IntelliToolCircle(){
IntelliTool::onMouseRightPressed(0,0);
}
void IntelliToolCircle::drawCircle(int radius){

View File

@@ -7,10 +7,11 @@
IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
this->ActiveType = Tooltype::FLOODFILL;
}
IntelliToolFloodFill::~IntelliToolFloodFill(){
IntelliTool::onMouseRightPressed(0,0);
}
void IntelliToolFloodFill::onMouseRightPressed(int x, int y){

View File

@@ -6,12 +6,13 @@
IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);
this->ActiveType = Tooltype::LINE;
//create checkbox or scroll dialog to get line style
this->lineStyle = LineStyle::SOLID_LINE;
}
IntelliToolLine::~IntelliToolLine(){
IntelliTool::onMouseRightPressed(0,0);
}
void IntelliToolLine::onMouseRightPressed(int x, int y){

View File

@@ -7,10 +7,11 @@
IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1);
this->ActiveType = Tooltype::PEN;
}
IntelliToolPen::~IntelliToolPen(){
IntelliTool::onMouseRightPressed(0,0);
}
void IntelliToolPen::onMouseRightPressed(int x, int y){

View File

@@ -4,6 +4,7 @@
#include "IntelliTool.h"
#include "QColor"
#include "QPoint"
/*!
* \brief The IntelliToolPen class represents a tool to draw a line.
*/

View File

@@ -4,10 +4,11 @@
IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
this->ActiveType = Tooltype::PLAIN;
}
IntelliToolPlainTool::~IntelliToolPlainTool(){
IntelliTool::onMouseRightPressed(0,0);
}
void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){

View File

@@ -5,15 +5,18 @@
#include <QInputDialog>
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);
: IntelliTool(Area, colorPicker){
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 255,0,255,1);
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",5,1,10,1);
isPointNearStart = false;
isDrawing = false;
this->ActiveType = Tooltype::POLYGON;
}
IntelliToolPolygon::~IntelliToolPolygon(){
if(isDrawing){
IntelliTool::onMouseRightPressed(0,0);
}
}
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
@@ -28,9 +31,17 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
this->Canvas->image->calculateVisiblity();
}
else if(isDrawing && isNearStart(x,y,QPointList.front())) {
isPointNearStart = true;
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
this->Canvas->image->calculateVisiblity();
if(QPointList.size() > 2){
isPointNearStart = true;
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
this->Canvas->image->calculateVisiblity();
}
else{
isDrawing = false;
QPointList.clear();
IntelliTool::onMouseRightPressed(x,y);
}
}
else if(isDrawing) {
QPoint drawingPoint(x,y);
@@ -48,7 +59,7 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){
}
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
if(isPointNearStart && QPointList.size() > 1) {
if(isPointNearStart) {
isPointNearStart = false;
isDrawing = false;
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
@@ -96,7 +107,7 @@ bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
bool isNear = false;
int StartX = Startpoint.x();
int StartY = Startpoint.y();
int valueToNear = 10;
int valueToNear = 5;
for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) {
for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) {

View File

@@ -6,10 +6,11 @@ IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicke
: IntelliTool(Area, colorPicker){
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
this->ActiveType = Tooltype::RECTANGLE;
}
IntelliToolRectangle::~IntelliToolRectangle(){
IntelliTool::onMouseRightPressed(0,0);
}
void IntelliToolRectangle::drawRectangle(QPoint otherCorner){