mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Extract Viewer::(vertical|horizontal)ScrollStep()
This commit is contained in:
parent
133b547e7a
commit
feaee915bc
@ -492,6 +492,18 @@ void Viewer::scrollBackwardVerticalFirst()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr auto relativeScrollStep = 0.80;
|
||||||
|
|
||||||
|
int Viewer::verticalScrollStep() const
|
||||||
|
{
|
||||||
|
return static_cast<int>(height() * relativeScrollStep);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Viewer::horizontalScrollStep() const
|
||||||
|
{
|
||||||
|
return static_cast<int>(width() * relativeScrollStep);
|
||||||
|
}
|
||||||
|
|
||||||
bool Viewer::isEdge(scrollDirection d)
|
bool Viewer::isEdge(scrollDirection d)
|
||||||
{
|
{
|
||||||
if (d == UP)
|
if (d == UP)
|
||||||
@ -509,15 +521,15 @@ void Viewer::scrollZigzag(scrollDirection d1, scrollDirection d2, bool forward)
|
|||||||
if (!isEdge(d1)) {
|
if (!isEdge(d1)) {
|
||||||
if (d1 == UP)
|
if (d1 == UP)
|
||||||
scrollTo(horizontalScrollBar()->sliderPosition(),
|
scrollTo(horizontalScrollBar()->sliderPosition(),
|
||||||
verticalScrollBar()->sliderPosition() - static_cast<int>((height() * 0.80)));
|
verticalScrollBar()->sliderPosition() - verticalScrollStep());
|
||||||
else if (d1 == DOWN)
|
else if (d1 == DOWN)
|
||||||
scrollTo(horizontalScrollBar()->sliderPosition(),
|
scrollTo(horizontalScrollBar()->sliderPosition(),
|
||||||
verticalScrollBar()->sliderPosition() + static_cast<int>((height() * 0.80)));
|
verticalScrollBar()->sliderPosition() + verticalScrollStep());
|
||||||
else if (d1 == LEFT)
|
else if (d1 == LEFT)
|
||||||
scrollTo(horizontalScrollBar()->sliderPosition() - static_cast<int>((width() * 0.80)),
|
scrollTo(horizontalScrollBar()->sliderPosition() - horizontalScrollStep(),
|
||||||
verticalScrollBar()->sliderPosition());
|
verticalScrollBar()->sliderPosition());
|
||||||
else // d1 == RIGHT
|
else // d1 == RIGHT
|
||||||
scrollTo(horizontalScrollBar()->sliderPosition() + static_cast<int>((width() * 0.80)),
|
scrollTo(horizontalScrollBar()->sliderPosition() + horizontalScrollStep(),
|
||||||
verticalScrollBar()->sliderPosition());
|
verticalScrollBar()->sliderPosition());
|
||||||
} else if (!isEdge(d2)) {
|
} else if (!isEdge(d2)) {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@ -533,13 +545,13 @@ void Viewer::scrollZigzag(scrollDirection d1, scrollDirection d2, bool forward)
|
|||||||
x = horizontalScrollBar()->minimum();
|
x = horizontalScrollBar()->minimum();
|
||||||
|
|
||||||
if (d2 == UP)
|
if (d2 == UP)
|
||||||
y = std::max(verticalScrollBar()->sliderPosition() - static_cast<int>((height() * 0.80)), verticalScrollBar()->minimum());
|
y = std::max(verticalScrollBar()->sliderPosition() - verticalScrollStep(), verticalScrollBar()->minimum());
|
||||||
else if (d2 == DOWN)
|
else if (d2 == DOWN)
|
||||||
y = std::min(verticalScrollBar()->sliderPosition() + static_cast<int>((height() * 0.80)), verticalScrollBar()->maximum());
|
y = std::min(verticalScrollBar()->sliderPosition() + verticalScrollStep(), verticalScrollBar()->maximum());
|
||||||
else if (d2 == LEFT)
|
else if (d2 == LEFT)
|
||||||
x = std::max(horizontalScrollBar()->sliderPosition() - static_cast<int>((width() * 0.80)), horizontalScrollBar()->minimum());
|
x = std::max(horizontalScrollBar()->sliderPosition() - horizontalScrollStep(), horizontalScrollBar()->minimum());
|
||||||
else // d2 == RIGHT
|
else // d2 == RIGHT
|
||||||
x = std::min(horizontalScrollBar()->sliderPosition() + static_cast<int>((width() * 0.80)), horizontalScrollBar()->maximum());
|
x = std::min(horizontalScrollBar()->sliderPosition() + horizontalScrollStep(), horizontalScrollBar()->maximum());
|
||||||
|
|
||||||
scrollTo(x, y);
|
scrollTo(x, y);
|
||||||
} else {
|
} else {
|
||||||
@ -596,12 +608,12 @@ void Viewer::keyPressEvent(QKeyEvent *event)
|
|||||||
else*/
|
else*/
|
||||||
|
|
||||||
if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)) {
|
if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_FORWARD_ACTION_Y)) {
|
||||||
nextPos = verticalScrollBar()->sliderPosition() + static_cast<int>((height() * 0.80));
|
nextPos = verticalScrollBar()->sliderPosition() + verticalScrollStep();
|
||||||
scrollDown();
|
scrollDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_ACTION_Y)) {
|
else if (key == ShortcutsManager::getShortcutsManager().getShortcut(AUTO_SCROLL_BACKWARD_ACTION_Y)) {
|
||||||
nextPos = verticalScrollBar()->sliderPosition() - static_cast<int>((height() * 0.80));
|
nextPos = verticalScrollBar()->sliderPosition() - verticalScrollStep();
|
||||||
scrollUp();
|
scrollUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,6 +164,9 @@ private:
|
|||||||
|
|
||||||
void moveAction(const QKeySequence &key);
|
void moveAction(const QKeySequence &key);
|
||||||
|
|
||||||
|
int verticalScrollStep() const;
|
||||||
|
int horizontalScrollStep() const;
|
||||||
|
|
||||||
//! ZigzagScroll
|
//! ZigzagScroll
|
||||||
enum scrollDirection { UP,
|
enum scrollDirection { UP,
|
||||||
DOWN,
|
DOWN,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user