20 this->setUp(maxWidth, maxHeight);
23 layerBundle[0].image->drawPlain(QColor(255,0,0,255));
24 std::vector<QPoint> polygon;
25 polygon.push_back(QPoint(100,000));
26 polygon.push_back(QPoint(200,100));
27 polygon.push_back(QPoint(100,200));
28 polygon.push_back(QPoint(000,100));
29 layerBundle[0].image->setPolygon(polygon);
32 layerBundle[1].image->drawPlain(QColor(0,255,0,255));
33 layerBundle[1].alpha=200;
42 void PaintingArea::setUp(
int maxWidth,
int maxHeight){
44 this->maxWidth = maxWidth;
45 this->maxHeight = maxHeight;
46 Canvas =
new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
49 setAttribute(Qt::WA_StaticContents);
55 newLayer.
width = width;
56 newLayer.
hight = height;
65 this->layerBundle.push_back(newLayer);
66 return static_cast<int>(layerBundle.size())-1;
71 if(index<static_cast<int>(layerBundle.size())){
72 this->layerBundle.erase(layerBundle.begin()+index);
73 if(activeLayer>=index){
80 if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())){
81 this->layerBundle.erase(layerBundle.begin()+activeLayer);
87 if(index>=0&&index<static_cast<int>(layerBundle.size())){
88 this->activeLayer=index;
93 if(index>=0&&index<static_cast<int>(layerBundle.size())){
94 layerBundle[static_cast<size_t>(index)].alpha=alpha;
100 if(this->activeLayer==-1){
103 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
112 if(layerBundle.size()==0){
115 this->assembleLayers(
true);
117 if(!strcmp(fileFormat,
"PNG")){
118 QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
120 if (visibleImage.save(fileName, fileFormat)) {
127 if (Canvas->save(fileName, fileFormat)) {
136 if(this->activeLayer==-1){
139 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
145 layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
146 layerBundle[static_cast<size_t>(activeLayer)].hightOffset += y;
151 this->activateUpperLayer();
153 this->activateLowerLayer();
158 if(a>=0 && a < static_cast<int>(layerBundle.size())){
164 QColor clr = QColorDialog::getColor(colorPicker.
getFirstColor(),
nullptr,
"Main Color");
169 QColor clr = QColorDialog::getColor(colorPicker.
getSecondColor(),
nullptr,
"Secondary Color");
198 int x =
event->x()-layerBundle[activeLayer].widthOffset;
199 int y =
event->y()-layerBundle[activeLayer].hightOffset;
200 if(event->button() == Qt::LeftButton){
202 }
else if(event->button() == Qt::RightButton){
214 int x =
event->x()-layerBundle[activeLayer].widthOffset;
215 int y =
event->y()-layerBundle[activeLayer].hightOffset;
224 int x =
event->x()-layerBundle[activeLayer].widthOffset;
225 int y =
event->y()-layerBundle[activeLayer].hightOffset;
226 if(event->button() == Qt::LeftButton){
228 }
else if(event->button() == Qt::RightButton){
238 this->assembleLayers();
240 QPainter painter(
this);
241 QRect dirtyRec =
event->rect();
242 painter.drawImage(dirtyRec, *Canvas, dirtyRec);
253 void PaintingArea::resizeImage(QImage *image_res,
const QSize &newSize){
257 void PaintingArea::activateUpperLayer(){
258 if(activeLayer!=-1 && activeLayer<layerBundle.size()-1){
259 std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]);
264 void PaintingArea::activateLowerLayer(){
265 if(activeLayer!=-1 && activeLayer>0){
266 std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]);
271 void PaintingArea::assembleLayers(
bool forSaving){
273 Canvas->fill(Qt::GlobalColor::transparent);
275 Canvas->fill(Qt::GlobalColor::black);
277 for(
size_t i=0; i<layerBundle.size(); i++){
282 for(
int y=0; y<layer.
hight; y++){
285 for(
int x=0; x<layer.
width; x++){
289 clr_1=cpy.pixelColor(x,y);
290 float t = static_cast<float>(clr_1.alpha())/255.f;
291 int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
292 int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
293 int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
294 int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
306 void PaintingArea::createTempLayerAfter(
int idx){
309 newLayer.
alpha = 255;
310 newLayer.
hight = layerBundle[idx].hight;
311 newLayer.
width = layerBundle[idx].width;
312 newLayer.
hightOffset = layerBundle[idx].hightOffset;
313 newLayer.
widthOffset = layerBundle[idx].widthOffset;
314 newLayer.
image = layerBundle[idx].image->getDeepCopy();
315 layerBundle.insert(layerBundle.begin()+idx+1,newLayer);