24 this->setUp(maxWidth, maxHeight);
27 layerBundle[0].image->drawPlain(QColor(255,0,0,255));
28 std::vector<QPoint> polygon;
29 polygon.push_back(QPoint(100,000));
30 polygon.push_back(QPoint(200,100));
31 polygon.push_back(QPoint(100,200));
32 polygon.push_back(QPoint(000,100));
33 layerBundle[0].image->setPolygon(polygon);
36 layerBundle[1].image->drawPlain(QColor(0,255,0,255));
37 layerBundle[1].alpha=200;
46 void PaintingArea::setUp(
int maxWidth,
int maxHeight){
48 this->maxWidth = maxWidth;
49 this->maxHeight = maxHeight;
50 Canvas =
new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
53 setAttribute(Qt::WA_StaticContents);
59 newLayer.
width = width;
60 newLayer.
hight = height;
69 this->layerBundle.push_back(newLayer);
70 return static_cast<int>(layerBundle.size())-1;
75 if(index<static_cast<int>(layerBundle.size())){
76 this->layerBundle.erase(layerBundle.begin()+index);
77 if(activeLayer>=index){
84 if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())){
85 this->layerBundle.erase(layerBundle.begin()+activeLayer);
91 if(index>=0&&index<static_cast<int>(layerBundle.size())){
92 this->activeLayer=index;
97 if(index>=0&&index<static_cast<int>(layerBundle.size())){
98 layerBundle[static_cast<size_t>(index)].alpha=alpha;
104 if(this->activeLayer==-1){
107 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
116 if(layerBundle.size()==0){
119 this->assembleLayers(
true);
121 if(!strcmp(fileFormat,
"PNG")){
122 QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
124 if (visibleImage.save(fileName, fileFormat)) {
131 if (Canvas->save(fileName, fileFormat)) {
140 if(this->activeLayer==-1){
143 IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
149 layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
150 layerBundle[static_cast<size_t>(activeLayer)].hightOffset += y;
155 this->activateUpperLayer();
157 this->activateLowerLayer();
162 if(a>=0 && a < static_cast<int>(layerBundle.size())){
168 QColor clr = QColorDialog::getColor(colorPicker.
getFirstColor(),
nullptr,
"Main Color", QColorDialog::DontUseNativeDialog);
173 QColor clr = QColorDialog::getColor(colorPicker.
getSecondColor(),
nullptr,
"Secondary Color", QColorDialog::DontUseNativeDialog);
202 int x =
event->x()-layerBundle[activeLayer].widthOffset;
203 int y =
event->y()-layerBundle[activeLayer].hightOffset;
204 if(event->button() == Qt::LeftButton){
206 }
else if(event->button() == Qt::RightButton){
218 int x =
event->x()-layerBundle[activeLayer].widthOffset;
219 int y =
event->y()-layerBundle[activeLayer].hightOffset;
228 int x =
event->x()-layerBundle[activeLayer].widthOffset;
229 int y =
event->y()-layerBundle[activeLayer].hightOffset;
230 if(event->button() == Qt::LeftButton){
232 }
else if(event->button() == Qt::RightButton){
239 QPoint numDegrees =
event->angleDelta() / 8;
240 if(!numDegrees.isNull()){
241 QPoint numSteps = numDegrees / 15;
250 this->assembleLayers();
252 QPainter painter(
this);
253 QRect dirtyRec =
event->rect();
254 painter.drawImage(dirtyRec, *Canvas, dirtyRec);
265 void PaintingArea::resizeImage(QImage *image_res,
const QSize &newSize){
269 void PaintingArea::activateUpperLayer(){
270 if(activeLayer!=-1 && activeLayer<layerBundle.size()-1){
271 std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]);
276 void PaintingArea::activateLowerLayer(){
277 if(activeLayer!=-1 && activeLayer>0){
278 std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]);
283 void PaintingArea::assembleLayers(
bool forSaving){
285 Canvas->fill(Qt::GlobalColor::transparent);
287 Canvas->fill(Qt::GlobalColor::black);
289 for(
size_t i=0; i<layerBundle.size(); i++){
294 for(
int y=0; y<layer.
hight; y++){
297 for(
int x=0; x<layer.
width; x++){
301 clr_1=cpy.pixelColor(x,y);
302 float t = static_cast<float>(clr_1.alpha())/255.f;
303 int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
304 int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
305 int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
306 int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
318 void PaintingArea::createTempLayerAfter(
int idx){
321 newLayer.
alpha = 255;
322 newLayer.
hight = layerBundle[idx].hight;
323 newLayer.
width = layerBundle[idx].width;
324 newLayer.
hightOffset = layerBundle[idx].hightOffset;
325 newLayer.
widthOffset = layerBundle[idx].widthOffset;
326 newLayer.
image = layerBundle[idx].image->getDeepCopy();
327 layerBundle.insert(layerBundle.begin()+idx+1,newLayer);