MagnifyingGlass: get rid of C-style casts to Viewer*

qobject_cast<const Viewer *> improves const correctness.
QLabel::pixmap() is const-qualified => make Viewer::pixmap() const too.

Return non-const QPixmap from Viewer::pixmap() to let compiler move the
return value at the function's call sites.

Introduce a named constant maxRelativeDimension. Change its type from
float to double, which usually multiplies faster on x86-64.

Remove redundant parentheses to improve readability.
This commit is contained in:
Igor Kushnir
2021-03-10 14:59:36 +02:00
parent fdba938fe8
commit efe9a1b995
3 changed files with 8 additions and 9 deletions

View File

@ -36,7 +36,7 @@ void MagnifyingGlass::updateImage(int x, int y)
// image section augmented
int zoomWidth = static_cast<int>(width() * zoomLevel);
int zoomHeight = static_cast<int>(height() * zoomLevel);
auto p = (Viewer *)parent();
auto *const p = qobject_cast<const Viewer *>(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());
}