Go to the documentation of this file.
62 for(
auto& layer : layerBundle) {
63 layer.image->updateRendererSetting(isFastRenderingOn);
74 this->maxWidth = maxWidth;
75 this->maxHeight = maxHeight;
76 Canvas =
new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
78 this->offsetXDimension = maxWidth / 2;
79 this->offsetYDimension = maxHeight / 2;
82 setAttribute(Qt::WA_StaticContents);
87 layerBundle[
static_cast<size_t>(activeLayer)].image->drawPixel(point, color);
91 layerBundle[
static_cast<size_t>(activeLayer)].image->setPolygon(points);
97 newLayer.
width = width;
101 newLayer.
alpha = alpha;
107 this->layerBundle.push_back(newLayer);
108 activeLayer =
static_cast<int>(layerBundle.size()) - 1;
118 if(idx<
static_cast<int>(layerBundle.size())&&idx>=0) {
119 this->layerBundle.erase(layerBundle.begin() + idx);
120 if(activeLayer>=idx) {
123 if(activeLayer < 0 && layerBundle.size()) {
130 if(activeLayer>=0 && activeLayer <
static_cast<int>(layerBundle.size())) {
131 this->layerBundle.erase(layerBundle.begin() + activeLayer);
139 if(idx>=0&&idx<
static_cast<int>(layerBundle.size())) {
140 this->activeLayer = idx;
145 if(idx>=0&&idx<
static_cast<int>(layerBundle.size())) {
146 if(alpha>=0 && alpha<=255) {
147 layerBundle[
static_cast<size_t>(idx)].alpha = alpha;
152 if(idx>=0&&idx<
static_cast<int>(layerBundle.size())) {
156 isSettingPolygon =
true;
164 if(this->activeLayer==-1) {
167 IntelliImage* active = layerBundle[
static_cast<size_t>(activeLayer)].image;
175 for(
auto layer: layerBundle) {
183 if(layerBundle.size()==0) {
186 this->drawLayers(
true);
188 if(!strcmp(fileFormat,
"PNG")) {
189 QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
191 if (visibleImage.save(filePath, fileFormat)) {
198 if (Canvas->save(filePath, fileFormat)) {
207 layerBundle[
static_cast<size_t>(activeLayer)].widthOffset += x;
208 layerBundle[
static_cast<size_t>(activeLayer)].heightOffset += y;
215 this->selectLayerUp();
217 this->selectLayerDown();
225 if(a>=0 && a <
static_cast<int>(layerBundle.size())) {
231 QColor clr = QColorDialog::getColor(
colorPicker.
getFirstColor(),
nullptr,
"Main Color", QColorDialog::DontUseNativeDialog);
236 QColor clr = QColorDialog::getColor(
colorPicker.
getSecondColor(),
nullptr,
"Secondary Color", QColorDialog::DontUseNativeDialog);
279 return this->layerBundle[
static_cast<size_t>(activeLayer)].width;
283 return this->layerBundle[
static_cast<size_t>(activeLayer)].height;
287 return this->maxWidth;
291 return this->maxHeight;
295 return this->layerBundle[
static_cast<size_t>(activeLayer)].image->getTypeOfImage();
299 return this->layerBundle[
static_cast<size_t>(activeLayer)].image->getPolygonData();
306 if(this->activeLayer < 0) {
311 int x =
event->x() - layerBundle[
static_cast<size_t>(activeLayer)].widthOffset - offsetXDimension;
312 int y =
event->y() - layerBundle[
static_cast<size_t>(activeLayer)].heightOffset - offsetYDimension;
313 if(event->button() == Qt::LeftButton) {
315 }
else if(event->button() == Qt::RightButton) {
325 if(this->activeLayer < 0) {
330 int x =
event->x() - layerBundle[
static_cast<size_t>(activeLayer)].widthOffset - offsetXDimension;
331 int y =
event->y() - layerBundle[
static_cast<size_t>(activeLayer)].heightOffset - offsetYDimension;
338 if(this->activeLayer < 0)
342 int x =
event->x() - layerBundle[
static_cast<size_t>(activeLayer)].widthOffset - offsetXDimension;
343 int y =
event->y() - layerBundle[
static_cast<size_t>(activeLayer)].heightOffset - offsetYDimension;
344 if(event->button() == Qt::LeftButton) {
346 }
else if(event->button() == Qt::RightButton) {
353 if(this->activeLayer < 0)
355 if(this->Tool !=
nullptr) {
356 QPoint numDegrees =
event->angleDelta() / 8;
357 if(!numDegrees.isNull()) {
358 QPoint numSteps = numDegrees / 15;
368 this->setFixedSize(QSize(maxWidth * 2,maxHeight * 2));
371 QPainter painter(
this);
378 painter.drawImage(0, 0, *Canvas, -offsetXDimension, -offsetYDimension);
382 void PaintingArea::selectLayerUp(){
384 if(activeLayer != -1 &&
static_cast<size_t>(activeLayer)<layerBundle.size() - 1) {
385 std::swap(layerBundle[
static_cast<size_t>(activeLayer)], layerBundle[
static_cast<size_t>(activeLayer + 1)]);
390 void PaintingArea::selectLayerDown(){
393 std::swap(layerBundle[
static_cast<size_t>(activeLayer)], layerBundle[
static_cast<size_t>(activeLayer - 1)]);
398 void PaintingArea::drawLayers(
bool forSaving){
400 Canvas->fill(Qt::GlobalColor::transparent);
402 Canvas->fill(Qt::GlobalColor::black);
404 for(
size_t i = 0; i<layerBundle.size(); i++) {
409 for(
int y = 0; y<layer.
height; y++) {
412 for(
int x = 0; x<layer.
width; x++) {
416 clr_1 = cpy.pixelColor(x,y);
417 float t =
static_cast<float>(clr_1.alpha()) / 255.f;
418 int r =
static_cast<int>(
static_cast<float>(clr_1.red()) * (t) +
static_cast<float>(clr_0.red()) * (1.f - t) + 0.5f);
419 int g =
static_cast<int>(
static_cast<float>(clr_1.green()) * (t) +
static_cast<float>(clr_0.green()) * (1.f - t) + 0.5f);
420 int b =
static_cast<int>(
static_cast<float>(clr_1.blue()) * (t) +
static_cast<float>(clr_0.blue() * (1.f - t)) + 0.5f);
421 int a = std::min(clr_0.alpha() + clr_1.alpha(), 255);
433 bool PaintingArea::createTempTopLayer(
int idx){
436 newLayer.
alpha = 255;
437 newLayer.
height = layerBundle[
static_cast<size_t>(idx)].height;
438 newLayer.
width = layerBundle[
static_cast<size_t>(idx)].width;
439 newLayer.
heightOffset = layerBundle[
static_cast<size_t>(idx)].heightOffset;
440 newLayer.
widthOffset = layerBundle[
static_cast<size_t>(idx)].widthOffset;
441 newLayer.
image = layerBundle[
static_cast<size_t>(idx)].image->getDeepCopy();
442 layerBundle.insert(layerBundle.begin() + idx + 1,newLayer);
457 default:
return nullptr;
469 return layerBundle[
static_cast<size_t>(activeLayer)].image;
475 returnImage = QImage(QSize(10,10),QImage::Format_ARGB32);
476 returnImage.fill(QColor(255,255,255,255));
479 returnImage = layerBundle[
static_cast<size_t>(activeLayer)].image->getImageData();
481 returnImage = returnImage.convertToFormat(QImage::Format_ARGB32);
491 void PaintingArea::updateTools(){
498 if(isSettingPolygon) {
500 this->Tool =
nullptr;
501 isSettingPolygon =
false;
506 void PaintingArea::historyadd(){
508 if (++historyPresent == 100) {
511 historyMaxFuture = historyPresent;
512 if (historyPresent == historyMaxPast)
513 if (++historyMaxPast == 100)
515 history[
static_cast<size_t>(historyPresent)] = layerBundle;
519 if (historyPresent != historyMaxPast) {
520 if (--historyPresent == -1)
522 layerBundle = history[
static_cast<size_t>(historyPresent)];
528 if (historyPresent != historyMaxFuture) {
529 if (++historyPresent == 100)
531 layerBundle = history[
static_cast<size_t>(historyPresent)];
int getWidthOfActive()
The getWidthOfActive gets the horizontal dimensions of the active layer.
QColor getFirstColor() const
A function to read the primary selected color.
ImageType
The Types, which an Image can be.
void setRenderSettings(bool isFastRenderingOn)
setRenderSettings updates all Images to the new Rendersetting.
IntelliImage * getImageOfActiveLayer()
void mouseReleaseEvent(QMouseEvent *event) override
void createRectangleTool()
bool isFastRenderering() const
The getfastRenderer gets the value of the flag for the fastRenderer setting.
bool save(const QString &filePath, const char *fileFormat)
The save method is used for exporting the current project as one picture.
void setLayerAlpha(int idx, int alpha)
The setAlphaOfLayer method sets the alpha value of a specific layer.
void setLayerActive(int idx)
The setLayerToActive method marks a specific layer as active.
int widthOffset
widthOffset - Stores the number of pixles from the left side of the painting area.
void deleteLayer(int idx, bool isTool=false)
The deleteLayer method removes a layer at a given idx.
void setSecondColor(QColor Color)
A function to set the secondary color.
The IntelliShapedImage manages a Shapedimage.
int heightOffset
heightOffset - Stores the number of pixles from the top of the painting area.
int getHeightOfActive()
The getHeightOfActive gets the vertical dimensions of the active layer.
virtual QImage getDisplayable(const QSize &displaySize, int alpha)=0
A function returning the displayable ImageData in a requested transparence and size.
void wheelEvent(QWheelEvent *event) override
virtual ImageType getTypeOfImage()
The LayerObject struct holds all the information needed to construct a layer.
void mousePressEvent(QMouseEvent *event) override
int alpha
alpha - Stores the alpha value of the layer (default=255).
QColor getSecondColor() const
A function to read the secondary selected color.
void colorPickerSetSecondColor()
The colorPickerSetSecondColor calls the QTColorPicker to determine the secondary drawing color.
void colorPickerSetFirstColor()
The colorPickerSetFirstColor calls the QTColorPicker to determine the primary drawing color.
std::vector< LayerObject > * getLayerBundle()
getLayerBundle returns the real active layerbundle (care!)
int width
width - Stores the width of a layer in pixels.
~PaintingArea() override
This deconstructor is used to clear up the memory and remove the currently active window.
void mouseMoveEvent(QMouseEvent *event) override
int getNumberOfActiveLayer()
void setFirstColor(QColor Color)
A function to set the primary color.
void slotDeleteActiveLayer()
The slotDeleteActiveLayer method handles the deletion of the active layer.
ImageType getTypeOfImageRealLayer()
void setToolWidth(int value)
bool open(const QString &filePath)
The open method is used for loading a picture into the current layer.
void moveActiveLayer(int idx)
The moveActiveLayer moves the active layer to a specific position in the layer stack.
IntelliColorPicker colorPicker
PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent=nullptr)
PaintingArea is the constructor of the PaintingArea class, which initiates the working environment.
void setPixelToActive(QColor color, QPoint point)
int height
height - Stores the height of a layer in pixels.
void deleteAllLayers()
deleteAllLayers deletes all layers
QImage getImageDataOfActiveLayer()
getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer ...
void setLayerDimensions(int maxWidth, int maxHeight)
void createFloodFillTool()
void slotActivateLayer(int a)
The slotActivateLayer method handles the event of selecting one layer as active.
void paintEvent(QPaintEvent *event) override
void setFastRendering(bool Updatedsetting)
setFastRendering sets fastRendering to Updatedsetting.
bool getRenderSettings()
getRenderSettings updates all Images to the new Rendersetting.
IntelliImage * image
image - Stores the imageData of the current LayerObject.
virtual bool loadImage(const QString &filePath)
A function that loads and sclaes an image to the fitting dimensions.
std::vector< QPoint > getPolygonDataOfRealLayer()
IntelliToolsettings Toolsettings
void setPolygon(int idx)
setPolygon is used for setting polygondata, it only works on RASTER images
void swapColors()
A function switching primary and secondary color.
void colorPickerSwapColors()
The colorPickerSwitchColor swaps the primary color with the secondary drawing color.
void movePositionActive(int x, int y)
The movePositionActive method moves the active layer to certain position.
An abstract class which manages the basic IntelliImage operations.
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, int alpha=255, ImageType type=ImageType::RASTERIMAGE)
The addLayer adds a layer to the current project/ painting area.
virtual void calculateVisiblity()=0
An abstract function that calculates the visiblity of the Image data if needed.
The IntelliRasterImage manages a RASTERIMAGE.
void setPolygonDataToActive(std::vector< QPoint > points)