mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-14 12:20:32 +02:00
Merge branch 'dev' into UnitTesting
This commit is contained in:
@@ -24,7 +24,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
|
||||
this->Tool = nullptr;
|
||||
this->setLayerDimensions(maxWidth, maxHeight);
|
||||
|
||||
activeLayer=-1;
|
||||
activeLayer = -1;
|
||||
}
|
||||
|
||||
PaintingArea::~PaintingArea(){
|
||||
@@ -32,7 +32,7 @@ PaintingArea::~PaintingArea(){
|
||||
}
|
||||
|
||||
void PaintingArea::setRenderSettings(bool isFastRenderingOn){
|
||||
if(isFastRenderingOn != renderSettings.isFastRenderering()) {
|
||||
if(isFastRenderingOn != renderSettings.isFastRenderering() && !Tool->getIsDrawing()) {
|
||||
renderSettings.setFastRendering(isFastRenderingOn);
|
||||
for(auto& layer : layerBundle) {
|
||||
layer.image->updateRendererSetting(isFastRenderingOn);
|
||||
@@ -65,7 +65,7 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff
|
||||
}
|
||||
newLayer.alpha = 255;
|
||||
this->layerBundle.push_back(newLayer);
|
||||
activeLayer = static_cast<int>(layerBundle.size())-1;
|
||||
activeLayer = static_cast<int>(layerBundle.size()) - 1;
|
||||
return activeLayer;
|
||||
}
|
||||
|
||||
@@ -75,19 +75,19 @@ void PaintingArea::deleteLayer(int idx, bool isTool){
|
||||
updateTools();
|
||||
}
|
||||
if(idx<static_cast<int>(layerBundle.size())&&idx>=0) {
|
||||
this->layerBundle.erase(layerBundle.begin()+idx);
|
||||
this->layerBundle.erase(layerBundle.begin() + idx);
|
||||
if(activeLayer>=idx) {
|
||||
activeLayer--;
|
||||
}
|
||||
if(activeLayer < 0 && layerBundle.size()) {
|
||||
activeLayer=0;
|
||||
activeLayer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::slotDeleteActiveLayer(){
|
||||
if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())) {
|
||||
this->layerBundle.erase(layerBundle.begin()+activeLayer);
|
||||
this->layerBundle.erase(layerBundle.begin() + activeLayer);
|
||||
activeLayer--;
|
||||
}
|
||||
}
|
||||
@@ -95,14 +95,14 @@ void PaintingArea::slotDeleteActiveLayer(){
|
||||
void PaintingArea::setLayerActive(int idx){
|
||||
updateTools();
|
||||
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
|
||||
this->activeLayer=idx;
|
||||
this->activeLayer = idx;
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::setLayerAlpha(int idx, int alpha){
|
||||
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
|
||||
if(alpha>=0 && alpha<=255) {
|
||||
layerBundle[static_cast<size_t>(idx)].alpha=alpha;
|
||||
layerBundle[static_cast<size_t>(idx)].alpha = alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,7 @@ void PaintingArea::setPolygon(int idx){
|
||||
delete this->Tool;
|
||||
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
|
||||
isSettingPolygon = true;
|
||||
this->DummyGui->setToolWidth(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,6 +166,7 @@ void PaintingArea::moveActiveLayer(int idx){
|
||||
}else if(idx==-1) {
|
||||
this->selectLayerDown();
|
||||
}
|
||||
DummyGui->UpdateGui();
|
||||
}
|
||||
|
||||
void PaintingArea::slotActivateLayer(int a){
|
||||
@@ -230,6 +232,14 @@ int PaintingArea::getHeightOfActive(){
|
||||
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].height;
|
||||
}
|
||||
|
||||
int PaintingArea::getMaxWidth(){
|
||||
return this->maxWidth;
|
||||
}
|
||||
|
||||
int PaintingArea::getMaxHeight(){
|
||||
return this->maxHeight;
|
||||
}
|
||||
|
||||
IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){
|
||||
return this->layerBundle[static_cast<unsigned long long>(activeLayer)].image->getTypeOfImage();
|
||||
}
|
||||
@@ -247,8 +257,8 @@ void PaintingArea::mousePressEvent(QMouseEvent*event){
|
||||
}
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
|
||||
int y = event->y()-layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
|
||||
int x = event->x() - layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
|
||||
int y = event->y() - layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
|
||||
if(event->button() == Qt::LeftButton) {
|
||||
Tool->onMouseLeftPressed(x, y);
|
||||
}else if(event->button() == Qt::RightButton) {
|
||||
@@ -266,8 +276,8 @@ void PaintingArea::mouseMoveEvent(QMouseEvent*event){
|
||||
}
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
|
||||
int y = event->y()-layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
|
||||
int x = event->x() - layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
|
||||
int y = event->y() - layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
|
||||
Tool->onMouseMoved(x, y);
|
||||
update();
|
||||
}
|
||||
@@ -278,8 +288,8 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){
|
||||
return;
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
|
||||
int y = event->y()-layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
|
||||
int x = event->x() - layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
|
||||
int y = event->y() - layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
|
||||
if(event->button() == Qt::LeftButton) {
|
||||
Tool->onMouseLeftReleased(x, y);
|
||||
}else if(event->button() == Qt::RightButton) {
|
||||
@@ -295,7 +305,7 @@ void PaintingArea::wheelEvent(QWheelEvent*event){
|
||||
QPoint numDegrees = event->angleDelta() / 8;
|
||||
if(!numDegrees.isNull()) {
|
||||
QPoint numSteps = numDegrees / 15;
|
||||
Tool->onWheelScrolled(numSteps.y()* -1);
|
||||
Tool->onWheelScrolled(numSteps.y() * -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,8 +335,8 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){
|
||||
|
||||
void PaintingArea::selectLayerUp(){
|
||||
updateTools();
|
||||
if(activeLayer!=-1 && static_cast<unsigned long long>(activeLayer)<layerBundle.size()-1) {
|
||||
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer+1)]);
|
||||
if(activeLayer!=-1 && static_cast<unsigned long long>(activeLayer)<layerBundle.size() - 1) {
|
||||
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer + 1)]);
|
||||
activeLayer++;
|
||||
}
|
||||
}
|
||||
@@ -334,7 +344,7 @@ void PaintingArea::selectLayerUp(){
|
||||
void PaintingArea::selectLayerDown(){
|
||||
updateTools();
|
||||
if(activeLayer!=-1 && activeLayer>0) {
|
||||
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]);
|
||||
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer - 1)]);
|
||||
activeLayer--;
|
||||
}
|
||||
}
|
||||
@@ -345,30 +355,30 @@ void PaintingArea::drawLayers(bool forSaving){
|
||||
}else{
|
||||
Canvas->fill(Qt::GlobalColor::black);
|
||||
}
|
||||
for(size_t i=0; i<layerBundle.size(); i++) {
|
||||
for(size_t i = 0; i<layerBundle.size(); i++) {
|
||||
LayerObject layer = layerBundle[i];
|
||||
QImage cpy = layer.image->getDisplayable(layer.alpha);
|
||||
QColor clr_0;
|
||||
QColor clr_1;
|
||||
for(int y=0; y<layer.height; y++) {
|
||||
if(layer.heightOffset+y<0) continue;
|
||||
if(layer.heightOffset+y>=maxHeight) break;
|
||||
for(int x=0; x<layer.width; x++) {
|
||||
if(layer.widthOffset+x<0) continue;
|
||||
if(layer.widthOffset+x>=maxWidth) break;
|
||||
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y);
|
||||
clr_1=cpy.pixelColor(x,y);
|
||||
float t = static_cast<float>(clr_1.alpha())/255.f;
|
||||
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
|
||||
int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
|
||||
int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
|
||||
int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
|
||||
for(int y = 0; y<layer.height; y++) {
|
||||
if(layer.heightOffset + y<0) continue;
|
||||
if(layer.heightOffset + y>=maxHeight) break;
|
||||
for(int x = 0; x<layer.width; x++) {
|
||||
if(layer.widthOffset + x<0) continue;
|
||||
if(layer.widthOffset + x>=maxWidth) break;
|
||||
clr_0 = Canvas->pixelColor(layer.widthOffset + x, layer.heightOffset + y);
|
||||
clr_1 = cpy.pixelColor(x,y);
|
||||
float t = static_cast<float>(clr_1.alpha()) / 255.f;
|
||||
int r = static_cast<int>(static_cast<float>(clr_1.red()) * (t) + static_cast<float>(clr_0.red()) * (1.f - t) + 0.5f);
|
||||
int g = static_cast<int>(static_cast<float>(clr_1.green()) * (t) + static_cast<float>(clr_0.green()) * (1.f - t) + 0.5f);
|
||||
int b = static_cast<int>(static_cast<float>(clr_1.blue()) * (t) + static_cast<float>(clr_0.blue() * (1.f - t)) + 0.5f);
|
||||
int a = std::min(clr_0.alpha() + clr_1.alpha(), 255);
|
||||
clr_0.setRed(r);
|
||||
clr_0.setGreen(g);
|
||||
clr_0.setBlue(b);
|
||||
clr_0.setAlpha(a);
|
||||
|
||||
Canvas->setPixelColor(layer.widthOffset+x, layer.heightOffset+y, clr_0);
|
||||
Canvas->setPixelColor(layer.widthOffset + x, layer.heightOffset + y, clr_0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -383,7 +393,7 @@ bool PaintingArea::createTempTopLayer(int idx){
|
||||
newLayer.heightOffset = layerBundle[static_cast<unsigned long long>(idx)].heightOffset;
|
||||
newLayer.widthOffset = layerBundle[static_cast<unsigned long long>(idx)].widthOffset;
|
||||
newLayer.image = layerBundle[static_cast<unsigned long long>(idx)].image->getDeepCopy();
|
||||
layerBundle.insert(layerBundle.begin()+idx+1,newLayer);
|
||||
layerBundle.insert(layerBundle.begin() + idx + 1,newLayer);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user