diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2011-08-29 18:52:55 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2011-08-29 18:52:55 +0000 |
| commit | 40461745dd60d98391959ceca8178a24426cfb52 (patch) | |
| tree | 89411791adb10c590fd8eeafd322d968d72ec43c /src/plugins/Ui | |
| parent | 32b643c3487be940ec4fa83ed3d6a4cb0800e87a (diff) | |
| download | qmmp-40461745dd60d98391959ceca8178a24426cfb52.tar.gz qmmp-40461745dd60d98391959ceca8178a24426cfb52.tar.bz2 qmmp-40461745dd60d98391959ceca8178a24426cfb52.zip | |
improved playlist selector
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2321 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Ui')
| -rw-r--r-- | src/plugins/Ui/skinned/playlistselector.cpp | 73 | ||||
| -rw-r--r-- | src/plugins/Ui/skinned/playlistselector.h | 8 |
2 files changed, 57 insertions, 24 deletions
diff --git a/src/plugins/Ui/skinned/playlistselector.cpp b/src/plugins/Ui/skinned/playlistselector.cpp index 8603ee082..2ea735539 100644 --- a/src/plugins/Ui/skinned/playlistselector.cpp +++ b/src/plugins/Ui/skinned/playlistselector.cpp @@ -38,7 +38,7 @@ PlayListSelector::PlayListSelector(PlayListManager *manager, QWidget *parent) : m_scrollable = false; m_left_pressed = false; m_right_pressed = false; - m_dest_index = -1; + m_moving = false; m_offset = 0; m_offset_max = 0; m_skin = Skin::instance(); @@ -127,10 +127,21 @@ void PlayListSelector::paintEvent(QPaintEvent *) QStringList names = m_pl_manager->playListNames(); int current = m_pl_manager->indexOf(m_pl_manager->currentPlayList()); int selected = m_pl_manager->indexOf(m_pl_manager->selectedPlayList()); - painter.setBrush(QBrush(m_selected_bg)); - painter.setPen(m_selected_bg); - painter.drawRect(m_rects.at(selected).x() - 2 - m_offset, 0, - m_rects.at(selected).width() + 3, height()-1); + + if(m_moving) + { + painter.setBrush(QBrush(m_normal_bg)); + painter.setPen(m_current); + painter.drawRect(m_rects.at(selected).x() - 2 - m_offset, 0, + m_rects.at(selected).width() + 3, height()-1); + } + else + { + painter.setBrush(QBrush(m_selected_bg)); + painter.setPen(m_selected_bg); + painter.drawRect(m_rects.at(selected).x() - 2 - m_offset, 0, + m_rects.at(selected).width() + 3, height()-1); + } for (int i = 0; i < m_rects.size(); ++i) { @@ -138,20 +149,29 @@ void PlayListSelector::paintEvent(QPaintEvent *) painter.setPen(m_current); else painter.setPen(m_normal); - painter.drawText(m_rects[i].x() - m_offset, m_metrics->ascent(), names.at(i)); + + if(!m_moving || i != selected) + painter.drawText(m_rects[i].x() - m_offset, m_metrics->ascent(), names.at(i)); if(i < m_rects.size() - 1) { painter.setPen(m_normal); painter.drawText(m_rects[i].x() + m_rects[i].width() - m_offset, m_metrics->ascent(), m_pl_separator); } - if(i == m_dest_index) - { - painter.setPen(m_current); - painter.drawLine(m_rects.at(i).x() - 2, height()-1, - m_rects.at(i).x() + m_rects.at(i).width() + 3, height()-1); - } } + + if(m_moving) + { + painter.setBrush(QBrush(m_selected_bg)); + painter.setPen(m_selected_bg); + painter.drawRect(m_mouse_pos.x() - m_press_offset - 2, 0, + m_rects.at(selected).width() + 3, height()); + + painter.setPen(selected == current ? m_current : m_normal); + painter.drawText(m_mouse_pos.x() - m_press_offset, + m_metrics->ascent(), names.at(selected)); + } + if(m_scrollable) { painter.drawPixmap(width()-40, 0, m_pixmap); @@ -200,7 +220,12 @@ void PlayListSelector::mousePressEvent (QMouseEvent *e) else if(e->button() == Qt::MidButton && selected) m_pl_manager->removePlayList(m_pl_manager->selectedPlayList()); else + { + m_moving = true; + m_mouse_pos = e->pos(); + m_press_offset = pp.x() - m_rects.at(m_pl_manager->selectedPlayListIndex()).x(); QWidget::mousePressEvent(e); + } } @@ -208,13 +233,9 @@ void PlayListSelector::mouseReleaseEvent (QMouseEvent *e) { m_left_pressed = false; m_right_pressed = false; + m_moving = false; drawButtons(); update(); - if(m_dest_index >= 0) - { - m_pl_manager->move(m_pl_manager->selectedPlayListIndex(), m_dest_index); - m_dest_index = -1; - } QWidget::mouseReleaseEvent(e); } @@ -228,12 +249,25 @@ void PlayListSelector::mouseDoubleClickEvent (QMouseEvent *e) void PlayListSelector::mouseMoveEvent(QMouseEvent *e) { + if(!m_moving) + { + QWidget::mouseMoveEvent(e); + return; + } + + m_mouse_pos = e->pos(); QPoint mp = e->pos(); mp.rx() += m_offset; + int dest = -1; for(int i = 0; i < m_rects.count(); ++i) { - if(mp.x() >= m_rects.at(i).x() && mp.x() <= m_rects.at(i).x() + m_rects.at(i).width()) + int x_delta = mp.x() - m_rects.at(i).x(); + if(x_delta < 0 || x_delta > m_rects.at(i).width()) + continue; + + if((x_delta > m_rects.at(i).width()/2 && m_pl_manager->selectedPlayListIndex() < i) || + (x_delta < m_rects.at(i).width()/2 && m_pl_manager->selectedPlayListIndex() > i)) { dest = i; break; @@ -241,12 +275,11 @@ void PlayListSelector::mouseMoveEvent(QMouseEvent *e) } if(dest == -1 || dest == m_pl_manager->selectedPlayListIndex()) { - m_dest_index = -1; update(); QWidget::mouseMoveEvent(e); return; } - m_dest_index = dest; + m_pl_manager->move(m_pl_manager->selectedPlayListIndex(), dest); update(); } diff --git a/src/plugins/Ui/skinned/playlistselector.h b/src/plugins/Ui/skinned/playlistselector.h index 4729ed64c..580e0dc80 100644 --- a/src/plugins/Ui/skinned/playlistselector.h +++ b/src/plugins/Ui/skinned/playlistselector.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009-2010 by Ilya Kotov * + * Copyright (C) 2009-2011 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -73,9 +73,9 @@ private: QColor m_normal, m_current, m_normal_bg, m_selected_bg; QPixmap m_pixmap; bool m_showButtons; - int m_offset, m_offset_max; - int m_dest_index; - bool m_left_pressed, m_right_pressed; + int m_offset, m_offset_max, m_press_offset; + bool m_moving, m_left_pressed, m_right_pressed; + QPoint m_mouse_pos; QString m_pl_separator; }; |
