mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Always limit Magnifying glass's height
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.
This commit is contained in:
parent
efe9a1b995
commit
c8697ccd2d
@ -191,42 +191,48 @@ void MagnifyingGlass::zoomOut()
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr auto maxRelativeDimension = 0.9;
|
||||
|
||||
void MagnifyingGlass::sizeUp()
|
||||
{
|
||||
if (width() < parentWidget()->width() * maxRelativeDimension)
|
||||
resizeAndUpdate(width() + 30, height() + 15);
|
||||
auto w = width();
|
||||
auto h = height();
|
||||
if (growWidth(w) | growHeight(h)) // bitwise OR prevents short-circuiting
|
||||
resizeAndUpdate(w, h);
|
||||
}
|
||||
|
||||
void MagnifyingGlass::sizeDown()
|
||||
{
|
||||
if (width() > 175)
|
||||
resizeAndUpdate(width() - 30, height() - 15);
|
||||
auto w = width();
|
||||
auto h = height();
|
||||
if (shrinkWidth(w) | shrinkHeight(h)) // bitwise OR prevents short-circuiting
|
||||
resizeAndUpdate(w, h);
|
||||
}
|
||||
|
||||
void MagnifyingGlass::heightUp()
|
||||
{
|
||||
if (height() < parentWidget()->height() * maxRelativeDimension)
|
||||
resizeAndUpdate(width(), height() + 15);
|
||||
auto h = height();
|
||||
if (growHeight(h))
|
||||
resizeAndUpdate(width(), h);
|
||||
}
|
||||
|
||||
void MagnifyingGlass::heightDown()
|
||||
{
|
||||
if (height() > 80)
|
||||
resizeAndUpdate(width(), height() - 15);
|
||||
auto h = height();
|
||||
if (shrinkHeight(h))
|
||||
resizeAndUpdate(width(), h);
|
||||
}
|
||||
|
||||
void MagnifyingGlass::widthUp()
|
||||
{
|
||||
if (width() < parentWidget()->width() * maxRelativeDimension)
|
||||
resizeAndUpdate(width() + 30, height());
|
||||
auto w = width();
|
||||
if (growWidth(w))
|
||||
resizeAndUpdate(w, height());
|
||||
}
|
||||
|
||||
void MagnifyingGlass::widthDown()
|
||||
{
|
||||
if (width() > 175)
|
||||
resizeAndUpdate(width() - 30, height());
|
||||
auto w = width();
|
||||
if (shrinkWidth(w))
|
||||
resizeAndUpdate(w, height());
|
||||
}
|
||||
|
||||
void MagnifyingGlass::resizeAndUpdate(int w, int h)
|
||||
@ -235,6 +241,46 @@ void MagnifyingGlass::resizeAndUpdate(int w, int h)
|
||||
updateImage();
|
||||
}
|
||||
|
||||
static constexpr auto maxRelativeDimension = 0.9;
|
||||
static constexpr auto widthStep = 30;
|
||||
static constexpr auto heightStep = 15;
|
||||
|
||||
bool MagnifyingGlass::growWidth(int &w) const
|
||||
{
|
||||
const auto maxWidth = parentWidget()->width() * maxRelativeDimension;
|
||||
if (w >= maxWidth)
|
||||
return false;
|
||||
w += widthStep;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MagnifyingGlass::shrinkWidth(int &w) const
|
||||
{
|
||||
constexpr auto minWidth = 175;
|
||||
if (w <= minWidth)
|
||||
return false;
|
||||
w -= widthStep;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MagnifyingGlass::growHeight(int &h) const
|
||||
{
|
||||
const auto maxHeight = parentWidget()->height() * maxRelativeDimension;
|
||||
if (h >= maxHeight)
|
||||
return false;
|
||||
h += heightStep;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MagnifyingGlass::shrinkHeight(int &h) const
|
||||
{
|
||||
constexpr auto minHeight = 80;
|
||||
if (h <= minHeight)
|
||||
return false;
|
||||
h -= heightStep;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MagnifyingGlass::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
bool validKey = false;
|
||||
|
@ -13,6 +13,15 @@ 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:
|
||||
|
Loading…
Reference in New Issue
Block a user