Commit 3bacf88cb72bc715e0606602ee28a663b4efb767

  • Tree SHA1: eed5744
  • Parent SHA1: bcfb7d0 (fix ExpandButton, adding a delay before submenu rolls out. this also fixes the redraw problem when pressing "clear".)
  • raw diff | raw patch
more drag and drop fixes

svn path=/trunk/kdeextragear-1/amarok/; revision=256743
TODO
(1 / 1)
  
99
1010 * fix: app freezing when renaming the file that's currently playing
1111
12 * fix: sample looping @ end of track or pause
12 * fix: sample looping @ end of track or pause (fixed?)
1313
1414 * fix: redirected URLs do not work
1515
  
3838#include <fileref.h>
3939#include <tag.h>
4040
41
4142PlaylistItem::PlaylistItem( QListView* parent, const KURL &url ) :
4243 KListViewItem( parent, nameForUrl( url ) )
4344{
8080 m_hasMetaInfo = false;
8181 m_isDir = false;
8282 m_bIsGlowing = false;
83 m_isMarker = false;
8483 setDragEnabled( true );
8584 setDropEnabled( true );
8685}
195195 }
196196
197197 pPainterBuf.drawText( margin, 0, width - margin, height(), align, text( column ) );
198
199 // draw drop indicator line
200 if ( m_isMarker )
201 {
202 QPen linePen( Qt::red, 0, Qt::DashLine );
203 pPainterBuf.setPen( linePen );
204 pPainterBuf.drawLine( 0, height() - 1, width - 1, height() - 1 );
205 }
206198
207199 // draw column separator line
208200 if ( listView() && QString( listView()->name() ) == "PlaylistWidget" )
  
6363 void setGlowing( bool b ) { m_bIsGlowing = b; }
6464 void setGlowCol( QColor col ) { m_glowCol = col; }
6565
66 bool isMarker() const { return m_isMarker; }
67 void setMarker( bool on ) { m_isMarker = on; }
68
6966 private:
7067 QString nameForUrl( const KURL &url ) const;
7168 void init();
7272 bool m_hasMetaInfo;
7373 KURL m_url;
7474 bool m_bIsGlowing;
75 bool m_isMarker;
7675 bool m_isDir;
7776 QString m_sPath;
7877 QColor m_glowCol;
  
11/***************************************************************************
2 playlistwidget.cpp - description
3 -------------------
4 begin : Don Dez 5 2002
5 copyright : (C) 2002 by Mark Kretschmann
6 email :
2 playlistwidget.cpp - description
3 -------------------
4 begin : Don Dez 5 2002
5 copyright : (C) 2002 by Mark Kretschmann
6 email :
77***************************************************************************/
88
99/***************************************************************************
2222#include "browserwidget.h"
2323#include "playlistitem.h"
2424
25#include <qbrush.h>
2526#include <qcolor.h>
2627#include <qcursor.h>
2728#include <qevent.h>
2829#include <qheader.h>
2930#include <qmessagebox.h>
31#include <qpainter.h>
3032#include <qpoint.h>
3133#include <qpopupmenu.h>
34#include <qrect.h>
3235#include <qstringlist.h>
3336#include <qtimer.h>
3437#include <qvaluelist.h>
5353PlaylistWidget::PlaylistWidget( QWidget *parent, const char *name ) :
5454 KListView( parent, name ),
5555 m_GlowCount( 100 ),
56 m_GlowAdd( 5 ),
57 m_pMarkerItem( NULL ),
58 m_pMarkerItemPrev( NULL )
56 m_GlowAdd( 5 )
5957{
6058 setName( "PlaylistWidget" );
6159 setFocusPolicy( QWidget::ClickFocus );
6260 setPaletteBackgroundColor( pApp->m_bgColor );
6361 setShowSortIndicator( true );
62 setDropVisualizer( false ); // we handle the drawing for ourselves
63 setDropVisualizerWidth( 3 );
6464
65 addColumn( i18n("Trackname"), 280 );
66 addColumn( i18n("Title"), 200 );
67 addColumn( i18n("Album"), 100 );
68 addColumn( i18n("Artist"), 100 );
69 addColumn( i18n("Year"), 40 );
70 addColumn( i18n("Comment"), 80 );
71 addColumn( i18n("Genre"), 80 );
72 addColumn( i18n("Directory"), 80 );
65 addColumn( i18n( "Trackname" ), 280 );
66 addColumn( i18n( "Title" ), 200 );
67 addColumn( i18n( "Album" ), 100 );
68 addColumn( i18n( "Artist" ), 100 );
69 addColumn( i18n( "Year" ), 40 );
70 addColumn( i18n( "Comment" ), 80 );
71 addColumn( i18n( "Genre" ), 80 );
72 addColumn( i18n( "Directory" ), 80 );
7373
7474 setSorting( -1 );
7575 connect( header(), SIGNAL( clicked( int ) ), this, SLOT( slotHeaderClicked( int ) ) );
7676
77 connect( this, SIGNAL( contentsMoving( int, int ) ), this, SLOT( slotEraseMarker() ) );
78
7779 setCurrentTrack( NULL );
7880 m_GlowColor.setRgb( 0xff, 0x40, 0x40 );
7981
9797void PlaylistWidget::contentsDragMoveEvent( QDragMoveEvent* e )
9898{
9999 e->acceptAction();
100 m_pMarkerItem = static_cast<PlaylistItem*>( itemAt( contentsToViewport( e->pos() ) ) );
101100
102 if ( m_pMarkerItem != m_pMarkerItemPrev )
103 {
104 eraseMarker();
101 QListViewItem *parent;
102 QListViewItem *after;
103 findDrop( e->pos(), parent, after );
105104
106 if ( m_pMarkerItem != NULL )
107 {
108 m_pMarkerItem->setMarker( true );
109 repaintItem( m_pMarkerItem );
110 }
105 QRect tmpRect = drawDropVisualizer( 0, parent, after );
111106
112 m_pMarkerItemPrev = m_pMarkerItem;
107 if ( tmpRect != m_marker )
108 {
109 slotEraseMarker();
110 m_marker = tmpRect;
111 viewport() ->repaint( tmpRect );
113112 }
114113}
115114
116115
117116void PlaylistWidget::contentsDragLeaveEvent( QDragLeaveEvent* )
118117{
119 eraseMarker();
118 slotEraseMarker();
120119}
121120
122121
123122void PlaylistWidget::contentsDropEvent( QDropEvent* e )
124123{
125 eraseMarker();
126 m_dropRecursionCounter = 0;
124 slotEraseMarker();
127125
128 if ( pApp->m_optDropMode == "Recursively" )
129 m_dropRecursively = true;
130 else
131 m_dropRecursively = false;
126 QListViewItem *parent, *after;
127 findDrop( e->pos(), parent, after );
132128
133 KURL::List urlList;
134
135 if ( e->source() == NULL ) // dragging from outside amarok
129 if ( e->source() == viewport() )
136130 {
137 if ( !KURLDrag::decode( e, urlList ) || urlList.isEmpty() )
138 return ;
139
140 setUpdatesEnabled( false );
141 m_pDropCurrentItem = static_cast<PlaylistItem*>( itemAt( contentsToViewport( e->pos() ) ) );
142 playlistDrop( urlList );
131 movableDropEvent( parent, after );
143132 }
144133 else
145134 {
146 PlaylistItem *srcItem, *newItem;
135 m_dropRecursionCounter = 0;
147136
148 m_pDropCurrentItem = static_cast<PlaylistItem*>( itemAt( contentsToViewport( e->pos() ) ) );
149
150 if ( !m_pDropCurrentItem )
151 m_pDropCurrentItem = ( PlaylistItem* ) 1;
152
153 if ( e->source()->parent() == this )
154 srcItem = static_cast<PlaylistItem*>( firstChild() );
137 if ( pApp->m_optDropMode == "Recursively" )
138 m_dropRecursively = true;
155139 else
156 srcItem = static_cast<PlaylistItem*>( pApp->m_pBrowserWin->m_pBrowserWidget->firstChild() );
140 m_dropRecursively = false;
157141
158 bool containsDirs = false;
142 KURL::List urlList;
159143
160 setUpdatesEnabled( false );
144 if ( e->source() == NULL ) // dragging from outside amarok
145 {
146 if ( !KURLDrag::decode( e, urlList ) || urlList.isEmpty() )
147 return ;
161148
162 while ( srcItem != NULL )
149 m_pDropCurrentItem = static_cast<PlaylistItem*>( after );
150 playlistDrop( urlList );
151 }
152 else
163153 {
164 newItem = static_cast<PlaylistItem*>( srcItem->nextSibling() );
154 PlaylistItem *srcItem, *newItem;
155 m_pDropCurrentItem = static_cast<PlaylistItem*>( after );
165156
166 if ( srcItem->isSelected() )
157 srcItem = static_cast<PlaylistItem*>( pApp->m_pBrowserWin->m_pBrowserWidget->firstChild() );
158 bool containsDirs = false;
159
160 while ( srcItem != NULL )
167161 {
168 urlList.append( srcItem->url() );
162 newItem = static_cast<PlaylistItem*>( srcItem->nextSibling() );
169163
170 if ( srcItem->isDir() )
171 containsDirs = true;
172 // if drag is inside this widget, do a move operation
173 if ( e->source()->parent() == this )
174 delete srcItem;
164 if ( srcItem->isSelected() )
165 {
166 urlList.append( srcItem->url() );
167
168 if ( srcItem->isDir() )
169 containsDirs = true;
170 }
171 srcItem = newItem;
175172 }
176 srcItem = newItem;
177 }
178 if ( containsDirs && pApp->m_optDropMode == "Ask" )
179 {
180 QPopupMenu popup( this );
181 popup.insertItem( i18n("Add Recursively"), this, SLOT( slotSetRecursive() ) );
182 popup.exec( mapToGlobal( QPoint( e->pos().x() - 120, e->pos().y() - 20 ) ) );
183 }
173 if ( containsDirs && pApp->m_optDropMode == "Ask" )
174 {
175 QPopupMenu popup( this );
176 popup.insertItem( i18n( "Add Recursively" ), this, SLOT( slotSetRecursive() ) );
177 popup.exec( mapToGlobal( QPoint( e->pos().x() - 120, e->pos().y() - 20 ) ) );
178 }
184179
185 playlistDrop( urlList );
180 playlistDrop( urlList );
181 }
186182 }
187
188 setUpdatesEnabled( true );
189 triggerUpdate();
190 e->acceptAction();
191183}
192184
193185
203203 if ( fileItem->isLink() && !pApp->m_optFollowSymlinks && m_dropRecursionCounter >= 2 )
204204 continue;
205205
206 if ( m_dropRecursionCounter >= 50 ) //no infinite loops, please
206 if ( m_dropRecursionCounter >= 50 ) //no infinite loops, please
207207 continue;
208208
209209 if ( !m_dropRecursively && m_dropRecursionCounter >= 2 )
243243}
244244
245245
246void PlaylistWidget::viewportPaintEvent( QPaintEvent *e )
247{
248 QListView::viewportPaintEvent( e );
246249
250 if ( m_marker.isValid() && e->rect().intersects( m_marker ) )
251 {
252 QPainter painter( viewport() );
253 QBrush brush( QBrush::Dense4Pattern );
254 brush.setColor( Qt::red );
255
256 // This is where we actually draw the drop-visualizer
257 painter.fillRect( m_marker, brush );
258 }
259}
260
261
247262QListViewItem* PlaylistWidget::currentTrack()
248263{
249264 return m_pCurrentTrack;
304304
305305PlaylistItem* PlaylistWidget::addItem( PlaylistItem *after, KURL url )
306306{
307 PlaylistItem *pNewItem;
307 PlaylistItem * pNewItem;
308308
309// we're abusing *after as a flag. value 1 == append to list
309 // we're abusing *after as a flag. value 1 == append to list
310310 if ( ( unsigned long ) after == 1 )
311311 {
312312 pNewItem = new PlaylistItem( this, lastItem(), url );
326326}
327327
328328
329void PlaylistWidget::eraseMarker()
330{
331 if ( m_pMarkerItemPrev != NULL )
332 {
333 m_pMarkerItemPrev->setMarker( false );
334 repaintItem( m_pMarkerItemPrev );
335 }
336}
337
338
339329// SLOTS ----------------------------------------------
340330
341331void PlaylistWidget::slotGlowTimer()
393393void PlaylistWidget::slotHeaderClicked( int section )
394394{
395395 QPopupMenu popup( this );
396 int MENU_ASCENDING = popup.insertItem( i18n("Sort Ascending") );
397 int MENU_DESCENDING = popup.insertItem( i18n("Sort Descending") );
396 int MENU_ASCENDING = popup.insertItem( i18n( "Sort Ascending" ) );
397 int MENU_DESCENDING = popup.insertItem( i18n( "Sort Descending" ) );
398398
399399 QPoint menuPos = QCursor::pos();
400400 menuPos.setX( menuPos.x() - 20 );
412412 setSorting( section, false );
413413 sort();
414414 setSorting( -1 );
415 }
416}
417
418
419void PlaylistWidget::slotEraseMarker()
420{
421 if ( m_marker.isValid() )
422 {
423 QRect rect = m_marker;
424 m_marker = QRect();
425 viewport() ->repaint( rect, true );
415426 }
416427}
417428
  
2828class QDragMoveEvent;
2929class QDropEvent;
3030class QFocusEvent;
31class QPaintEvent;
3132class QPoint;
33class QRect;
3234class QString;
3335class QStringList;
3436class QTimer;
5454 void unglowItems();
5555 void triggerSignalPlay();
5656 PlaylistItem* addItem( PlaylistItem *after, KURL url );
57 void eraseMarker();
58
5957 void contentsDropEvent( QDropEvent* e);
6058
6159// ATTRIBUTES ------
6363 void slotSetRecursive();
6464 void slotTextChanged( const QString &str );
6565 void slotHeaderClicked( int section );
66 void slotEraseMarker();
6667
6768 signals:
6869 void signalJump();
7373 void contentsDragMoveEvent( QDragMoveEvent* e );
7474 void contentsDragLeaveEvent( QDragLeaveEvent* );
7575 void focusInEvent( QFocusEvent *e );
76 void viewportPaintEvent( QPaintEvent *e );
7677
7778 void playlistDrop( KURL::List urlList );
7879 PlaylistItem* playlistInsertItem( KURL srcUrl, PlaylistItem* dstItem );
9191 int m_GlowAdd;
9292 QColor m_GlowColor;
9393 QListViewItem *m_pCurrentTrack;
94 PlaylistItem *m_pMarkerItem;
95 PlaylistItem *m_pMarkerItemPrev;
94 QRect m_marker;
9695};
9796#endif