From e665b5d7ade1e8fd131326c3508ee9a15aadf765 Mon Sep 17 00:00:00 2001 From: Tobias Rundstrom Date: Tue, 28 Feb 2006 21:01:26 -0300 Subject: [PATCH] Uberpimped the playlist into be fast and nice. --- Playlist.cpp | 10 +++++++++- PlaylistList.cpp | 30 +++++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Playlist.cpp b/Playlist.cpp index bf74185..7d25496 100644 --- a/Playlist.cpp +++ b/Playlist.cpp @@ -5,6 +5,7 @@ #include #include #include +#include PlaylistScrollButton::PlaylistScrollButton (PlaylistScroller *parent, uint normal, uint pressed) : Button (parent, normal, pressed, true) { @@ -14,6 +15,8 @@ PlaylistScrollButton::PlaylistScrollButton (PlaylistScroller *parent, uint norma void PlaylistScrollButton::mouseMoveEvent (QMouseEvent *event) { + PlaylistWindow *pw = dynamic_cast(window ()); + QPoint p (event->pos ()); int npos = pos().y()+p.y()-m_diffy; @@ -110,7 +113,12 @@ PlaylistWindow::doScroll (int pos) { int npos = ((float)pos) / (float)(m_scroller->getMax()) * float(m_list->height() - m_view->height()); m_list->setOffset (npos); - m_list->scroll (0, npos); + if (npos == 0) { + m_list->update (); + } else { + m_list->scroll (0, npos); + } + QApplication::sendPostedEvents (m_list, 0); } void diff --git a/PlaylistList.cpp b/PlaylistList.cpp index 249dfcb..78b4b88 100644 --- a/PlaylistList.cpp +++ b/PlaylistList.cpp @@ -12,9 +12,6 @@ PlaylistItem::PlaylistItem (PlaylistList *pl, uint id) m_isactive = false; m_isselected = false; m_req = false; - if (getSelected ()) { - qDebug ("trasigt!"); - } pl->addItem (this); } @@ -44,6 +41,9 @@ PlaylistList::PlaylistList (QWidget *parent) : QWidget (parent) XMMSHandler *xmmsh = XMMSHandler::getInstance (); Skin *skin = Skin::getInstance (); + setAttribute (Qt::WA_NoBackground); + setFocusPolicy (Qt::StrongFocus); + connect (skin, SIGNAL (skinChanged (Skin *)), this, SLOT (setPixmaps(Skin *))); @@ -250,17 +250,22 @@ PlaylistList::paintEvent (QPaintEvent *event) int ch = event->rect().height(); int sitem = cy / getFontH(); int eitem = (cy + ch) / getFontH(); + int mod = m_offset - (getFontH() * sitem); if (eitem > m_items->count()) eitem = m_items->count(); + QString q; + QRect r; + for (i = sitem; i < eitem; i++) { - QRect r (3, getFontH()*(i-sitem), size().width(), getFontH()); - if (event->region().contains (r)) { + r.setRect(0, (getFontH()*(i-sitem)) - mod, + size().width(), getFontH()); + /* + if (event->rect().contains (r)) { + */ PlaylistItem *item = m_items->value (i); - QString q; - q.sprintf ("%d. ", i+1); - q += item->text (); + q = QString::number (i + 1) + ". " + item->text (); if (item->getSelected ()) { paint.fillRect (r, QBrush (m_color_selected)); @@ -276,12 +281,15 @@ PlaylistList::paintEvent (QPaintEvent *event) paint.drawText (r, q); } + /* } + */ } - if (getFontH()*(i-sitem) < size().height()) { - paint.eraseRect (QRect (0, getFontH()*(i-sitem), size().width(), - size().height()-getFontH()*(i-sitem))); + if ((getFontH()*(i-sitem) - mod) < size().height()) { + paint.eraseRect (QRect (0, (getFontH()*(i-sitem) - mod), + size().width(), + size().height()-(getFontH()*(i-sitem) - mod))); } paint.end ();