From a7e3c41f34061b0971898c8ca7ccc5ab71914650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sat, 2 Oct 2021 08:07:15 +0200 Subject: [PATCH] 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 --- YACReader/magnifying_glass.cpp | 30 +++++++++++++++--------------- YACReader/main_window_viewer.cpp | 7 ++++--- YACReader/viewer.cpp | 6 +++++- YACReader/viewer.h | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/YACReader/magnifying_glass.cpp b/YACReader/magnifying_glass.cpp index 28cce728..9db4b137 100644 --- a/YACReader/magnifying_glass.cpp +++ b/YACReader/magnifying_glass.cpp @@ -38,9 +38,9 @@ void MagnifyingGlass::updateImage(int x, int y) int zoomHeight = static_cast(height() * zoomLevel); auto p = (Viewer *)parent(); int currentPos = p->verticalScrollBar()->sliderPosition(); - const QPixmap *image = p->pixmap(); - int iWidth = image->width(); - int iHeight = image->height(); + const QPixmap image = p->pixmap(); + int iWidth = image.width(); + int iHeight = image.height(); float wFactor = static_cast(iWidth) / p->widget()->width(); float hFactor = static_cast(iHeight) / p->widget()->height(); zoomWidth *= wFactor; @@ -67,12 +67,12 @@ void MagnifyingGlass::updateImage(int x, int y) outImage = true; } - if (xp + zoomWidth >= image->width()) { - zw -= xp + zw - image->width(); + if (xp + zoomWidth >= image.width()) { + zw -= xp + zw - image.width(); outImage = true; } - if (yp + zoomHeight >= image->height()) { - zh -= yp + zh - image->height(); + if (yp + zoomHeight >= image.height()) { + zh -= yp + zh - image.height(); outImage = true; } if (outImage) { @@ -81,11 +81,11 @@ void MagnifyingGlass::updateImage(int x, int y) img.fill(Configuration::getConfiguration().getBackgroundColor()); if (zw > 0 && zh > 0) { 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)); } else - setPixmap(image->copy(xp, yp, zoomWidth, zoomHeight)); + setPixmap(image.copy(xp, yp, zoomWidth, zoomHeight)); } else { int xp = static_cast(((x - p->widget()->pos().x()) * wFactor) - zoomWidth / 2); int yp = static_cast((y + currentPos) * hFactor - zoomHeight / 2); @@ -108,12 +108,12 @@ void MagnifyingGlass::updateImage(int x, int y) outImage = true; } - if (xp + zoomWidth >= image->width()) { - zw -= xp + zw - image->width(); + if (xp + zoomWidth >= image.width()) { + zw -= xp + zw - image.width(); outImage = true; } - if (yp + zoomHeight >= image->height()) { - zh -= yp + zh - image->height(); + if (yp + zoomHeight >= image.height()) { + zh -= yp + zh - image.height(); outImage = true; } if (outImage) { @@ -122,11 +122,11 @@ void MagnifyingGlass::updateImage(int x, int y) img.fill(Configuration::getConfiguration().getBackgroundColor()); if (zw > 0 && zh > 0) { 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)); } else - setPixmap(image->copy(xp, yp, zoomWidth, zoomHeight)); + setPixmap(image.copy(xp, yp, zoomWidth, zoomHeight)); } move(static_cast(x - float(width()) / 2), static_cast(y - float(height()) / 2)); } diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 8f9e496f..9bd53f53 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -978,9 +978,10 @@ void MainWindowViewer::saveImage() if (!pathFile.isEmpty()) { QFileInfo fi(pathFile); currentDirectoryImgDest = fi.absolutePath(); - const QPixmap *p = viewer->pixmap(); - if (p != nullptr) - p->save(pathFile); + const QPixmap p = viewer->pixmap(); + if (!p.isNull()) { + p.save(pathFile); + } } } diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 2ac31308..bf7df3b9 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -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(); +#else + return *(content->pixmap()); +#endif } void Viewer::magnifyingGlassSwitch() diff --git a/YACReader/viewer.h b/YACReader/viewer.h index f7aab2ed..393815d9 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -178,7 +178,7 @@ private: public: Viewer(QWidget *parent = nullptr); ~Viewer(); - const QPixmap *pixmap(); + const QPixmap pixmap(); // Comic * getComic(){return comic;} const BookmarksDialog *getBookmarksDialog() { return bd; } // returns the current index starting in 1 [1,nPages]