From 13b9c475232eb273664a751a99f4d40366e59e40 Mon Sep 17 00:00:00 2001 From: Tobias Rundstrom Date: Sat, 11 Mar 2006 19:37:41 -0300 Subject: [PATCH] Key up and down works in playlist and repositions the view. --- Playlist.cpp | 2 ++ PlaylistList.cpp | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Playlist.cpp b/Playlist.cpp index bd9fc2b..1b13903 100644 --- a/Playlist.cpp +++ b/Playlist.cpp @@ -84,6 +84,8 @@ PlaylistScroller::repositionButton (void) PlaylistWidget *pw = dynamic_cast(parent ()); /* x = 182.6 / (454 - 242) * 224 */ int bpos = (int)((float)(pw->getOffset ()) / (float)m_max * (float) getMax ()); + if (bpos > getMax ()) + bpos = getMax (); m_button->move (0, bpos); } diff --git a/PlaylistList.cpp b/PlaylistList.cpp index fa8f294..8c04f4a 100644 --- a/PlaylistList.cpp +++ b/PlaylistList.cpp @@ -468,18 +468,30 @@ PlaylistList::keyPressEvent (QKeyEvent *event) { XMMSHandler *xmmsh = XMMSHandler::getInstance (); + QWidget *w = dynamic_cast(parent()); + QSize s = w->size (); + int lastitem = (m_offset + s.height()) / getFontH () - 1; + if (lastitem > m_items->count()) + lastitem = m_items->count() - 1; + int firstitem = m_offset / getFontH(); switch (event->key ()) { case Qt::Key_Down: { int i = m_selected->last (); i ++; - if (i > m_items->count ()) - i = m_items->count (); + + if (i > (m_items->count () - 1)) + i = m_items->count () - 1; + m_selected->clear (); m_selected->append (i); + if (i > lastitem) + setOffset (m_offset += getFontH ()); + update (); + emit sizeChanged (size()); } break; case Qt::Key_Up: @@ -490,8 +502,11 @@ PlaylistList::keyPressEvent (QKeyEvent *event) i = 0; m_selected->clear (); m_selected->append (i); + if (i < firstitem) + setOffset (m_offset -= getFontH ()); update (); + emit sizeChanged (size()); } break; case Qt::Key_Backspace: