Go to the documentation of this file.
25 this->setLayerDimensions(maxWidth, maxHeight);
37 for(
auto& layer : layerBundle) {
38 layer.image->updateRendererSetting(isFastRenderingOn);
43 void PaintingArea::setLayerDimensions(
int maxWidth,
int maxHeight){
45 this->maxWidth = maxWidth;
46 this->maxHeight = maxHeight;
47 Canvas =
new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
50 setAttribute(Qt::WA_StaticContents);
57 newLayer.
width = width;
67 this->layerBundle.push_back(newLayer);
68 activeLayer =
static_cast<int>(layerBundle.size()) - 1;
77 if(idx<
static_cast<int>(layerBundle.size())) {
78 this->layerBundle.erase(layerBundle.begin() + idx);
79 if(activeLayer>=idx) {
82 if(activeLayer < 0 && layerBundle.size()) {
89 if(activeLayer>=0 && activeLayer <
static_cast<int>(layerBundle.size())) {
90 this->layerBundle.erase(layerBundle.begin() + activeLayer);
97 if(idx>=0&&idx<
static_cast<int>(layerBundle.size())) {
98 this->activeLayer = idx;
103 if(idx>=0&&idx<
static_cast<int>(layerBundle.size())) {
104 layerBundle[
static_cast<size_t>(idx)].alpha = alpha;
108 if(idx>=0&&idx<
static_cast<int>(layerBundle.size())) {
112 isSettingPolygon =
true;
120 if(this->activeLayer==-1) {
123 IntelliImage* active = layerBundle[
static_cast<size_t>(activeLayer)].image;
132 if(layerBundle.size()==0) {
135 this->drawLayers(
true);
137 if(!strcmp(fileFormat,
"PNG")) {
138 QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
140 if (visibleImage.save(filePath, fileFormat)) {
147 if (Canvas->save(filePath, fileFormat)) {
156 layerBundle[
static_cast<size_t>(activeLayer)].widthOffset += x;
157 layerBundle[
static_cast<size_t>(activeLayer)].heightOffset += y;
163 this->selectLayerUp();
165 this->selectLayerDown();
172 if(a>=0 && a <
static_cast<int>(layerBundle.size())) {
178 QColor clr = QColorDialog::getColor(
colorPicker.
getFirstColor(),
nullptr,
"Main Color", QColorDialog::DontUseNativeDialog);
183 QColor clr = QColorDialog::getColor(
colorPicker.
getSecondColor(),
nullptr,
"Secondary Color", QColorDialog::DontUseNativeDialog);
226 return this->layerBundle[
static_cast<unsigned long long>(activeLayer)].width;
230 return this->layerBundle[
static_cast<unsigned long long>(activeLayer)].height;
234 return this->maxWidth;
238 return this->maxHeight;
242 return this->layerBundle[
static_cast<unsigned long long>(activeLayer)].image->getTypeOfImage();
246 return this->layerBundle[
static_cast<unsigned long long>(activeLayer)].image->getPolygonData();
253 if(this->activeLayer < 0) {
258 int x =
event->x() - layerBundle[
static_cast<unsigned long long>(activeLayer)].widthOffset;
259 int y =
event->y() - layerBundle[
static_cast<unsigned long long>(activeLayer)].heightOffset;
260 if(event->button() == Qt::LeftButton) {
262 }
else if(event->button() == Qt::RightButton) {
272 if(this->activeLayer < 0) {
277 int x =
event->x() - layerBundle[
static_cast<unsigned long long>(activeLayer)].widthOffset;
278 int y =
event->y() - layerBundle[
static_cast<unsigned long long>(activeLayer)].heightOffset;
285 if(this->activeLayer < 0)
289 int x =
event->x() - layerBundle[
static_cast<unsigned long long>(activeLayer)].widthOffset;
290 int y =
event->y() - layerBundle[
static_cast<unsigned long long>(activeLayer)].heightOffset;
291 if(event->button() == Qt::LeftButton) {
293 }
else if(event->button() == Qt::RightButton) {
300 if(this->activeLayer < 0)
302 if(this->Tool !=
nullptr) {
303 QPoint numDegrees =
event->angleDelta() / 8;
304 if(!numDegrees.isNull()) {
305 QPoint numSteps = numDegrees / 15;
317 QPainter painter(
this);
318 QRect dirtyRec =
event->rect();
319 painter.drawImage(dirtyRec, *Canvas, dirtyRec);
330 void PaintingArea::resizeLayer(QImage*image_res,
const QSize &newSize){
334 void PaintingArea::selectLayerUp(){
336 if(activeLayer!=-1 &&
static_cast<unsigned long long>(activeLayer)<layerBundle.size() - 1) {
337 std::swap(layerBundle[
static_cast<unsigned long long>(activeLayer)], layerBundle[
static_cast<unsigned long long>(activeLayer + 1)]);
342 void PaintingArea::selectLayerDown(){
344 if(activeLayer!=-1 && activeLayer>0) {
345 std::swap(layerBundle[
static_cast<unsigned long long>(activeLayer)], layerBundle[
static_cast<unsigned long long>(activeLayer - 1)]);
350 void PaintingArea::drawLayers(
bool forSaving){
352 Canvas->fill(Qt::GlobalColor::transparent);
354 Canvas->fill(Qt::GlobalColor::black);
356 for(
size_t i = 0; i<layerBundle.size(); i++) {
361 for(
int y = 0; y<layer.
height; y++) {
364 for(
int x = 0; x<layer.
width; x++) {
368 clr_1 = cpy.pixelColor(x,y);
369 float t =
static_cast<float>(clr_1.alpha()) / 255.f;
370 int r =
static_cast<int>(
static_cast<float>(clr_1.red()) * (t) +
static_cast<float>(clr_0.red()) * (1.f - t) + 0.5f);
371 int g =
static_cast<int>(
static_cast<float>(clr_1.green()) * (t) +
static_cast<float>(clr_0.green()) * (1.f - t) + 0.5f);
372 int b =
static_cast<int>(
static_cast<float>(clr_1.blue()) * (t) +
static_cast<float>(clr_0.blue() * (1.f - t)) + 0.5f);
373 int a = std::min(clr_0.alpha() + clr_1.alpha(), 255);
385 bool PaintingArea::createTempTopLayer(
int idx){
388 newLayer.
alpha = 255;
389 newLayer.
height = layerBundle[
static_cast<unsigned long long>(idx)].height;
390 newLayer.
width = layerBundle[
static_cast<unsigned long long>(idx)].width;
391 newLayer.
heightOffset = layerBundle[
static_cast<unsigned long long>(idx)].heightOffset;
392 newLayer.
widthOffset = layerBundle[
static_cast<unsigned long long>(idx)].widthOffset;
393 newLayer.
image = layerBundle[
static_cast<unsigned long long>(idx)].image->getDeepCopy();
394 layerBundle.insert(layerBundle.begin() + idx + 1,newLayer);
409 default:
return nullptr;
421 return layerBundle[
static_cast<size_t>(activeLayer)].image;
427 returnImage = QImage(QSize(10,10),QImage::Format_ARGB32);
428 returnImage.fill(QColor(255,255,255,255));
431 returnImage = layerBundle[
static_cast<size_t>(activeLayer)].image->getImageData();
433 returnImage = returnImage.convertToFormat(QImage::Format_ARGB32);
439 void PaintingArea::updateTools(){
446 if(isSettingPolygon) {
448 this->Tool =
nullptr;
449 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.
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 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
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()
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.
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.
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.