FIxed all bugs and removed dead code

my job is done here
ready to be merge
This commit is contained in:
Jan Schuffenhauer
2020-01-15 14:23:14 +01:00
parent f575da20d7
commit 1f0b856079
6 changed files with 53 additions and 94 deletions

View File

@@ -202,35 +202,6 @@ void IntelliPhotoGui::slotMoveLayerDown(){
update();
}
void IntelliPhotoGui::slotClearActiveLayer(){
// Stores button value
bool ok1, ok2, ok3, ok4;
// "Red Input" 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 red = QInputDialog::getInt(this, tr("Red Input"),
tr("Red:"),
255,0, 255,1, &ok1);
// "Green Input" is the title of the window
int green = QInputDialog::getInt(this, tr("Green Input"),
tr("Green:"),
255,0, 255, 1, &ok2);
// "Blue Input" is the title of the window
int blue = QInputDialog::getInt(this, tr("Blue Input"),
tr("Blue:"),
255,0, 255, 1, &ok3);
// "Alpha Input" is the title of the window
int alpha = QInputDialog::getInt(this, tr("Alpha Input"),
tr("Alpha:"),
255,0, 255, 1, &ok4);
if (ok1&&ok2&&ok3&&ok4)
{
paintingArea->floodFill(red, green, blue, alpha);
UpdateGui();
}
}
void IntelliPhotoGui::slotSetActiveLayer(){
// Stores button value
bool ok1;
@@ -788,6 +759,7 @@ void IntelliPhotoGui::setIntelliStyle(){
this->helpMenu->setPalette(Palette);
this->renderMenu->setPalette(Palette);
this->toolMenu->setPalette(Palette);
this->layerCreationMenu->setPalette(Palette);
this->layerMenu->setPalette(Palette);
this->colorMenu->setPalette(Palette);
this->toolCreationMenu->setPalette(Palette);

View File

@@ -47,7 +47,6 @@ void slotSave();
void slotCreateNewRasterLayer();
void slotCreateNewShapedLayer();
void slotDeleteLayer();
void slotClearActiveLayer();
void slotSetActiveLayer();
void slotSetActiveAlpha();
void slotSetPolygon();

View File

@@ -18,24 +18,13 @@
#include "Tool/IntelliToolFloodFill.h"
#include "Tool/IntelliToolPolygon.h"
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
: QWidget(parent){
this->Tool = nullptr;
this->setLayerDimensions(maxWidth, maxHeight);
this->addLayer(200,200,0,0,IntelliImage::ImageType::SHAPEDIMAGE);
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
std::vector<QPoint> polygon;
polygon.push_back(QPoint(100,000));
polygon.push_back(QPoint(200,100));
polygon.push_back(QPoint(100,200));
polygon.push_back(QPoint(000,100));
layerBundle[0].image->setPolygon(polygon);
this->addLayer(200,200,150,150,IntelliImage::ImageType::RASTERIMAGE);
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
layerBundle[1].alpha=200;
activeLayer=0;
activeLayer=-1;
}
PaintingArea::~PaintingArea(){
@@ -64,6 +53,7 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){
LayerObject newLayer;
updateTools();
newLayer.width = width;
newLayer.height = height;
newLayer.widthOffset = widthOffset;
@@ -80,7 +70,10 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff
}
void PaintingArea::deleteLayer(int idx){
void PaintingArea::deleteLayer(int idx, bool isTool){
if(!isTool){
updateTools();
}
if(idx<static_cast<int>(layerBundle.size())) {
this->layerBundle.erase(layerBundle.begin()+idx);
if(activeLayer>=idx) {
@@ -100,7 +93,8 @@ void PaintingArea::slotDeleteActiveLayer(){
}
void PaintingArea::setLayerActive(int idx){
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
updateTools();
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
this->activeLayer=idx;
}
}
@@ -115,6 +109,7 @@ void PaintingArea::setPolygon(int idx){
if(layerBundle[static_cast<size_t>(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){
delete this->Tool;
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
isSettingPolygon = true;
}
}
}
@@ -155,36 +150,14 @@ bool PaintingArea::save(const QString &filePath, const char*fileFormat){
}
}
// Color the image area with white
void PaintingArea::floodFill(int r, int g, int b, int a){
if(this->activeLayer==-1) {
return;
}
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
active->drawPlain(QColor(r, g, b, a));
update();
}
void PaintingArea::movePositionActive(int x, int y){
if(Tool!=nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
updateTools();
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
}
void PaintingArea::moveActiveLayer(int idx){
if(Tool != nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
updateTools();
if(idx==1) {
this->selectLayerUp();
}else if(idx==-1) {
@@ -193,14 +166,8 @@ void PaintingArea::moveActiveLayer(int idx){
}
void PaintingArea::slotActivateLayer(int a){
if(Tool != nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
if(a>=0 && a < static_cast<int>(layerBundle.size())) {
updateTools();
if(a>=0 && a < static_cast<int>(layerBundle.size())) {
this->setLayerActive(a);
}
}
@@ -343,7 +310,7 @@ void PaintingArea::paintEvent(QPaintEvent*event){
update();
}
// Resize the image to slightly larger then the main window
//TODOJ Resize the image to slightly larger then the main window
// to cut down on the need to resize the image
void PaintingArea::resizeEvent(QResizeEvent*event){
//TODO wait till tool works
@@ -355,14 +322,16 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){
}
void PaintingArea::selectLayerUp(){
if(activeLayer!=-1 && static_cast<unsigned long long>(activeLayer)<layerBundle.size()-1) {
updateTools();
if(activeLayer!=-1 && static_cast<unsigned long long>(activeLayer)<layerBundle.size()-1) {
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer+1)]);
activeLayer++;
}
}
void PaintingArea::selectLayerDown(){
if(activeLayer!=-1 && activeLayer>0) {
updateTools();
if(activeLayer!=-1 && activeLayer>0) {
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]);
activeLayer--;
}
@@ -456,3 +425,18 @@ QImage PaintingArea::getImageDataOfActiveLayer(){
}
return returnImage;
}
void PaintingArea::updateTools(){
if(Tool!=nullptr) {
if(Tool->getIsDrawing()){
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
if(isSettingPolygon){
delete this->Tool;
this->Tool = nullptr;
isSettingPolygon = false;
}
}
}

View File

@@ -102,8 +102,9 @@ int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffs
/*!
* \brief The deleteLayer method removes a layer at a given idx
* \param idx - The index of the layer to be removed
* \param isTool - Is the flag for when a tool uses this function.
*/
void deleteLayer(int idx);
void deleteLayer(int idx, bool isTool = false);
/*!
* \brief The setLayerToActive method marks a specific layer as active
* \param idx - The index of the layer to be active
@@ -120,14 +121,6 @@ void setLayerAlpha(int idx, int alpha);
* \param idx - represents the number of the layer with should be transformed
*/
void setPolygon(int idx);
/*!
* \brief The floodFill method fills a the active layer with a given color
* \param r - Red value of the color the layer should be filled with
* \param g - Green value of the color the layer should be filled with
* \param b - Blue value of the color the layer should be filled with
* \param a - Alpha value of the color the layer should be filled with
*/
void floodFill(int r, int g, int b, int a);
/*!
* \brief The movePositionActive method moves the active layer to certain position
* \param x - The x value the new center of the layer should be at
@@ -226,6 +219,8 @@ QImage* Canvas;
int maxWidth;
int maxHeight;
bool isSettingPolygon = false;
IntelliRenderSettings renderSettings;
IntelliTool* Tool;
IntelliPhotoGui* DummyGui;
@@ -239,6 +234,9 @@ void resizeLayer(QImage*image_res, const QSize &newSize);
// Helper for Tool
bool createTempTopLayer(int idx);
//this function is needed to avoid errors in inputhandeling if a layer has changed
void updateTools();
};
#endif

View File

@@ -32,10 +32,11 @@ void IntelliTool::onMouseLeftPressed(int x, int y){
void IntelliTool::onMouseLeftReleased(int x, int y){
if(isDrawing) {
isDrawing=false;
isDrawing=false;
this->mergeToolLayer();
this->deleteToolLayer();
activeLayer->image->calculateVisiblity();
}
}
@@ -87,7 +88,7 @@ void IntelliTool::mergeToolLayer(){
}
void IntelliTool::deleteToolLayer(){
Area->deleteLayer(Area->activeLayer+1);
Area->deleteLayer(Area->activeLayer+1, true);
this->Canvas=nullptr;
}

View File

@@ -21,9 +21,14 @@ IntelliToolPolygon::~IntelliToolPolygon(){
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
QPoint Point(x,y);
isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
if(Area->getPolygonDataOfRealLayer().size()>2){
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
QPoint Point(x,y);
isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
}
else{
isInside = true;
}
if(isSettingPolygon){
isInside = true;
}