mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
MagnifyingGlass: don't updateImage() needlessly
Not all possible keyboard modifiers of a wheel event change MagnifyingGlass's pixmap. So in case of e.g. MetaModifier or more than one modifier, MagnifyingGlass::wheelEvent() calls updateImage() to no avail. Move the updateImage() call into the public slots to make them self-sufficient. This also allows not to call updateImage() when the pixmap is not changed in case the adjusted parameter has reached its minimum or maximum value already.
This commit is contained in:
parent
a1bb7735d2
commit
fdba938fe8
@ -170,59 +170,70 @@ void MagnifyingGlass::wheelEvent(QWheelEvent *event)
|
||||
else
|
||||
zoomOut();
|
||||
break;
|
||||
default:
|
||||
break; // Never propagate a wheel event to the parent widget, even if we ignore it.
|
||||
}
|
||||
updateImage();
|
||||
event->setAccepted(true);
|
||||
}
|
||||
void MagnifyingGlass::zoomIn()
|
||||
{
|
||||
if (zoomLevel > 0.2f)
|
||||
if (zoomLevel > 0.2f) {
|
||||
zoomLevel -= 0.025f;
|
||||
updateImage();
|
||||
}
|
||||
}
|
||||
|
||||
void MagnifyingGlass::zoomOut()
|
||||
{
|
||||
if (zoomLevel < 0.9f)
|
||||
if (zoomLevel < 0.9f) {
|
||||
zoomLevel += 0.025f;
|
||||
updateImage();
|
||||
}
|
||||
}
|
||||
|
||||
void MagnifyingGlass::sizeUp()
|
||||
{
|
||||
auto p = (Viewer *)parent();
|
||||
if (width() < (p->width() * 0.90f))
|
||||
resize(width() + 30, height() + 15);
|
||||
resizeAndUpdate(width() + 30, height() + 15);
|
||||
}
|
||||
|
||||
void MagnifyingGlass::sizeDown()
|
||||
{
|
||||
if (width() > 175)
|
||||
resize(width() - 30, height() - 15);
|
||||
resizeAndUpdate(width() - 30, height() - 15);
|
||||
}
|
||||
|
||||
void MagnifyingGlass::heightUp()
|
||||
{
|
||||
auto p = (Viewer *)parent();
|
||||
if (height() < (p->height() * 0.90f))
|
||||
resize(width(), height() + 15);
|
||||
resizeAndUpdate(width(), height() + 15);
|
||||
}
|
||||
|
||||
void MagnifyingGlass::heightDown()
|
||||
{
|
||||
if (height() > 80)
|
||||
resize(width(), height() - 15);
|
||||
resizeAndUpdate(width(), height() - 15);
|
||||
}
|
||||
|
||||
void MagnifyingGlass::widthUp()
|
||||
{
|
||||
auto p = (Viewer *)parent();
|
||||
if (width() < (p->width() * 0.90f))
|
||||
resize(width() + 30, height());
|
||||
resizeAndUpdate(width() + 30, height());
|
||||
}
|
||||
|
||||
void MagnifyingGlass::widthDown()
|
||||
{
|
||||
if (width() > 175)
|
||||
resize(width() - 30, height());
|
||||
resizeAndUpdate(width() - 30, height());
|
||||
}
|
||||
|
||||
void MagnifyingGlass::resizeAndUpdate(int w, int h)
|
||||
{
|
||||
resize(w, h);
|
||||
updateImage();
|
||||
}
|
||||
|
||||
void MagnifyingGlass::keyPressEvent(QKeyEvent *event)
|
||||
@ -264,7 +275,6 @@ void MagnifyingGlass::keyPressEvent(QKeyEvent *event)
|
||||
}
|
||||
|
||||
if (validKey) {
|
||||
updateImage();
|
||||
event->setAccepted(true);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ class MagnifyingGlass : public QLabel
|
||||
private:
|
||||
float zoomLevel;
|
||||
void setup(const QSize &size);
|
||||
void resizeAndUpdate(int w, int h);
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user