diff --git a/YACReader/magnifying_glass.cpp b/YACReader/magnifying_glass.cpp index d2b8f458..839b1b6c 100644 --- a/YACReader/magnifying_glass.cpp +++ b/YACReader/magnifying_glass.cpp @@ -36,7 +36,7 @@ void MagnifyingGlass::updateImage(int x, int y) // image section augmented int zoomWidth = static_cast(width() * zoomLevel); int zoomHeight = static_cast(height() * zoomLevel); - auto p = (Viewer *)parent(); + auto *const p = qobject_cast(parentWidget()); int currentPos = p->verticalScrollBar()->sliderPosition(); const QPixmap image = p->pixmap(); int iWidth = image.width(); @@ -191,10 +191,11 @@ void MagnifyingGlass::zoomOut() } } +static constexpr auto maxRelativeDimension = 0.9; + void MagnifyingGlass::sizeUp() { - auto p = (Viewer *)parent(); - if (width() < (p->width() * 0.90f)) + if (width() < parentWidget()->width() * maxRelativeDimension) resizeAndUpdate(width() + 30, height() + 15); } @@ -206,8 +207,7 @@ void MagnifyingGlass::sizeDown() void MagnifyingGlass::heightUp() { - auto p = (Viewer *)parent(); - if (height() < (p->height() * 0.90f)) + if (height() < parentWidget()->height() * maxRelativeDimension) resizeAndUpdate(width(), height() + 15); } @@ -219,8 +219,7 @@ void MagnifyingGlass::heightDown() void MagnifyingGlass::widthUp() { - auto p = (Viewer *)parent(); - if (width() < (p->width() * 0.90f)) + if (width() < parentWidget()->width() * maxRelativeDimension) resizeAndUpdate(width() + 30, height()); } diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index edda73de..4a942df2 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -748,7 +748,7 @@ void Viewer::mouseMoveEvent(QMouseEvent *event) } } -const QPixmap Viewer::pixmap() +QPixmap Viewer::pixmap() const { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) return content->pixmap(); diff --git a/YACReader/viewer.h b/YACReader/viewer.h index ee5bbda9..e86562d5 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -181,7 +181,7 @@ private: public: Viewer(QWidget *parent = nullptr); ~Viewer(); - const QPixmap pixmap(); + QPixmap pixmap() const; // Comic * getComic(){return comic;} const BookmarksDialog *getBookmarksDialog() { return bd; } // returns the current index starting in 1 [1,nPages]