mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
MagnifyingGlass::sizeUp() and MagnifyingGlass::sizeDown() grow/shrink both width and height, but check only width's limits. Thus the user can first increase Magnifying glass's height, then increase its size and make the height greater than the main window's height. The user can also first increase the width, then decrease the size until the height shrinks to 0 and Magnifying glass disappears. When Magnifying glass disappears, the only way to make it visible again is to restore its default size by restarting YACReader, because the invisible MagnifyingGlass widget does not receive wheel events and Viewer::keyPressEvent() propagates shortcuts to mglass only if it is visible. And even this workaround is possible only because YACReader does not save/restore Magnifying glass's size (should it?). Always checking both width and height limits fixes the bug. If one of the dimensions reaches a limit, only the other dimension is modified. If both dimensions reach their limits, neither is modified.
46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
#ifndef __MAGNIFYING_GLASS
|
|
#define __MAGNIFYING_GLASS
|
|
|
|
#include <QLabel>
|
|
#include <QtGui>
|
|
#include <QMouseEvent>
|
|
#include <QWidget>
|
|
|
|
class MagnifyingGlass : public QLabel
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
float zoomLevel;
|
|
void setup(const QSize &size);
|
|
void resizeAndUpdate(int w, int h);
|
|
|
|
// The following 4 functions increase/decrease their argument and return true,
|
|
// unless the maximum dimension value has been reached, in which case they
|
|
// do not modify the argument and return false.
|
|
bool growWidth(int &w) const;
|
|
bool shrinkWidth(int &w) const;
|
|
bool growHeight(int &h) const;
|
|
bool shrinkHeight(int &h) const;
|
|
|
|
void keyPressEvent(QKeyEvent *event) override;
|
|
|
|
public:
|
|
MagnifyingGlass(int width, int height, QWidget *parent);
|
|
MagnifyingGlass(const QSize &size, QWidget *parent);
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
public slots:
|
|
void updateImage(int x, int y);
|
|
void updateImage();
|
|
void wheelEvent(QWheelEvent *event) override;
|
|
void zoomIn();
|
|
void zoomOut();
|
|
void sizeUp();
|
|
void sizeDown();
|
|
void heightUp();
|
|
void heightDown();
|
|
void widthUp();
|
|
void widthDown();
|
|
};
|
|
|
|
#endif
|