From eb9b2635d5981265b45b2ff6eb1b6f78a2e6bb34 Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 20 Feb 2014 17:06:21 +0100 Subject: [PATCH] [ButtonWithMenu] Fixed selectPreviousItem not selecting first item --- src/lib/tools/buttonwithmenu.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/lib/tools/buttonwithmenu.cpp b/src/lib/tools/buttonwithmenu.cpp index 198f1aafc..3d53b40e4 100644 --- a/src/lib/tools/buttonwithmenu.cpp +++ b/src/lib/tools/buttonwithmenu.cpp @@ -58,7 +58,7 @@ void ButtonWithMenu::selectPreviousItem() { int index = m_items.indexOf(m_currentItem) - 1; - if (index > 0) { + if (index >= 0) { setCurrentIndex(index); } } @@ -124,20 +124,11 @@ void ButtonWithMenu::setCurrentIndex(int index, bool emitSignal) void ButtonWithMenu::wheelEvent(QWheelEvent* event) { - int currItemIndex = m_items.indexOf(m_currentItem); - int itemsCount = m_items.count(); - - if (itemsCount == 0) { - return; - } - if (event->delta() > 0) { - if (currItemIndex != 0) { - setCurrentItem(m_items.at(currItemIndex - 1)); - } + selectPreviousItem(); } - else if (currItemIndex < itemsCount - 1) { - setCurrentItem(m_items.at(currItemIndex + 1)); + else { + selectNextItem(); } event->accept();