26 this->setUp(maxWidth, maxHeight);
28 layerBundle[0].image->drawPlain(QColor(0,0,255,255));
29 std::vector<QPoint> polygon;
30 polygon.push_back(QPoint(100,000));
31 polygon.push_back(QPoint(200,100));
32 polygon.push_back(QPoint(100,200));
33 polygon.push_back(QPoint(000,100));
34 layerBundle[0].image->setPolygon(polygon);
37 layerBundle[1].image->drawPlain(QColor(0,255,0,255));
38 layerBundle[1].alpha=200;
47 void PaintingArea::setUp(
int maxWidth,
int maxHeight){
49 this->maxWidth = maxWidth;
50 this->maxHeight = maxHeight;
51 Canvas =
new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
54 setAttribute(Qt::WA_StaticContents);
60 newLayer.
width = width;
61 newLayer.
hight = height;
70 this->layerBundle.push_back(newLayer);
71 return static_cast<int>(layerBundle.size())-1;
76 if(index<static_cast<int>(layerBundle.size())){
77 this->layerBundle.erase(layerBundle.begin()+index);
78 if(activeLayer>=index){
85 if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())){
86 this->layerBundle.erase(layerBundle.begin()+activeLayer);
92 if(index>=0&&index<static_cast<int>(layerBundle.size())){
93 this->activeLayer=index;
98 if(index>=0&&index<static_cast<int>(layerBundle.size())){
99 layerBundle[static_cast<size_t>(index)].alpha=alpha;
105 if(this->activeLayer==-1){
108 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
117 if(layerBundle.size()==0){
120 this->assembleLayers(
true);
122 if(!strcmp(fileFormat,
"PNG")){
123 QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
125 if (visibleImage.save(fileName, fileFormat)) {
132 if (Canvas->save(fileName, fileFormat)) {
141 if(this->activeLayer==-1){
144 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
150 layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
151 layerBundle[static_cast<size_t>(activeLayer)].hightOffset += y;
156 this->activateUpperLayer();
158 this->activateLowerLayer();
163 if(a>=0 && a < static_cast<int>(layerBundle.size())){
169 QColor clr = QColorDialog::getColor(colorPicker.
getFirstColor(),
nullptr,
"Main Color", QColorDialog::DontUseNativeDialog);
174 QColor clr = QColorDialog::getColor(colorPicker.
getSecondColor(),
nullptr,
"Secondary Color", QColorDialog::DontUseNativeDialog);
198 return layerBundle.operator[](activeLayer).width;
202 return layerBundle.operator[](activeLayer).hight;
211 int x =
event->x()-layerBundle[activeLayer].widthOffset;
212 int y =
event->y()-layerBundle[activeLayer].hightOffset;
213 if(event->button() == Qt::LeftButton){
215 }
else if(event->button() == Qt::RightButton){
227 int x =
event->x()-layerBundle[activeLayer].widthOffset;
228 int y =
event->y()-layerBundle[activeLayer].hightOffset;
237 int x =
event->x()-layerBundle[activeLayer].widthOffset;
238 int y =
event->y()-layerBundle[activeLayer].hightOffset;
239 if(event->button() == Qt::LeftButton){
241 }
else if(event->button() == Qt::RightButton){
248 QPoint numDegrees =
event->angleDelta() / 8;
249 if(!numDegrees.isNull()){
250 QPoint numSteps = numDegrees / 15;
259 this->assembleLayers();
261 QPainter painter(
this);
262 QRect dirtyRec =
event->rect();
263 painter.drawImage(dirtyRec, *Canvas, dirtyRec);
274 void PaintingArea::resizeImage(QImage *image_res,
const QSize &newSize){
278 void PaintingArea::activateUpperLayer(){
279 if(activeLayer!=-1 && activeLayer<layerBundle.size()-1){
280 std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]);
285 void PaintingArea::activateLowerLayer(){
286 if(activeLayer!=-1 && activeLayer>0){
287 std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]);
292 void PaintingArea::assembleLayers(
bool forSaving){
294 Canvas->fill(Qt::GlobalColor::transparent);
296 Canvas->fill(Qt::GlobalColor::black);
298 for(
size_t i=0; i<layerBundle.size(); i++){
303 for(
int y=0; y<layer.
hight; y++){
306 for(
int x=0; x<layer.
width; x++){
310 clr_1=cpy.pixelColor(x,y);
311 float t = static_cast<float>(clr_1.alpha())/255.f;
312 int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
313 int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
314 int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
315 int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
327 void PaintingArea::createTempLayerAfter(
int idx){
330 newLayer.
alpha = 255;
331 newLayer.
hight = layerBundle[idx].hight;
332 newLayer.
width = layerBundle[idx].width;
333 newLayer.
hightOffset = layerBundle[idx].hightOffset;
334 newLayer.
widthOffset = layerBundle[idx].widthOffset;
335 newLayer.
image = layerBundle[idx].image->getDeepCopy();
336 layerBundle.insert(layerBundle.begin()+idx+1,newLayer);