Skip to content

Commit

Permalink
#178: Add ability to scroll through entry view using keyboard (#179)
Browse files Browse the repository at this point in the history
# Description

This commit adds ability to scroll through the entry view using the
keyboard arrow keys, page up/down, and the home/end keys.

Closes #178.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)

# How Has This Been Tested?

Inspected manually on macOS, Linux, and Windows.

# Checklist:

- [x] My code follows the style guidelines of this project (`black` for
Python
  code, `.clang-format` in the `src/jyut-dict` directory for C++)
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have translated my user-facing strings to all
currently-supported languages
- [x] I have made corresponding changes to the documentation
  • Loading branch information
aaronhktan authored Apr 17, 2024
1 parent effee4f commit 4a1b488
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/jyut-dict/components/entryview/entryscrollarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ EntryScrollArea::EntryScrollArea(std::shared_ptr<SQLUserDataUtils> sqlUserUtils,
_updateUITimer = new QTimer{this};

setFrameShape(QFrame::NoFrame);
verticalScrollBar()->setFocusPolicy(Qt::StrongFocus);

_scrollAreaWidget = new EntryScrollAreaWidget{sqlUserUtils, manager, this};

Expand Down Expand Up @@ -84,7 +85,43 @@ void EntryScrollArea::keyPressEvent(QKeyEvent *event)
{
if (isWindow() && event->key() == Qt::Key_Escape) {
close();
return;
} else {
// Not sure why setting the focus policy of the scroll bar
// doesn't work, but this is a workaround!
switch (event->key()) {
case Qt::Key_Down: {
verticalScrollBar()->triggerAction(
QAbstractSlider::SliderSingleStepAdd);
break;
}
case Qt::Key_Up: {
verticalScrollBar()->triggerAction(
QAbstractSlider::SliderSingleStepSub);
break;
}
case Qt::Key_PageDown: {
verticalScrollBar()->triggerAction(
QAbstractSlider::SliderPageStepAdd);
break;
}
case Qt::Key_PageUp: {
verticalScrollBar()->triggerAction(
QAbstractSlider::SliderPageStepSub);
break;
}
case Qt::Key_Home: {
verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMinimum);
break;
}
case Qt::Key_End: {
verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
break;
}
}
return;
}
QWidget::keyPressEvent(event);
}

void EntryScrollArea::setEntry(const Entry &entry)
Expand Down

0 comments on commit 4a1b488

Please sign in to comment.