mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-12 19:40:28 +02:00
Merge branch 'dev' into 'dev-rework'
# Conflicts: # cppcheck_errors.txt # src/GUI/IntelliPhotoGui.h
This commit is contained in:
@@ -65,8 +65,8 @@ void IntelliPhotoGui::slotSave(){
|
||||
saveFile(fileFormat);
|
||||
}
|
||||
|
||||
// Opens a dialog that allows the user to create a New Layer
|
||||
void IntelliPhotoGui::slotCreateNewLayer(){
|
||||
// Opens a dialog that allows the user to create a New RASTER Layer
|
||||
void IntelliPhotoGui::slotCreateNewRasterLayer(){
|
||||
// Stores button value
|
||||
bool ok1, ok2;
|
||||
|
||||
@@ -85,7 +85,32 @@ void IntelliPhotoGui::slotCreateNewLayer(){
|
||||
200,1, 500, 1, &ok2);
|
||||
// Create New Layer
|
||||
if (ok1&&ok2) {
|
||||
paintingArea->addLayer(width,height,0,0);
|
||||
paintingArea->addLayer(width,height,0,0,IntelliImage::ImageType::RASTERIMAGE);
|
||||
UpdateGui();
|
||||
}
|
||||
}
|
||||
|
||||
// Opens a dialog that allows the user to create a New SHAPED Layer
|
||||
void IntelliPhotoGui::slotCreateNewShapedLayer(){
|
||||
// Stores button value
|
||||
bool ok1, ok2;
|
||||
|
||||
// "New Layer" is the title of the window
|
||||
// the next tr is the text to display
|
||||
// Define the standard Value, min, max, step and ok button
|
||||
QInputDialog Input;
|
||||
Input.setPalette(Palette);
|
||||
|
||||
int width = Input.getInt(this, tr("New Layer"),
|
||||
tr("Width:"),
|
||||
200,1, 500, 1, &ok1);
|
||||
|
||||
int height = QInputDialog::getInt(this, tr("New Layer"),
|
||||
tr("Height:"),
|
||||
200,1, 500, 1, &ok2);
|
||||
// Create New Layer
|
||||
if (ok1&&ok2) {
|
||||
paintingArea->addLayer(width,height,0,0,IntelliImage::ImageType::SHAPEDIMAGE);
|
||||
UpdateGui();
|
||||
}
|
||||
}
|
||||
@@ -129,6 +154,24 @@ void IntelliPhotoGui::slotSetActiveAlpha(){
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotSetPolygon(){
|
||||
// Stores button value
|
||||
bool ok1;
|
||||
|
||||
// "Layer to set on" 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 layer = QInputDialog::getInt(this, tr("Layer to set on"),
|
||||
tr("Layer:"),
|
||||
1,1,500,1, &ok1);
|
||||
|
||||
if (ok1)
|
||||
{
|
||||
paintingArea->setPolygon(layer-1);
|
||||
UpdateGui();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotPositionMoveUp(){
|
||||
paintingArea->movePositionActive(0,-20);
|
||||
update();
|
||||
@@ -159,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;
|
||||
@@ -343,10 +357,16 @@ void IntelliPhotoGui::createActions(){
|
||||
actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
|
||||
connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen()));
|
||||
|
||||
// Create New Layer action and tie to IntelliPhotoGui::newLayer()
|
||||
actionCreateNewLayer = new QAction(tr("&New Layer..."), this);
|
||||
actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
||||
connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer()));
|
||||
// Create New RASTER Layer action and tie to IntelliPhotoGui::newLayer()
|
||||
actionCreateNewRasterLayer = new QAction(tr("&Raster Image"), this);
|
||||
actionCreateNewRasterLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
||||
connect(actionCreateNewRasterLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewRasterLayer()));
|
||||
|
||||
|
||||
// Create New SHAPED Layer action and tie to IntelliPhotoGui::newLayer()
|
||||
actionCreateNewShapedLayer = new QAction(tr("&Shaped Image"), this);
|
||||
actionCreateNewShapedLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N + Qt::ALT));
|
||||
connect(actionCreateNewShapedLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewShapedLayer()));
|
||||
|
||||
// Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
|
||||
actionDeleteLayer = new QAction(tr("&Delete Layer..."), this);
|
||||
@@ -361,6 +381,10 @@ void IntelliPhotoGui::createActions(){
|
||||
actionSetActiveAlpha->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_A));
|
||||
connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha()));
|
||||
|
||||
actionSetPolygon = new QAction(tr("&set new Polygondata"), this);
|
||||
actionSetPolygon->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_P));
|
||||
connect(actionSetPolygon, SIGNAL(triggered()), this, SLOT(slotSetPolygon()));
|
||||
|
||||
actionMovePositionUp = new QAction(tr("&move Up"), this);
|
||||
actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
|
||||
connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp()));
|
||||
@@ -510,12 +534,17 @@ void IntelliPhotoGui::createMenus(){
|
||||
renderMenu->addAction(actionUpdateRenderSettingsOn);
|
||||
renderMenu->addAction(actionUpdateRenderSettingsOff);
|
||||
|
||||
//Attach all Layer Creations to Menu
|
||||
layerCreationMenu = new QMenu(tr("&Create new Layer"), this);
|
||||
layerCreationMenu->addAction(actionCreateNewRasterLayer);
|
||||
layerCreationMenu->addAction(actionCreateNewShapedLayer);
|
||||
// Attach all actions to Layer
|
||||
layerMenu = new QMenu(tr("&Layer"), this);
|
||||
layerMenu->addAction(actionCreateNewLayer);
|
||||
layerMenu->addMenu(layerCreationMenu);
|
||||
layerMenu->addSeparator();
|
||||
layerMenu->addAction(actionSetActiveAlpha);
|
||||
layerMenu->addAction(actionSetActiveLayer);
|
||||
layerMenu->addAction(actionSetPolygon);
|
||||
layerMenu->addSeparator();
|
||||
layerMenu->addAction(actionMovePositionUp);
|
||||
layerMenu->addAction(actionMovePositionDown);
|
||||
@@ -730,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);
|
||||
|
||||
@@ -40,11 +40,13 @@ private slots:
|
||||
void slotOpen();
|
||||
void slotSave();
|
||||
|
||||
void slotCreateNewLayer();
|
||||
// layer slots here
|
||||
void slotCreateNewRasterLayer();
|
||||
void slotCreateNewShapedLayer();
|
||||
void slotDeleteLayer();
|
||||
void slotClearActiveLayer();
|
||||
void slotSetActiveLayer();
|
||||
void slotSetActiveAlpha();
|
||||
void slotSetPolygon();
|
||||
void slotPositionMoveUp();
|
||||
void slotPositionMoveDown();
|
||||
void slotPositionMoveLeft();
|
||||
@@ -123,6 +125,7 @@ QMenu*saveAsMenu;
|
||||
QMenu*fileMenu;
|
||||
QMenu*renderMenu;
|
||||
QMenu*optionMenu;
|
||||
QMenu*layerCreationMenu;
|
||||
QMenu*layerMenu;
|
||||
QMenu*colorMenu;
|
||||
QMenu*toolCreationMenu;
|
||||
@@ -158,10 +161,12 @@ QAction*actionAboutDialog;
|
||||
QAction*actionAboutQtDialog;
|
||||
|
||||
// layer change actions
|
||||
QAction*actionCreateNewLayer;
|
||||
QAction*actionDeleteLayer;
|
||||
QAction* actionCreateNewRasterLayer;
|
||||
QAction* actionCreateNewShapedLayer;
|
||||
QAction* actionDeleteLayer;
|
||||
QAction* actionSetActiveLayer;
|
||||
QAction* actionSetActiveAlpha;
|
||||
QAction* actionSetPolygon;
|
||||
QAction* actionMovePositionUp;
|
||||
QAction* actionMovePositionDown;
|
||||
QAction* actionMovePositionLeft;
|
||||
|
||||
@@ -27,6 +27,9 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){
|
||||
}
|
||||
|
||||
void IntelliShapedImage::calculateVisiblity(){
|
||||
if(polygonData.size()<2) {
|
||||
return;
|
||||
}
|
||||
if(fastRenderering) {
|
||||
this->imageData = imageData.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
@@ -91,6 +94,19 @@ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||
this->polygonData.push_back(QPoint(element.x(), element.y()));
|
||||
}
|
||||
triangles = IntelliTriangulation::calculateTriangles(polygonData);
|
||||
if(fastRenderering) {
|
||||
imageData = imageData.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
for(int y = 0; y<imageData.height(); y++) {
|
||||
for(int x = 0; x<imageData.width(); x++) {
|
||||
QColor clr = imageData.pixelColor(x,y);
|
||||
clr.setAlpha(255);
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
if(fastRenderering) {
|
||||
imageData = imageData.convertToFormat(QImage::Format_Indexed8);
|
||||
}
|
||||
}
|
||||
calculateVisiblity();
|
||||
return;
|
||||
|
||||
@@ -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,6 +93,7 @@ void PaintingArea::slotDeleteActiveLayer(){
|
||||
}
|
||||
|
||||
void PaintingArea::setLayerActive(int idx){
|
||||
updateTools();
|
||||
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
|
||||
this->activeLayer=idx;
|
||||
}
|
||||
@@ -110,6 +104,15 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){
|
||||
layerBundle[static_cast<size_t>(idx)].alpha=alpha;
|
||||
}
|
||||
}
|
||||
void PaintingArea::setPolygon(int idx){
|
||||
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Used to load the image and place it in the widget
|
||||
bool PaintingArea::open(const QString &filePath){
|
||||
@@ -147,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) {
|
||||
@@ -185,13 +166,7 @@ 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;
|
||||
}
|
||||
}
|
||||
updateTools();
|
||||
if(a>=0 && a < static_cast<int>(layerBundle.size())) {
|
||||
this->setLayerActive(a);
|
||||
}
|
||||
@@ -335,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
|
||||
@@ -347,6 +322,7 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){
|
||||
}
|
||||
|
||||
void PaintingArea::selectLayerUp(){
|
||||
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++;
|
||||
@@ -354,6 +330,7 @@ void PaintingArea::selectLayerUp(){
|
||||
}
|
||||
|
||||
void PaintingArea::selectLayerDown(){
|
||||
updateTools();
|
||||
if(activeLayer!=-1 && activeLayer>0) {
|
||||
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]);
|
||||
activeLayer--;
|
||||
@@ -431,5 +408,35 @@ IntelliImage* PaintingArea::getImageOfActiveLayer(){
|
||||
if(activeLayer<0) {
|
||||
return nullptr;
|
||||
}
|
||||
return layerBundle[activeLayer].image;
|
||||
return layerBundle[static_cast<size_t>(activeLayer)].image;
|
||||
}
|
||||
|
||||
QImage PaintingArea::getImageDataOfActiveLayer(){
|
||||
QImage returnImage;
|
||||
if(activeLayer<0) {
|
||||
returnImage = QImage(QSize(10,10),QImage::Format_ARGB32);
|
||||
returnImage.fill(QColor(255,255,255,255));
|
||||
}
|
||||
else{
|
||||
returnImage = layerBundle[static_cast<size_t>(activeLayer)].image->getImageData();
|
||||
if(renderSettings.isFastRenderering()) {
|
||||
returnImage = returnImage.convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,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
|
||||
@@ -113,13 +114,10 @@ void setLayerActive(int idx);
|
||||
*/
|
||||
void setLayerAlpha(int idx, int alpha);
|
||||
/*!
|
||||
* \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
|
||||
* \brief setPolygon is used for setting polygondata, it only works on RASTER images
|
||||
* \param idx - represents the number of the layer with should be transformed
|
||||
*/
|
||||
void floodFill(int r, int g, int b, int a);
|
||||
void setPolygon(int idx);
|
||||
/*!
|
||||
* \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
|
||||
@@ -174,6 +172,12 @@ int getNumberOfActiveLayer();
|
||||
|
||||
IntelliImage* getImageOfActiveLayer();
|
||||
|
||||
/*!
|
||||
* \brief getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer it return a 10*10 white picture)
|
||||
* \return return the image as an rgba32bit qImage
|
||||
*/
|
||||
QImage getImageDataOfActiveLayer();
|
||||
|
||||
IntelliToolsettings Toolsettings;
|
||||
IntelliColorPicker colorPicker;
|
||||
|
||||
@@ -209,6 +213,8 @@ QImage* Canvas;
|
||||
int maxWidth;
|
||||
int maxHeight;
|
||||
|
||||
bool isSettingPolygon = false;
|
||||
|
||||
IntelliRenderSettings renderSettings;
|
||||
IntelliTool* Tool;
|
||||
IntelliPhotoGui* DummyGui;
|
||||
@@ -221,6 +227,9 @@ void drawLayers(bool forSaving=false);
|
||||
void resizeLayer(QImage*image_res, const QSize &newSize);
|
||||
|
||||
bool createTempTopLayer(int idx);
|
||||
|
||||
//this function is needed to avoid errors in inputhandeling if a layer has changed
|
||||
void updateTools();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,6 +36,7 @@ void IntelliTool::onMouseLeftReleased(int x, int y){
|
||||
this->mergeToolLayer();
|
||||
this->deleteToolLayer();
|
||||
activeLayer->image->calculateVisiblity();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,11 +81,14 @@ void IntelliTool::mergeToolLayer(){
|
||||
}
|
||||
}
|
||||
activeLayer->image->setImageData(updatedImage);
|
||||
if(Canvas->image->getPolygonData().size() > 0) {
|
||||
activeLayer->image->setPolygon(Canvas->image->getPolygonData());
|
||||
}
|
||||
Area->DummyGui->UpdateGui();
|
||||
}
|
||||
|
||||
void IntelliTool::deleteToolLayer(){
|
||||
Area->deleteLayer(Area->activeLayer+1);
|
||||
Area->deleteLayer(Area->activeLayer+1, true);
|
||||
this->Canvas=nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
#include <QInputDialog>
|
||||
#include <QDebug>
|
||||
|
||||
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
|
||||
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon)
|
||||
: IntelliTool(Area, colorPicker, Toolsettings){
|
||||
isPointNearStart = false;
|
||||
isDrawing = false;
|
||||
isInside = false;
|
||||
this->isSettingPolygon = isSettingPolygon;
|
||||
this->ActiveType = Tooltype::POLYGON;
|
||||
}
|
||||
|
||||
@@ -20,9 +21,17 @@ 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;
|
||||
}
|
||||
}
|
||||
else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
|
||||
isInside = true;
|
||||
@@ -36,13 +45,17 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
QPointList.push_back(drawingPoint);
|
||||
|
||||
this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
if(!isSettingPolygon) {
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
else if(isDrawing && isNearStart(x,y,QPointList.front())) {
|
||||
if(QPointList.size() > 2) {
|
||||
isPointNearStart = true;
|
||||
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
if(!isSettingPolygon) {
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
else{
|
||||
isInside = false;
|
||||
@@ -56,7 +69,9 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
QPoint drawingPoint(x,y);
|
||||
QPointList.push_back(drawingPoint);
|
||||
this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
if(!isSettingPolygon) {
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,24 +88,31 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
||||
isInside = false;
|
||||
isPointNearStart = false;
|
||||
isDrawing = false;
|
||||
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
|
||||
QPoint Point;
|
||||
QColor colorTwo(colorPicker->getSecondColor());
|
||||
colorTwo.setAlpha(Toolsettings->getInnerAlpha());
|
||||
for(int i = 0; i < activeLayer->width; i++) {
|
||||
for(int j = 0; j < activeLayer->height; j++) {
|
||||
Point = QPoint(i,j);
|
||||
if(IntelliTriangulation::isInPolygon(Triangles,Point)) {
|
||||
this->Canvas->image->drawPixel(Point, colorTwo);
|
||||
if(!isSettingPolygon) {
|
||||
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
|
||||
QPoint Point;
|
||||
QColor colorTwo(colorPicker->getSecondColor());
|
||||
colorTwo.setAlpha(Toolsettings->getInnerAlpha());
|
||||
for(int i = 0; i < activeLayer->width; i++) {
|
||||
for(int j = 0; j < activeLayer->height; j++) {
|
||||
Point = QPoint(i,j);
|
||||
if(IntelliTriangulation::isInPolygon(Triangles,Point)) {
|
||||
this->Canvas->image->drawPixel(Point, colorTwo);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=0; i<static_cast<int>(QPointList.size()); i++) {
|
||||
int next = static_cast<int>((i+static_cast<int>(1))%static_cast<int>(QPointList.size()));
|
||||
this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
|
||||
}
|
||||
|
||||
}
|
||||
for(int i=0; i<static_cast<int>(QPointList.size()); i++) {
|
||||
int next = static_cast<int>((i+static_cast<int>(1))%static_cast<int>(QPointList.size()));
|
||||
this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
|
||||
else{
|
||||
Canvas->image->setPolygon(QPointList);
|
||||
Canvas->image->setImageData(Area->getImageDataOfActiveLayer());
|
||||
}
|
||||
QPointList.clear();
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
QPointList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,11 @@ bool isDrawing;
|
||||
*/
|
||||
bool isInside;
|
||||
|
||||
/*!
|
||||
* \brief isSettingPolygon is the flag for calling the setPolygon method.
|
||||
*/
|
||||
bool isSettingPolygon;
|
||||
|
||||
/*!
|
||||
* \brief PointIsNearStart true, when last click near startpoint, else false.
|
||||
*/
|
||||
@@ -43,8 +48,9 @@ public:
|
||||
* \brief A constructor setting the general paintingArea and colorPicker.
|
||||
* \param Area - The general paintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
* \param isSettingPolygon - The flag for the set polygon method, standart is false
|
||||
*/
|
||||
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
|
||||
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon = false);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
@@ -91,7 +97,6 @@ virtual void onWheelScrolled(int value) override;
|
||||
*/
|
||||
virtual void onMouseMoved(int x, int y) override;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user