Commit 091050c2 authored by Scott Wheeler's avatar Scott Wheeler

Show a drop indicator over the playlist where the dragged items would be

added.

http://ktown.kde.org/~wheeler/images/juk-drop-indicator.png

CCMAIL:69053-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=305006
parent e190a6d4
......@@ -46,7 +46,8 @@ PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const QString &name) :
m_updatePlaylistStack(true),
m_viewModeIndex(0),
m_hasSelection(false),
m_doingMultiSelect(false)
m_doingMultiSelect(false),
m_dropItem(0)
{
readConfig();
addColumn("Playlists", width());
......@@ -389,6 +390,12 @@ void PlaylistBox::contentsDropEvent(QDropEvent *e)
{
Item *i = static_cast<Item *>(itemAt(contentsToViewport(e->pos())));
decode(e, i);
if(m_dropItem) {
Item *old = m_dropItem;
m_dropItem = 0;
old->repaint();
}
}
void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
......@@ -404,8 +411,9 @@ void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
return;
}
if(itemAt(e->pos())) {
Item *target = static_cast<Item *>(itemAt(e->pos()));
Item *target = static_cast<Item *>(itemAt(contentsToViewport(e->pos())));
if(target) {
if(target->playlist() && target->playlist()->readOnly())
return;
......@@ -427,6 +435,20 @@ void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
}
else // the dropped items are coming from outside of JuK
e->accept(true);
if(m_dropItem != target) {
Item *old = m_dropItem;
if(e->isAccepted()) {
m_dropItem = target;
target->repaint();
}
else
m_dropItem = 0;
if(old)
old->repaint();
}
}
else {
......@@ -437,6 +459,16 @@ void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
}
}
void PlaylistBox::contentsDragLeaveEvent(QDragLeaveEvent *e)
{
if(m_dropItem) {
Item *old = m_dropItem;
m_dropItem = 0;
old->repaint();
}
KListView::contentsDragLeaveEvent(e);
}
void PlaylistBox::contentsMousePressEvent(QMouseEvent *e)
{
if(e->button() == LeftButton)
......
......@@ -83,6 +83,8 @@ public:
friend class Item;
typedef QValueList<Item *> ItemList;
Item *dropItem() const { return m_dropItem; }
public slots:
void paste();
void clear() {} // override the (destructive) default
......@@ -109,6 +111,7 @@ private:
virtual void decode(QMimeSource *s, Item *item);
virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
virtual void contentsDragLeaveEvent(QDragLeaveEvent *e);
virtual void contentsMousePressEvent(QMouseEvent *e);
virtual void contentsMouseReleaseEvent(QMouseEvent *e);
virtual void keyPressEvent(QKeyEvent *e);
......@@ -146,6 +149,7 @@ private:
KSelectAction *m_viewModeAction;
bool m_hasSelection;
bool m_doingMultiSelect;
Item *m_dropItem;
};
......
......@@ -46,19 +46,17 @@ ViewMode::~ViewMode()
}
void ViewMode::paintCell(PlaylistBox::Item *i,
void ViewMode::paintCell(PlaylistBox::Item *item,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int)
{
if(width < i->pixmap(column)->width())
if(width < item->pixmap(column)->width())
return;
if(m_needsRefresh)
updateHeights();
PlaylistBox::Item *item = static_cast<PlaylistBox::Item *>(i);
QFontMetrics fm = painter->fontMetrics();
int y = item->listView()->itemMargin();
......@@ -77,12 +75,15 @@ void ViewMode::paintCell(PlaylistBox::Item *i,
painter->drawPixmap(x, y, *pm);
}
y += pm->height() + fm.height() - fm.descent();
for(QStringList::Iterator it = m_lines[i].begin(); it != m_lines[i].end(); ++it) {
for(QStringList::Iterator it = m_lines[item].begin(); it != m_lines[item].end(); ++it) {
int x = (width - fm.width(*it)) / 2;
x = QMAX(x, item->listView()->itemMargin());
painter->drawText(x, y, *it);
y += fm.height() - fm.descent();
}
if(item == item->listView()->dropItem())
paintDropIndicator(painter, width, item->height());
}
PlaylistBox::Item *ViewMode::createSearchItem(PlaylistBox *box, SearchPlaylist *playlist,
......@@ -122,6 +123,8 @@ void ViewMode::updateIcons(int size)
}
}
void ViewMode::updateHeights()
{
const int width = m_playlistBox->viewport()->width();
......@@ -140,6 +143,22 @@ void ViewMode::updateHeights()
m_needsRefresh = false;
}
void ViewMode::paintDropIndicator(QPainter *painter, int width, int height) // static
{
static const int border = 1;
static const int lineWidth = 2;
QPen oldPen = painter->pen();
QPen newPen = oldPen;
newPen.setWidth(lineWidth);
newPen.setStyle(DotLine);
painter->setPen(newPen);
painter->drawRect(border, border, width - border * 2, height - border * 2);
painter->setPen(oldPen);
}
QStringList ViewMode::lines(const PlaylistBox::Item *item,
const QFontMetrics &fm,
int width) const
......@@ -193,6 +212,8 @@ void CompactViewMode::paintCell(PlaylistBox::Item *item,
int column, int width, int align)
{
item->KListViewItem::paintCell(painter, colorGroup, column, width, align);
if(item == item->listView()->dropItem())
paintDropIndicator(painter, width, item->height());
}
void CompactViewMode::setShown(bool shown)
......
......@@ -59,9 +59,8 @@ protected:
bool visible() const { return m_visible; }
void setVisible(bool v) { m_visible = v; }
void updateIcons(int size);
protected:
virtual void updateHeights();
static void paintDropIndicator(QPainter *painter, int width, int height);
signals:
void signalCreateSearchList(const PlaylistSearch &search,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment