QLabel QPixmap *pixmap() method is deprecated

const QPixmap should perform as fast as a pointer
there is a replacement version for Qt5 but it requires Qt5.15, so we are using indirection witch is unsafer but it should be ok as all the action is happen in the main thread
This commit is contained in:
Luis Ángel San Martín 2021-10-02 08:07:15 +02:00
parent 5fbd100449
commit a7e3c41f34
4 changed files with 25 additions and 20 deletions

View File

@ -38,9 +38,9 @@ void MagnifyingGlass::updateImage(int x, int y)
int zoomHeight = static_cast<int>(height() * zoomLevel); int zoomHeight = static_cast<int>(height() * zoomLevel);
auto p = (Viewer *)parent(); auto p = (Viewer *)parent();
int currentPos = p->verticalScrollBar()->sliderPosition(); int currentPos = p->verticalScrollBar()->sliderPosition();
const QPixmap *image = p->pixmap(); const QPixmap image = p->pixmap();
int iWidth = image->width(); int iWidth = image.width();
int iHeight = image->height(); int iHeight = image.height();
float wFactor = static_cast<float>(iWidth) / p->widget()->width(); float wFactor = static_cast<float>(iWidth) / p->widget()->width();
float hFactor = static_cast<float>(iHeight) / p->widget()->height(); float hFactor = static_cast<float>(iHeight) / p->widget()->height();
zoomWidth *= wFactor; zoomWidth *= wFactor;
@ -67,12 +67,12 @@ void MagnifyingGlass::updateImage(int x, int y)
outImage = true; outImage = true;
} }
if (xp + zoomWidth >= image->width()) { if (xp + zoomWidth >= image.width()) {
zw -= xp + zw - image->width(); zw -= xp + zw - image.width();
outImage = true; outImage = true;
} }
if (yp + zoomHeight >= image->height()) { if (yp + zoomHeight >= image.height()) {
zh -= yp + zh - image->height(); zh -= yp + zh - image.height();
outImage = true; outImage = true;
} }
if (outImage) { if (outImage) {
@ -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, image->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(image->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);
@ -108,12 +108,12 @@ void MagnifyingGlass::updateImage(int x, int y)
outImage = true; outImage = true;
} }
if (xp + zoomWidth >= image->width()) { if (xp + zoomWidth >= image.width()) {
zw -= xp + zw - image->width(); zw -= xp + zw - image.width();
outImage = true; outImage = true;
} }
if (yp + zoomHeight >= image->height()) { if (yp + zoomHeight >= image.height()) {
zh -= yp + zh - image->height(); zh -= yp + zh - image.height();
outImage = true; outImage = true;
} }
if (outImage) { if (outImage) {
@ -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, image->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(image->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));
} }

View File

@ -978,9 +978,10 @@ void MainWindowViewer::saveImage()
if (!pathFile.isEmpty()) { if (!pathFile.isEmpty()) {
QFileInfo fi(pathFile); QFileInfo fi(pathFile);
currentDirectoryImgDest = fi.absolutePath(); currentDirectoryImgDest = fi.absolutePath();
const QPixmap *p = viewer->pixmap(); const QPixmap p = viewer->pixmap();
if (p != nullptr) if (!p.isNull()) {
p->save(pathFile); p.save(pathFile);
}
} }
} }

View File

@ -773,9 +773,13 @@ void Viewer::mouseMoveEvent(QMouseEvent *event)
} }
} }
const QPixmap *Viewer::pixmap() const QPixmap Viewer::pixmap()
{ {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return content->pixmap(); return content->pixmap();
#else
return *(content->pixmap());
#endif
} }
void Viewer::magnifyingGlassSwitch() void Viewer::magnifyingGlassSwitch()

View File

@ -178,7 +178,7 @@ private:
public: public:
Viewer(QWidget *parent = nullptr); Viewer(QWidget *parent = nullptr);
~Viewer(); ~Viewer();
const QPixmap *pixmap(); const QPixmap pixmap();
// Comic * getComic(){return comic;} // Comic * getComic(){return comic;}
const BookmarksDialog *getBookmarksDialog() { return bd; } const BookmarksDialog *getBookmarksDialog() { return bd; }
// returns the current index starting in 1 [1,nPages] // returns the current index starting in 1 [1,nPages]