Use exiting variable instead of request the image several times

This commit is contained in:
Luis Ángel San Martín 2019-06-01 12:13:06 +02:00
parent 0503a83a86
commit 0ab94181cc

View File

@ -81,11 +81,11 @@ void MagnifyingGlass::updateImage(int x, int y)
img.fill(Configuration::getConfiguration().getBackgroundColor()); img.fill(Configuration::getConfiguration().getBackgroundColor());
if (zw > 0 && zh > 0) { if (zw > 0 && zh > 0) {
QPainter painter(&img); QPainter painter(&img);
painter.drawPixmap(xOffset, yOffset, p->pixmap()->copy(xp, yp, zw, zh)); painter.drawPixmap(xOffset, yOffset, image->copy(xp, yp, zw, zh));
} }
setPixmap(QPixmap().fromImage(img)); setPixmap(QPixmap().fromImage(img));
} else } else
setPixmap(p->pixmap()->copy(xp, yp, zoomWidth, zoomHeight)); setPixmap(image->copy(xp, yp, zoomWidth, zoomHeight));
} else { } else {
int xp = static_cast<int>(((x - p->widget()->pos().x()) * wFactor) - zoomWidth / 2); int xp = static_cast<int>(((x - p->widget()->pos().x()) * wFactor) - zoomWidth / 2);
int yp = static_cast<int>((y + currentPos) * hFactor - zoomHeight / 2); int yp = static_cast<int>((y + currentPos) * hFactor - zoomHeight / 2);
@ -122,11 +122,11 @@ void MagnifyingGlass::updateImage(int x, int y)
img.fill(Configuration::getConfiguration().getBackgroundColor()); img.fill(Configuration::getConfiguration().getBackgroundColor());
if (zw > 0 && zh > 0) { if (zw > 0 && zh > 0) {
QPainter painter(&img); QPainter painter(&img);
painter.drawPixmap(xOffset, yOffset, p->pixmap()->copy(xp, yp, zw, zh)); painter.drawPixmap(xOffset, yOffset, image->copy(xp, yp, zw, zh));
} }
setPixmap(QPixmap().fromImage(img)); setPixmap(QPixmap().fromImage(img));
} else } else
setPixmap(p->pixmap()->copy(xp, yp, zoomWidth, zoomHeight)); setPixmap(image->copy(xp, yp, zoomWidth, zoomHeight));
} }
move(static_cast<int>(x - float(width()) / 2), static_cast<int>(y - float(height()) / 2)); move(static_cast<int>(x - float(width()) / 2), static_cast<int>(y - float(height()) / 2));
} }