Skip to content

Commit

Permalink
librarycontrol: simplify slotSelectSidebarItem
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jan 15, 2022
1 parent 46e5423 commit 63ee935
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,24 +835,18 @@ void LibraryControl::updateFocusedWidgetControls() {
}

void LibraryControl::slotSelectSidebarItem(double v) {
VERIFY_OR_DEBUG_ASSERT(m_pSidebarWidget) {
if (!m_pSidebarWidget) {
return;
}
if (v > 0) {
QApplication::postEvent(m_pSidebarWidget, new QKeyEvent(
QEvent::KeyPress,
(int)Qt::Key_Down, Qt::NoModifier, QString(), true));
QApplication::postEvent(m_pSidebarWidget, new QKeyEvent(
QEvent::KeyRelease,
(int)Qt::Key_Down, Qt::NoModifier, QString(), true));
} else if (v < 0) {
QApplication::postEvent(m_pSidebarWidget, new QKeyEvent(
QEvent::KeyPress,
(int)Qt::Key_Up, Qt::NoModifier, QString(), true));
QApplication::postEvent(m_pSidebarWidget, new QKeyEvent(
QEvent::KeyRelease,
(int)Qt::Key_Up, Qt::NoModifier, QString(), true));
if (v == 0) {
return;
}

const auto key = (v < 0) ? Qt::Key_Up : Qt::Key_Down;
const auto times = static_cast<unsigned short>(std::abs(v));
QKeyEvent event = QKeyEvent{
QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times};
QApplication::sendEvent(m_pSidebarWidget, &event);
}

void LibraryControl::slotSelectNextSidebarItem(double v) {
Expand Down

0 comments on commit 63ee935

Please sign in to comment.