24 this->setUp(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::setUp(
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 return static_cast<int>(layerBundle.size())-1;
74 if(index<static_cast<int>(layerBundle.size())) {
75 this->layerBundle.erase(layerBundle.begin()+index);
76 if(activeLayer>=index) {
83 if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())) {
84 this->layerBundle.erase(layerBundle.begin()+activeLayer);
90 if(index>=0&&index<static_cast<int>(layerBundle.size())) {
91 this->activeLayer=index;
96 if(index>=0&&index<static_cast<int>(layerBundle.size())) {
97 layerBundle[static_cast<size_t>(index)].alpha=alpha;
103 if(this->activeLayer==-1) {
106 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
115 if(layerBundle.size()==0) {
118 this->assembleLayers(
true);
120 if(!strcmp(fileFormat,
"PNG")) {
121 QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
123 if (visibleImage.save(fileName, fileFormat)) {
130 if (Canvas->save(fileName, fileFormat)) {
139 if(this->activeLayer==-1) {
142 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
148 layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
149 layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
154 this->activateUpperLayer();
156 this->activateLowerLayer();
161 if(a>=0 && a < static_cast<int>(layerBundle.size())) {
167 QColor clr = QColorDialog::getColor(colorPicker.
getFirstColor(),
nullptr,
"Main Color", QColorDialog::DontUseNativeDialog);
172 QColor clr = QColorDialog::getColor(colorPicker.
getSecondColor(),
nullptr,
"Secondary Color", QColorDialog::DontUseNativeDialog);
215 return this->layerBundle[activeLayer].width;
219 return this->layerBundle[activeLayer].height;
228 int x =
event->x()-layerBundle[activeLayer].widthOffset;
229 int y =
event->y()-layerBundle[activeLayer].heightOffset;
230 if(event->button() == Qt::LeftButton) {
232 }
else if(event->button() == Qt::RightButton) {
244 int x =
event->x()-layerBundle[activeLayer].widthOffset;
245 int y =
event->y()-layerBundle[activeLayer].heightOffset;
254 int x =
event->x()-layerBundle[activeLayer].widthOffset;
255 int y =
event->y()-layerBundle[activeLayer].heightOffset;
256 if(event->button() == Qt::LeftButton) {
258 }
else if(event->button() == Qt::RightButton) {
265 QPoint numDegrees =
event->angleDelta() / 8;
266 if(!numDegrees.isNull()) {
267 QPoint numSteps = numDegrees / 15;
276 this->assembleLayers();
278 QPainter painter(
this);
279 QRect dirtyRec =
event->rect();
280 painter.drawImage(dirtyRec, *Canvas, dirtyRec);
291 void PaintingArea::resizeImage(QImage*image_res,
const QSize &newSize){
295 void PaintingArea::activateUpperLayer(){
296 if(activeLayer!=-1 && activeLayer<layerBundle.size()-1) {
297 std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]);
302 void PaintingArea::activateLowerLayer(){
303 if(activeLayer!=-1 && activeLayer>0) {
304 std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]);
309 void PaintingArea::assembleLayers(
bool forSaving){
311 Canvas->fill(Qt::GlobalColor::transparent);
313 Canvas->fill(Qt::GlobalColor::black);
315 for(
size_t i=0; i<layerBundle.size(); i++) {
320 for(
int y=0; y<layer.
height; y++) {
323 for(
int x=0; x<layer.
width; x++) {
327 clr_1=cpy.pixelColor(x,y);
328 float t = static_cast<float>(clr_1.alpha())/255.f;
329 int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
330 int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
331 int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
332 int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
344 void PaintingArea::createTempLayerAfter(
int idx){
347 newLayer.
alpha = 255;
348 newLayer.
height = layerBundle[idx].height;
349 newLayer.
width = layerBundle[idx].width;
351 newLayer.
widthOffset = layerBundle[idx].widthOffset;
352 newLayer.
image = layerBundle[idx].image->getDeepCopy();
353 layerBundle.insert(layerBundle.begin()+idx+1,newLayer);