mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-12 19:40:28 +02:00
Merge branch 'dev-variable-refractor' into dev
This commit is contained in:
@@ -206,8 +206,8 @@ void IntelliPhotoGui::slotSetSecondColor(){
|
||||
paintingArea->colorPickerSetSecondColor();
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotSwitchColor(){
|
||||
paintingArea->colorPickerSwitchColor();
|
||||
void IntelliPhotoGui::slotSwapColor(){
|
||||
paintingArea->colorPickerSwapColors();
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotCreatePenTool(){
|
||||
@@ -328,9 +328,9 @@ void IntelliPhotoGui::createActions(){
|
||||
actionColorPickerSecondColor = new QAction(tr("&Secondary"), this);
|
||||
connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetSecondColor()));
|
||||
|
||||
actionColorSwitch = new QAction(tr("&Switch"), this);
|
||||
actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
|
||||
connect(actionColorSwitch, SIGNAL(triggered()), this, SLOT(slotSwitchColor()));
|
||||
actionColorSwap = new QAction(tr("&Switch"), this);
|
||||
actionColorSwap->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
|
||||
connect(actionColorSwap, SIGNAL(triggered()), this, SLOT(slotSwapColor()));
|
||||
|
||||
//Create Tool actions down here
|
||||
actionCreatePlainTool = new QAction(tr("&Plain"), this);
|
||||
@@ -398,7 +398,7 @@ void IntelliPhotoGui::createMenus(){
|
||||
colorMenu = new QMenu(tr("&Color"), this);
|
||||
colorMenu->addAction(actionColorPickerFirstColor);
|
||||
colorMenu->addAction(actionColorPickerSecondColor);
|
||||
colorMenu->addAction(actionColorSwitch);
|
||||
colorMenu->addAction(actionColorSwap);
|
||||
|
||||
//Attach all Tool Options
|
||||
toolMenu = new QMenu(tr("&Tools"), this);
|
||||
|
||||
@@ -55,7 +55,7 @@ void slotMoveLayerDown();
|
||||
// color Picker slots here
|
||||
void slotSetFirstColor();
|
||||
void slotSetSecondColor();
|
||||
void slotSwitchColor();
|
||||
void slotSwapColor();
|
||||
|
||||
// tool slots here
|
||||
void slotCreatePenTool();
|
||||
@@ -103,7 +103,7 @@ QAction*actionExit;
|
||||
// color Picker actions
|
||||
QAction*actionColorPickerFirstColor;
|
||||
QAction*actionColorPickerSecondColor;
|
||||
QAction*actionColorSwitch;
|
||||
QAction*actionColorSwap;
|
||||
|
||||
// tool actions
|
||||
QAction*actionCreatePenTool;
|
||||
|
||||
@@ -11,12 +11,12 @@ IntelliImage::~IntelliImage(){
|
||||
|
||||
}
|
||||
|
||||
bool IntelliImage::loadImage(const QString &fileName){
|
||||
bool IntelliImage::loadImage(const QString &filePath){
|
||||
// Holds the image
|
||||
QImage loadedImage;
|
||||
|
||||
// If the image wasn't loaded leave this function
|
||||
if (!loadedImage.load(fileName))
|
||||
if (!loadedImage.load(filePath))
|
||||
return false;
|
||||
|
||||
// scaled Image to size of Layer
|
||||
|
||||
@@ -33,10 +33,10 @@ QImage imageData;
|
||||
public:
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param width - The width of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliImage(int weight, int height);
|
||||
IntelliImage(int width, int height);
|
||||
|
||||
/*!
|
||||
* \brief An Abstract Destructor.
|
||||
@@ -91,7 +91,7 @@ virtual QImage getDisplayable(int alpha=255) = 0;
|
||||
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
* \return An [allocated] image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() = 0;
|
||||
|
||||
@@ -116,10 +116,10 @@ virtual std::vector<QPoint> getPolygonData(){
|
||||
|
||||
/*!
|
||||
* \brief A function that loads and sclaes an image to the fitting dimensions.
|
||||
* \param fileName - The path+name of the image which to loaded.
|
||||
* \param filePath - The path+name of the image which to loaded.
|
||||
* \return True if the image could be loaded, false otherwise.
|
||||
*/
|
||||
virtual bool loadImage(const QString &fileName);
|
||||
virtual bool loadImage(const QString &filePath);
|
||||
|
||||
/*!
|
||||
* \brief A function that returns the pixelcolor at a certain point
|
||||
|
||||
@@ -16,10 +16,10 @@ virtual void calculateVisiblity() override;
|
||||
public:
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliRasterImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param width - The width of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliRasterImage(int weight, int height);
|
||||
IntelliRasterImage(int width, int height);
|
||||
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
|
||||
@@ -29,10 +29,10 @@ std::vector<QPoint> polygonData;
|
||||
public:
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliShapedImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param width - The width of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliShapedImage(int weight, int height);
|
||||
IntelliShapedImage(int width, int height);
|
||||
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
|
||||
@@ -9,7 +9,7 @@ IntelliColorPicker::~IntelliColorPicker(){
|
||||
|
||||
}
|
||||
|
||||
void IntelliColorPicker::switchColors(){
|
||||
void IntelliColorPicker::swapColors(){
|
||||
std::swap(firstColor, secondColor);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ virtual ~IntelliColorPicker();
|
||||
/*!
|
||||
* \brief A function switching primary and secondary color.
|
||||
*/
|
||||
void switchColors();
|
||||
void swapColors();
|
||||
|
||||
/*!
|
||||
* \brief A function to read the primary selected color.
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
|
||||
: QWidget(parent){
|
||||
this->Tool = nullptr;
|
||||
this->setUp(maxWidth, maxHeight);
|
||||
this->setLayerDimensions(maxWidth, maxHeight);
|
||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
||||
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
|
||||
std::vector<QPoint> polygon;
|
||||
@@ -42,7 +42,7 @@ PaintingArea::~PaintingArea(){
|
||||
delete Tool;
|
||||
}
|
||||
|
||||
void PaintingArea::setUp(int maxWidth, int maxHeight){
|
||||
void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
|
||||
//set standart parameter
|
||||
this->maxWidth = maxWidth;
|
||||
this->maxHeight = maxHeight;
|
||||
@@ -99,35 +99,35 @@ void PaintingArea::setAlphaOfLayer(int index, int alpha){
|
||||
}
|
||||
|
||||
// Used to load the image and place it in the widget
|
||||
bool PaintingArea::open(const QString &fileName){
|
||||
bool PaintingArea::open(const QString &filePath){
|
||||
if(this->activeLayer==-1) {
|
||||
return false;
|
||||
}
|
||||
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
|
||||
bool open = active->loadImage(fileName);
|
||||
bool open = active->loadImage(filePath);
|
||||
active->calculateVisiblity();
|
||||
update();
|
||||
return open;
|
||||
}
|
||||
|
||||
// Save the current image
|
||||
bool PaintingArea::save(const QString &fileName, const char*fileFormat){
|
||||
bool PaintingArea::save(const QString &filePath, const char*fileFormat){
|
||||
if(layerBundle.size()==0) {
|
||||
return false;
|
||||
}
|
||||
this->assembleLayers(true);
|
||||
this->drawLayers(true);
|
||||
|
||||
if(!strcmp(fileFormat,"PNG")) {
|
||||
QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
|
||||
fileFormat = "png";
|
||||
if (visibleImage.save(fileName, fileFormat)) {
|
||||
if (visibleImage.save(filePath, fileFormat)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Canvas->save(fileName, fileFormat)) {
|
||||
if (Canvas->save(filePath, fileFormat)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -151,9 +151,9 @@ void PaintingArea::movePositionActive(int x, int y){
|
||||
|
||||
void PaintingArea::moveActiveLayer(int idx){
|
||||
if(idx==1) {
|
||||
this->activateUpperLayer();
|
||||
this->selectLayerUp();
|
||||
}else if(idx==-1) {
|
||||
this->activateLowerLayer();
|
||||
this->selectLayerDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,8 +173,8 @@ void PaintingArea::colorPickerSetSecondColor(){
|
||||
this->colorPicker.setSecondColor(clr);
|
||||
}
|
||||
|
||||
void PaintingArea::colorPickerSwitchColor(){
|
||||
this->colorPicker.switchColors();
|
||||
void PaintingArea::colorPickerSwapColors(){
|
||||
this->colorPicker.swapColors();
|
||||
}
|
||||
|
||||
void PaintingArea::createPenTool(){
|
||||
@@ -273,7 +273,7 @@ void PaintingArea::wheelEvent(QWheelEvent*event){
|
||||
// The QPaintEvent is sent to widgets that need to
|
||||
// update themselves
|
||||
void PaintingArea::paintEvent(QPaintEvent*event){
|
||||
this->assembleLayers();
|
||||
this->drawLayers();
|
||||
|
||||
QPainter painter(this);
|
||||
QRect dirtyRec = event->rect();
|
||||
@@ -288,25 +288,25 @@ void PaintingArea::resizeEvent(QResizeEvent*event){
|
||||
update();
|
||||
}
|
||||
|
||||
void PaintingArea::resizeImage(QImage*image_res, const QSize &newSize){
|
||||
void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){
|
||||
//TODO implement
|
||||
}
|
||||
|
||||
void PaintingArea::activateUpperLayer(){
|
||||
void PaintingArea::selectLayerUp(){
|
||||
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::activateLowerLayer(){
|
||||
void PaintingArea::selectLayerDown(){
|
||||
if(activeLayer!=-1 && activeLayer>0) {
|
||||
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]);
|
||||
activeLayer--;
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::assembleLayers(bool forSaving){
|
||||
void PaintingArea::drawLayers(bool forSaving){
|
||||
if(forSaving) {
|
||||
Canvas->fill(Qt::GlobalColor::transparent);
|
||||
}else{
|
||||
@@ -341,7 +341,7 @@ void PaintingArea::assembleLayers(bool forSaving){
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::createTempLayerAfter(int idx){
|
||||
void PaintingArea::createTempTopLayer(int idx){
|
||||
if(idx>=0) {
|
||||
LayerObject newLayer;
|
||||
newLayer.alpha = 255;
|
||||
|
||||
@@ -61,14 +61,14 @@ public:
|
||||
* \param fileName - Path and filename which are used to determine where the to-be-opened file is stored
|
||||
* \return Returns a boolean variable whether the file was successfully opened or not
|
||||
*/
|
||||
bool open(const QString &fileName);
|
||||
bool open(const QString &filePath);
|
||||
/*!
|
||||
* \brief The save method is used for exporting the current project as one picture
|
||||
* \param fileName
|
||||
* \param fileFormat
|
||||
* \return Returns a boolean variable, true if the file was saved successfully, false if not
|
||||
*/
|
||||
bool save(const QString &fileName, const char *fileFormat);
|
||||
bool save(const QString &filePath, const char *fileFormat);
|
||||
|
||||
/*!
|
||||
* \brief The addLayer adds a layer to the current project/ painting area
|
||||
@@ -139,7 +139,7 @@ public:
|
||||
/*!
|
||||
* \brief The colorPickerSwitchColor swaps the primary color with the secondary drawing color
|
||||
*/
|
||||
void colorPickerSwitchColor();
|
||||
void colorPickerSwapColors();
|
||||
|
||||
// Create tools
|
||||
void createPenTool();
|
||||
@@ -187,9 +187,9 @@ protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private:
|
||||
void setUp(int maxWidth, int maxHeight);
|
||||
void activateUpperLayer();
|
||||
void activateLowerLayer();
|
||||
void setLayerDimensions(int maxWidth, int maxHeight);
|
||||
void selectLayerUp();
|
||||
void selectLayerDown();
|
||||
|
||||
QImage* Canvas;
|
||||
int maxWidth;
|
||||
@@ -201,12 +201,13 @@ private:
|
||||
std::vector<LayerObject> layerBundle;
|
||||
int activeLayer=-1;
|
||||
|
||||
void assembleLayers(bool forSaving=false);
|
||||
void drawLayers(bool forSaving=false);
|
||||
|
||||
void resizeImage(QImage *image_res, const QSize &newSize);
|
||||
void resizeLayer(QImage *image_res, const QSize &newSize);
|
||||
|
||||
// Helper for Tool
|
||||
void createTempLayerAfter(int idx);
|
||||
// TODO: Always create this layer on top and return the id here!
|
||||
void createTempTopLayer(int idx);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,8 +12,8 @@ IntelliTool::~IntelliTool(){
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseRightPressed(int x, int y){
|
||||
if(drawing) {
|
||||
drawing=false;
|
||||
if(isDrawing) {
|
||||
isDrawing=false;
|
||||
this->deleteToolLayer();
|
||||
}
|
||||
}
|
||||
@@ -23,23 +23,23 @@ void IntelliTool::onMouseRightReleased(int x, int y){
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseLeftPressed(int x, int y){
|
||||
this->drawing=true;
|
||||
this->isDrawing=true;
|
||||
//create drawing layer
|
||||
this->createToolLayer();
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseLeftReleased(int x, int y){
|
||||
if(drawing) {
|
||||
drawing=false;
|
||||
if(isDrawing) {
|
||||
isDrawing=false;
|
||||
this->mergeToolLayer();
|
||||
this->deleteToolLayer();
|
||||
Active->image->calculateVisiblity();
|
||||
activeLayer->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseMoved(int x, int y){
|
||||
if(drawing)
|
||||
if(isDrawing)
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
@@ -48,17 +48,17 @@ void IntelliTool::onWheelScrolled(int value){
|
||||
}
|
||||
|
||||
void IntelliTool::createToolLayer(){
|
||||
Area->createTempLayerAfter(Area->activeLayer);
|
||||
this->Active=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
|
||||
this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)];
|
||||
Area->createTempTopLayer(Area->activeLayer);
|
||||
this->activeLayer=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
|
||||
this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)];
|
||||
}
|
||||
|
||||
void IntelliTool::mergeToolLayer(){
|
||||
QColor clr_0;
|
||||
QColor clr_1;
|
||||
for(int y=0; y<Active->height; y++) {
|
||||
for(int x=0; x<Active->width; x++) {
|
||||
clr_0=Active->image->imageData.pixelColor(x,y);
|
||||
for(int y=0; y<activeLayer->height; y++) {
|
||||
for(int x=0; x<activeLayer->width; x++) {
|
||||
clr_0=activeLayer->image->imageData.pixelColor(x,y);
|
||||
clr_1=Canvas->image->imageData.pixelColor(x,y);
|
||||
float t = static_cast<float>(clr_1.alpha())/255.f;
|
||||
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
|
||||
@@ -70,7 +70,7 @@ void IntelliTool::mergeToolLayer(){
|
||||
clr_0.setBlue(b);
|
||||
clr_0.setAlpha(a);
|
||||
|
||||
Active->image->imageData.setPixelColor(x, y, clr_0);
|
||||
activeLayer->image->imageData.setPixelColor(x, y, clr_0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ IntelliColorPicker* colorPicker;
|
||||
/*!
|
||||
* \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews.
|
||||
*/
|
||||
LayerObject* Active;
|
||||
LayerObject* activeLayer;
|
||||
|
||||
/*!
|
||||
* \brief A pointer to the drawing canvas of the tool, work on this.
|
||||
@@ -50,7 +50,7 @@ LayerObject* Canvas;
|
||||
/*!
|
||||
* \brief A flag checking if the user is currently drawing or not.
|
||||
*/
|
||||
bool drawing = false;
|
||||
bool isDrawing = false;
|
||||
|
||||
public:
|
||||
/*!
|
||||
|
||||
@@ -5,46 +5,46 @@
|
||||
|
||||
IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
: IntelliTool(Area, colorPicker){
|
||||
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
|
||||
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
|
||||
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);
|
||||
}
|
||||
|
||||
IntelliToolCircle::~IntelliToolCircle(){
|
||||
|
||||
}
|
||||
|
||||
void IntelliToolCircle::drawCyrcle(int radius){
|
||||
void IntelliToolCircle::drawCircle(int radius){
|
||||
int outer = radius+20;
|
||||
QColor inner = this->colorPicker->getSecondColor();
|
||||
inner.setAlpha(alphaInner);
|
||||
inner.setAlpha(innerAlpha);
|
||||
int yMin, yMax, xMin, xMax;
|
||||
yMin = Middle.y()-radius;
|
||||
yMax = Middle.y()+radius;
|
||||
yMin = centerPoint.y()-radius;
|
||||
yMax = centerPoint.y()+radius;
|
||||
// x = x0+-sqrt(r2-(y-y0)2)
|
||||
for(int i=yMin; i<=yMax; i++) {
|
||||
xMin = static_cast<int>(Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2)));
|
||||
xMax = static_cast<int>(Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2)));
|
||||
xMin = static_cast<int>(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
|
||||
xMax = static_cast<int>(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
|
||||
this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1);
|
||||
}
|
||||
|
||||
//TODO implement circle drawing algorithm bresenham
|
||||
radius = static_cast<int>(radius +(this->edgeWidth/2.)-1.);
|
||||
yMin = (Middle.y()-radius);
|
||||
yMax = (Middle.y()+radius);
|
||||
radius = static_cast<int>(radius +(this->borderWidth/2.)-1.);
|
||||
yMin = (centerPoint.y()-radius);
|
||||
yMax = (centerPoint.y()+radius);
|
||||
for(int i=yMin; i<=yMax; i++) {
|
||||
xMin = static_cast<int>(Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2)));
|
||||
xMax = static_cast<int>(Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2)));
|
||||
this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),edgeWidth);
|
||||
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth);
|
||||
xMin = static_cast<int>(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
|
||||
xMax = static_cast<int>(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
|
||||
this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),borderWidth);
|
||||
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),borderWidth);
|
||||
}
|
||||
|
||||
xMin = (Middle.x()-radius);
|
||||
xMax = (Middle.x()+radius);
|
||||
xMin = (centerPoint.x()-radius);
|
||||
xMax = (centerPoint.x()+radius);
|
||||
for(int i=xMin; i<=xMax; i++) {
|
||||
int yMin = static_cast<int>(Middle.y()-sqrt(pow(radius,2)-pow(i-Middle.x(),2)));
|
||||
int yMax = static_cast<int>(Middle.y()+sqrt(pow(radius,2)-pow(i-Middle.x(),2)));
|
||||
this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),edgeWidth);
|
||||
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth);
|
||||
int yMin = static_cast<int>(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
|
||||
int yMax = static_cast<int>(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
|
||||
this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),borderWidth);
|
||||
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),borderWidth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,9 +58,9 @@ void IntelliToolCircle::onMouseRightReleased(int x, int y){
|
||||
|
||||
void IntelliToolCircle::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->Middle=QPoint(x,y);
|
||||
this->centerPoint=QPoint(x,y);
|
||||
int radius = 1;
|
||||
drawCyrcle(radius);
|
||||
drawCircle(radius);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
@@ -70,18 +70,18 @@ void IntelliToolCircle::onMouseLeftReleased(int x, int y){
|
||||
|
||||
void IntelliToolCircle::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->edgeWidth+=value;
|
||||
if(this->edgeWidth<=0) {
|
||||
this->edgeWidth=1;
|
||||
this->borderWidth+=value;
|
||||
if(this->borderWidth<=0) {
|
||||
this->borderWidth=1;
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolCircle::onMouseMoved(int x, int y){
|
||||
if(this->drawing) {
|
||||
if(this->isDrawing) {
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
int radius = static_cast<int>(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2)));
|
||||
drawCyrcle(radius);
|
||||
int radius = static_cast<int>(sqrt(pow((centerPoint.x()-x),2)+pow((centerPoint.y()-y),2)));
|
||||
drawCircle(radius);
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
@@ -12,22 +12,22 @@ class IntelliToolCircle : public IntelliTool {
|
||||
* \brief A function that implements a circle drawing algorithm.
|
||||
* \param radius - The radius of the circle.
|
||||
*/
|
||||
void drawCyrcle(int radius);
|
||||
void drawCircle(int radius);
|
||||
|
||||
/*!
|
||||
* \brief The center of the circle.
|
||||
*/
|
||||
QPoint Middle;
|
||||
QPoint centerPoint;
|
||||
|
||||
/*!
|
||||
* \brief The alpha value of the inner circle.
|
||||
*/
|
||||
int alphaInner;
|
||||
int innerAlpha;
|
||||
|
||||
/*!
|
||||
* \brief The width of the outer circle edge.
|
||||
*/
|
||||
int edgeWidth;
|
||||
int borderWidth;
|
||||
public:
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker. And reading in the inner alpha and edgeWidth.
|
||||
|
||||
@@ -31,7 +31,7 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
|
||||
std::queue<QPoint> Q;
|
||||
Q.push(start);
|
||||
|
||||
QColor oldColor = this->Active->image->getPixelColor(start);
|
||||
QColor oldColor = this->activeLayer->image->getPixelColor(start);
|
||||
QColor newColor = this->colorPicker->getFirstColor();
|
||||
Canvas->image->drawPixel(start,newColor);
|
||||
|
||||
@@ -44,19 +44,19 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
|
||||
right = QPoint(Current.x()+1,Current.y() );
|
||||
top = QPoint(Current.x(),Current.y()-1);
|
||||
down = QPoint(Current.x(),Current.y()+1);
|
||||
if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (Active->image->getPixelColor(right) == oldColor)) {
|
||||
if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (activeLayer->image->getPixelColor(right) == oldColor)) {
|
||||
Canvas->image->drawPixel(right,newColor);
|
||||
Q.push(right);
|
||||
}
|
||||
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)) {
|
||||
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (activeLayer->image->getPixelColor(left) == oldColor)) {
|
||||
Canvas->image->drawPixel(left,newColor);
|
||||
Q.push(left);
|
||||
}
|
||||
if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)) {
|
||||
if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (activeLayer->image->getPixelColor(top) == oldColor)) {
|
||||
Canvas->image->drawPixel(top,newColor);
|
||||
Q.push(top);
|
||||
}
|
||||
if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)) {
|
||||
if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (activeLayer->image->getPixelColor(down) == oldColor)) {
|
||||
Canvas->image->drawPixel(down,newColor);
|
||||
Q.push(down);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){
|
||||
|
||||
void IntelliToolLine::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->start=QPoint(x,y);
|
||||
this->Canvas->image->drawPoint(start, colorPicker->getFirstColor(),lineWidth);
|
||||
this->lineStartingPoint=QPoint(x,y);
|
||||
this->Canvas->image->drawPoint(lineStartingPoint, colorPicker->getFirstColor(),lineWidth);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
@@ -42,18 +42,18 @@ void IntelliToolLine::onWheelScrolled(int value){
|
||||
}
|
||||
|
||||
void IntelliToolLine::onMouseMoved(int x, int y){
|
||||
if(this->drawing) {
|
||||
if(this->isDrawing) {
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
switch(lineStyle) {
|
||||
case LineStyle::SOLID_LINE:
|
||||
this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth);
|
||||
this->Canvas->image->drawLine(lineStartingPoint,next,colorPicker->getFirstColor(),lineWidth);
|
||||
break;
|
||||
case LineStyle::DOTTED_LINE:
|
||||
QPoint p1 =start.x() <= next.x() ? start : next;
|
||||
QPoint p2 =start.x() < next.x() ? next : start;
|
||||
int m = static_cast<int>((p2.y()-p1.y())/(p2.x()-p1.x())+0.5f);
|
||||
int c = start.y()-start.x()*m;
|
||||
QPoint p1 =lineStartingPoint.x() <= next.x() ? lineStartingPoint : next;
|
||||
QPoint p2 =lineStartingPoint.x() < next.x() ? next : lineStartingPoint;
|
||||
int m = static_cast<int>(static_cast<float>(p2.y()-p1.y())/static_cast<float>(p2.x()-p1.x())+0.5f);
|
||||
int c = lineStartingPoint.y()-lineStartingPoint.x()*m;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class IntelliToolLine : public IntelliTool {
|
||||
/*!
|
||||
* \brief The starting point of the line.
|
||||
*/
|
||||
QPoint start;
|
||||
QPoint lineStartingPoint;
|
||||
|
||||
/*!
|
||||
* \brief The width of the line to draw.
|
||||
|
||||
@@ -23,8 +23,8 @@ void IntelliToolPen::onMouseRightReleased(int x, int y){
|
||||
|
||||
void IntelliToolPen::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->point=QPoint(x,y);
|
||||
this->Canvas->image->drawPixel(point, colorPicker->getFirstColor());
|
||||
this->previousPoint=QPoint(x,y);
|
||||
this->Canvas->image->drawPixel(previousPoint, colorPicker->getFirstColor());
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ void IntelliToolPen::onMouseLeftReleased(int x, int y){
|
||||
}
|
||||
|
||||
void IntelliToolPen::onMouseMoved(int x, int y){
|
||||
if(this->drawing) {
|
||||
if(this->isDrawing) {
|
||||
QPoint newPoint(x,y);
|
||||
this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth);
|
||||
this->point=newPoint;
|
||||
this->Canvas->image->drawLine(this->previousPoint, newPoint, colorPicker->getFirstColor(), penWidth);
|
||||
this->previousPoint=newPoint;
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ int penWidth;
|
||||
/*!
|
||||
* \brief point - Represents the previous point to help drawing a line.
|
||||
*/
|
||||
QPoint point;
|
||||
QPoint previousPoint;
|
||||
public:
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker. Reading the penWidth.
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
: IntelliTool(Area, colorPicker){
|
||||
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
|
||||
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);
|
||||
PointIsNearStart = false;
|
||||
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);
|
||||
isPointNearStart = false;
|
||||
isDrawing = false;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
else if(isDrawing && isNearStart(x,y,QPointList.front())) {
|
||||
PointIsNearStart = true;
|
||||
isPointNearStart = true;
|
||||
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
@@ -42,21 +42,21 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
|
||||
void IntelliToolPolygon::onMouseRightPressed(int x, int y){
|
||||
isDrawing = false;
|
||||
PointIsNearStart = false;
|
||||
isPointNearStart = false;
|
||||
QPointList.clear();
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
||||
if(PointIsNearStart && QPointList.size() > 1) {
|
||||
PointIsNearStart = false;
|
||||
if(isPointNearStart && QPointList.size() > 1) {
|
||||
isPointNearStart = false;
|
||||
isDrawing = false;
|
||||
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
|
||||
QPoint Point;
|
||||
QColor colorTwo(colorPicker->getSecondColor());
|
||||
colorTwo.setAlpha(alphaInner);
|
||||
for(int i = 0; i < Active->width; i++) {
|
||||
for(int j = 0; j < Active->height; j++) {
|
||||
colorTwo.setAlpha(innerAlpha);
|
||||
for(int i = 0; i < activeLayer->width; i++) {
|
||||
for(int j = 0; j < activeLayer->height; j++) {
|
||||
Point = QPoint(i,j);
|
||||
if(IntelliHelper::isInPolygon(Triangles,Point)) {
|
||||
this->Canvas->image->drawPixel(Point, colorTwo);
|
||||
|
||||
@@ -32,12 +32,12 @@ bool isDrawing;
|
||||
/*!
|
||||
* \brief PointIsNearStart true, when last click near startpoint, else false.
|
||||
*/
|
||||
bool PointIsNearStart;
|
||||
bool isPointNearStart;
|
||||
|
||||
/*!
|
||||
* \brief The alpha value of the inner circle.
|
||||
*/
|
||||
int alphaInner;
|
||||
int innerAlpha;
|
||||
|
||||
/*!
|
||||
* \brief QPointList list of all points of the polygon.
|
||||
|
||||
@@ -4,30 +4,30 @@
|
||||
|
||||
IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
: IntelliTool(Area, colorPicker){
|
||||
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
|
||||
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
|
||||
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);
|
||||
}
|
||||
|
||||
IntelliToolRectangle::~IntelliToolRectangle(){
|
||||
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::drawRectangle(QPoint otherCornor){
|
||||
int xMin = std::min(originCornor.x(), otherCornor.x());
|
||||
int xMax = std::max(originCornor.x(), otherCornor.x());
|
||||
void IntelliToolRectangle::drawRectangle(QPoint otherCorner){
|
||||
int xMin = std::min(originCorner.x(), otherCorner.x());
|
||||
int xMax = std::max(originCorner.x(), otherCorner.x());
|
||||
|
||||
int yMin = std::min(originCornor.y(), otherCornor.y());
|
||||
int yMax = std::max(originCornor.y(), otherCornor.y());
|
||||
int yMin = std::min(originCorner.y(), otherCorner.y());
|
||||
int yMax = std::max(originCorner.y(), otherCorner.y());
|
||||
|
||||
QColor clr = colorPicker->getSecondColor();
|
||||
clr.setAlpha(alphaInner);
|
||||
clr.setAlpha(innerAlpha);
|
||||
for(int y=yMin; y<=yMax; y++) {
|
||||
this->Canvas->image->drawLine(QPoint(xMin,y), QPoint(xMax, y), clr, 1);
|
||||
}
|
||||
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), borderWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), borderWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), borderWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), borderWidth);
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::onMouseRightPressed(int x, int y){
|
||||
@@ -40,8 +40,8 @@ void IntelliToolRectangle::onMouseRightReleased(int x, int y){
|
||||
|
||||
void IntelliToolRectangle::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->originCornor=QPoint(x,y);
|
||||
drawRectangle(originCornor);
|
||||
this->originCorner=QPoint(x,y);
|
||||
drawRectangle(originCorner);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ void IntelliToolRectangle::onMouseLeftReleased(int x, int y){
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::onMouseMoved(int x, int y){
|
||||
if(this->drawing) {
|
||||
if(this->isDrawing) {
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
drawRectangle(next);
|
||||
@@ -60,8 +60,8 @@ void IntelliToolRectangle::onMouseMoved(int x, int y){
|
||||
|
||||
void IntelliToolRectangle::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->edgeWidth+=value;
|
||||
if(this->edgeWidth<=0) {
|
||||
this->edgeWidth=1;
|
||||
this->borderWidth+=value;
|
||||
if(this->borderWidth<=0) {
|
||||
this->borderWidth=1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,22 +11,22 @@
|
||||
class IntelliToolRectangle : public IntelliTool {
|
||||
/*!
|
||||
* \brief A function that implements a rectagle drawing algorithm.
|
||||
* \param otherCornor - The second corner point of the rectangle.
|
||||
* \param othercorner - The second corner point of the rectangle.
|
||||
*/
|
||||
void drawRectangle(QPoint otherCornor);
|
||||
void drawRectangle(QPoint otherCorner);
|
||||
|
||||
/*!
|
||||
* \brief originCornor - The first corner point of the rectangle.
|
||||
* \brief origincorner - The first corner point of the rectangle.
|
||||
*/
|
||||
QPoint originCornor;
|
||||
QPoint originCorner;
|
||||
/*!
|
||||
* \brief alphaInner- Represents the alpha value of the inside.
|
||||
*/
|
||||
int alphaInner;
|
||||
int innerAlpha;
|
||||
/*!
|
||||
* \brief edgeWidth - The width of the rectangle edges.
|
||||
*/
|
||||
int edgeWidth;
|
||||
int borderWidth;
|
||||
public:
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker. And reading in the alphaInner and edgeWidth.
|
||||
|
||||
Reference in New Issue
Block a user