24 this->setLayerDimensions(maxWidth, maxHeight);
26 layerBundle[0].image->drawPlain(QColor(0,0,255,255));
27 std::vector<QPoint> polygon;
28 polygon.push_back(QPoint(100,000));
29 polygon.push_back(QPoint(200,100));
30 polygon.push_back(QPoint(100,200));
31 polygon.push_back(QPoint(000,100));
32 layerBundle[0].image->setPolygon(polygon);
35 layerBundle[1].image->drawPlain(QColor(0,255,0,255));
36 layerBundle[1].alpha=200;
45 void PaintingArea::setLayerDimensions(
int maxWidth,
int maxHeight){
47 this->maxWidth = maxWidth;
48 this->maxHeight = maxHeight;
49 Canvas =
new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
52 setAttribute(Qt::WA_StaticContents);
58 newLayer.
width = width;
68 this->layerBundle.push_back(newLayer);
69 activeLayer = static_cast<int>(layerBundle.size())-1;
75 if(idx<static_cast<int>(layerBundle.size())) {
76 this->layerBundle.erase(layerBundle.begin()+idx);
77 if(activeLayer>=idx && activeLayer != 0) {
84 if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())) {
85 this->layerBundle.erase(layerBundle.begin()+activeLayer);
91 if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
92 this->activeLayer=idx;
97 if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
98 layerBundle[static_cast<size_t>(idx)].alpha=alpha;
104 if(this->activeLayer==-1) {
107 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
116 if(layerBundle.size()==0) {
119 this->drawLayers(
true);
121 if(!strcmp(fileFormat,
"PNG")) {
122 QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
124 if (visibleImage.save(filePath, fileFormat)) {
131 if (Canvas->save(filePath, fileFormat)) {
140 if(this->activeLayer==-1) {
143 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
156 layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
157 layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
161 if(Tool !=
nullptr) {
169 this->selectLayerUp();
171 this->selectLayerDown();
176 if(Tool !=
nullptr) {
183 if(a>=0 && a < static_cast<int>(layerBundle.size())) {
189 QColor clr = QColorDialog::getColor(
colorPicker.
getFirstColor(),
nullptr,
"Main Color", QColorDialog::DontUseNativeDialog);
194 QColor clr = QColorDialog::getColor(
colorPicker.
getSecondColor(),
nullptr,
"Secondary Color", QColorDialog::DontUseNativeDialog);
237 return this->layerBundle[static_cast<unsigned long long>(activeLayer)].width;
241 return this->layerBundle[static_cast<unsigned long long>(activeLayer)].height;
245 return this->layerBundle[static_cast<unsigned long long>(activeLayer)].image->getTypeOfImage();
249 return this->layerBundle[static_cast<unsigned long long>(activeLayer)].image->getPolygonData();
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) {
274 int x =
event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
275 int y =
event->y()-layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
284 int x =
event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
285 int y =
event->y()-layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
286 if(event->button() == Qt::LeftButton) {
288 }
else if(event->button() == Qt::RightButton) {
295 if(this->Tool !=
nullptr) {
296 QPoint numDegrees =
event->angleDelta() / 8;
297 if(!numDegrees.isNull()) {
298 QPoint numSteps = numDegrees / 15;
310 QPainter painter(
this);
311 QRect dirtyRec =
event->rect();
312 painter.drawImage(dirtyRec, *Canvas, dirtyRec);
323 void PaintingArea::resizeLayer(QImage*image_res,
const QSize &newSize){
327 void PaintingArea::selectLayerUp(){
328 if(activeLayer!=-1 && static_cast<unsigned long long>(activeLayer)<layerBundle.size()-1) {
329 std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer+1)]);
334 void PaintingArea::selectLayerDown(){
335 if(activeLayer!=-1 && activeLayer>0) {
336 std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]);
341 void PaintingArea::drawLayers(
bool forSaving){
343 Canvas->fill(Qt::GlobalColor::transparent);
345 Canvas->fill(Qt::GlobalColor::black);
347 for(
size_t i=0; i<layerBundle.size(); i++) {
352 for(
int y=0; y<layer.
height; y++) {
355 for(
int x=0; x<layer.
width; x++) {
359 clr_1=cpy.pixelColor(x,y);
360 float t = static_cast<float>(clr_1.alpha())/255.f;
361 int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
362 int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
363 int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
364 int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
376 void PaintingArea::createTempTopLayer(
int idx){
379 newLayer.
alpha = 255;
380 newLayer.
height = layerBundle[static_cast<unsigned long long>(idx)].height;
381 newLayer.
width = layerBundle[static_cast<unsigned long long>(idx)].width;
382 newLayer.
heightOffset = layerBundle[static_cast<unsigned long long>(idx)].heightOffset;
383 newLayer.
widthOffset = layerBundle[static_cast<unsigned long long>(idx)].widthOffset;
384 newLayer.
image = layerBundle[static_cast<unsigned long long>(idx)].image->getDeepCopy();
385 layerBundle.insert(layerBundle.begin()+idx+1,newLayer);
398 default:
return nullptr;
407 return layerBundle[activeLayer].image;