Go to the documentation of this file.
25 this->setLayerDimensions(maxWidth, maxHeight);
45 for(
auto& layer : layerBundle) {
46 layer.image->updateRendererSetting(isFastRenderingOn);
51 void PaintingArea::setLayerDimensions(
int maxWidth,
int maxHeight){
53 this->maxWidth = maxWidth;
54 this->maxHeight = maxHeight;
55 Canvas =
new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
58 setAttribute(Qt::WA_StaticContents);
65 newLayer.
width = width;
75 this->layerBundle.push_back(newLayer);
76 activeLayer =
static_cast<int>(layerBundle.size()) - 1;
85 if(idx<
static_cast<int>(layerBundle.size())&&idx>=0) {
86 this->layerBundle.erase(layerBundle.begin() + idx);
87 if(activeLayer>=idx) {
90 if(activeLayer < 0 && layerBundle.size()) {
97 if(activeLayer>=0 && activeLayer <
static_cast<int>(layerBundle.size())) {
98 this->layerBundle.erase(layerBundle.begin() + activeLayer);
105 if(idx>=0&&idx<
static_cast<int>(layerBundle.size())) {
106 this->activeLayer = idx;
111 if(idx>=0&&idx<
static_cast<int>(layerBundle.size())) {
112 if(alpha>=0 && alpha<=255) {
113 layerBundle[
static_cast<size_t>(idx)].alpha = alpha;
118 if(idx>=0&&idx<
static_cast<int>(layerBundle.size())) {
122 isSettingPolygon =
true;
130 if(this->activeLayer==-1) {
133 IntelliImage* active = layerBundle[
static_cast<size_t>(activeLayer)].image;
142 if(layerBundle.size()==0) {
145 this->drawLayers(
true);
147 if(!strcmp(fileFormat,
"PNG")) {
148 QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
150 if (visibleImage.save(filePath, fileFormat)) {
157 if (Canvas->save(filePath, fileFormat)) {
166 layerBundle[
static_cast<size_t>(activeLayer)].widthOffset += x;
167 layerBundle[
static_cast<size_t>(activeLayer)].heightOffset += y;
173 this->selectLayerUp();
175 this->selectLayerDown();
182 if(a>=0 && a <
static_cast<int>(layerBundle.size())) {
188 QColor clr = QColorDialog::getColor(
colorPicker.
getFirstColor(),
nullptr,
"Main Color", QColorDialog::DontUseNativeDialog);
193 QColor clr = QColorDialog::getColor(
colorPicker.
getSecondColor(),
nullptr,
"Secondary Color", QColorDialog::DontUseNativeDialog);
236 return this->layerBundle[
static_cast<unsigned long long>(activeLayer)].width;
240 return this->layerBundle[
static_cast<unsigned long long>(activeLayer)].height;
244 return this->maxWidth;
248 return this->maxHeight;
252 return this->layerBundle[
static_cast<unsigned long long>(activeLayer)].image->getTypeOfImage();
256 return this->layerBundle[
static_cast<unsigned long long>(activeLayer)].image->getPolygonData();
263 if(this->activeLayer < 0) {
268 int x =
event->x() - layerBundle[
static_cast<unsigned long long>(activeLayer)].widthOffset;
269 int y =
event->y() - layerBundle[
static_cast<unsigned long long>(activeLayer)].heightOffset;
270 if(event->button() == Qt::LeftButton) {
272 }
else if(event->button() == Qt::RightButton) {
282 if(this->activeLayer < 0) {
287 int x =
event->x() - layerBundle[
static_cast<unsigned long long>(activeLayer)].widthOffset;
288 int y =
event->y() - layerBundle[
static_cast<unsigned long long>(activeLayer)].heightOffset;
295 if(this->activeLayer < 0)
299 int x =
event->x() - layerBundle[
static_cast<unsigned long long>(activeLayer)].widthOffset;
300 int y =
event->y() - layerBundle[
static_cast<unsigned long long>(activeLayer)].heightOffset;
301 if(event->button() == Qt::LeftButton) {
303 }
else if(event->button() == Qt::RightButton) {
310 if(this->activeLayer < 0)
312 if(this->Tool !=
nullptr) {
313 QPoint numDegrees =
event->angleDelta() / 8;
314 if(!numDegrees.isNull()) {
315 QPoint numSteps = numDegrees / 15;
327 QPainter painter(
this);
328 QRect dirtyRec =
event->rect();
329 painter.drawImage(dirtyRec, *Canvas, dirtyRec);
340 void PaintingArea::resizeLayer(QImage*image_res,
const QSize &newSize){
344 void PaintingArea::selectLayerUp(){
346 if(activeLayer!=-1 &&
static_cast<unsigned long long>(activeLayer)<layerBundle.size() - 1) {
347 std::swap(layerBundle[
static_cast<unsigned long long>(activeLayer)], layerBundle[
static_cast<unsigned long long>(activeLayer + 1)]);
352 void PaintingArea::selectLayerDown(){
354 if(activeLayer!=-1 && activeLayer>0) {
355 std::swap(layerBundle[
static_cast<unsigned long long>(activeLayer)], layerBundle[
static_cast<unsigned long long>(activeLayer - 1)]);
360 void PaintingArea::drawLayers(
bool forSaving){
362 Canvas->fill(Qt::GlobalColor::transparent);
364 Canvas->fill(Qt::GlobalColor::black);
366 for(
size_t i = 0; i<layerBundle.size(); i++) {
371 for(
int y = 0; y<layer.
height; y++) {
374 for(
int x = 0; x<layer.
width; x++) {
378 clr_1 = cpy.pixelColor(x,y);
379 float t =
static_cast<float>(clr_1.alpha()) / 255.f;
380 int r =
static_cast<int>(
static_cast<float>(clr_1.red()) * (t) +
static_cast<float>(clr_0.red()) * (1.f - t) + 0.5f);
381 int g =
static_cast<int>(
static_cast<float>(clr_1.green()) * (t) +
static_cast<float>(clr_0.green()) * (1.f - t) + 0.5f);
382 int b =
static_cast<int>(
static_cast<float>(clr_1.blue()) * (t) +
static_cast<float>(clr_0.blue() * (1.f - t)) + 0.5f);
383 int a = std::min(clr_0.alpha() + clr_1.alpha(), 255);
395 bool PaintingArea::createTempTopLayer(
int idx){
398 newLayer.
alpha = 255;
399 newLayer.
height = layerBundle[
static_cast<unsigned long long>(idx)].height;
400 newLayer.
width = layerBundle[
static_cast<unsigned long long>(idx)].width;
401 newLayer.
heightOffset = layerBundle[
static_cast<unsigned long long>(idx)].heightOffset;
402 newLayer.
widthOffset = layerBundle[
static_cast<unsigned long long>(idx)].widthOffset;
403 newLayer.
image = layerBundle[
static_cast<unsigned long long>(idx)].image->getDeepCopy();
404 layerBundle.insert(layerBundle.begin() + idx + 1,newLayer);
419 default:
return nullptr;
431 return layerBundle[
static_cast<size_t>(activeLayer)].image;
437 returnImage = QImage(QSize(10,10),QImage::Format_ARGB32);
438 returnImage.fill(QColor(255,255,255,255));
441 returnImage = layerBundle[
static_cast<size_t>(activeLayer)].image->getImageData();
443 returnImage = returnImage.convertToFormat(QImage::Format_ARGB32);
449 void PaintingArea::updateTools(){
456 if(isSettingPolygon) {
458 this->Tool =
nullptr;
459 isSettingPolygon =
false;
int getWidthOfActive()
The getWidthOfActive gets the horizontal dimensions of the active layer.
void setRenderSettings(bool isFastRenderingOn)
setRenderSettings updates all Images to the new Rendersetting.
IntelliImage * getImageOfActiveLayer()
void mouseReleaseEvent(QMouseEvent *event) override
void createRectangleTool()
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.
QColor getSecondColor()
A function to read the secondary selected color.
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
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).
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.
IntelliImage::ImageType getTypeOfImageRealLayer()
int width
width - Stores the width of a layer in pixels.
bool isFastRenderering()
The getfastRenderer gets the value of the flag for the fastRenderer setting.
~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.
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.
QColor getFirstColor()
A function to read the primary selected color.
int height
height - Stores the height of a layer in pixels.
QImage getImageDataOfActiveLayer()
getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer ...
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.
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 resizeEvent(QResizeEvent *event) override
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.
virtual void calculateVisiblity()=0
An abstract function that calculates the visiblity of the Image data if needed.
The IntelliRasterImage manages a RASTERIMAGE.
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type=IntelliImage::ImageType::RASTERIMAGE)
The addLayer adds a layer to the current project/ painting area.
ImageType
The Types, which an Image can be.