Commit 3bacf88cb72bc715e0606602ee28a663b4efb767
- Diff rendering mode:
- inline
- side by side
TODO
(1 / 1)
|   | |||
| 9 | 9 | ||
| 10 | 10 | * fix: app freezing when renaming the file that's currently playing | |
| 11 | 11 | ||
| 12 | * fix: sample looping @ end of track or pause | ||
| 12 | * fix: sample looping @ end of track or pause (fixed?) | ||
| 13 | 13 | ||
| 14 | 14 | * fix: redirected URLs do not work | |
| 15 | 15 |
amarok/playlistitem.cpp
(1 / 9)
|   | |||
| 38 | 38 | #include <fileref.h> | |
| 39 | 39 | #include <tag.h> | |
| 40 | 40 | ||
| 41 | |||
| 41 | 42 | PlaylistItem::PlaylistItem( QListView* parent, const KURL &url ) : | |
| 42 | 43 | KListViewItem( parent, nameForUrl( url ) ) | |
| 43 | 44 | { | |
| … | … | ||
| 80 | 80 | m_hasMetaInfo = false; | |
| 81 | 81 | m_isDir = false; | |
| 82 | 82 | m_bIsGlowing = false; | |
| 83 | m_isMarker = false; | ||
| 84 | 83 | setDragEnabled( true ); | |
| 85 | 84 | setDropEnabled( true ); | |
| 86 | 85 | } | |
| … | … | ||
| 195 | 195 | } | |
| 196 | 196 | ||
| 197 | 197 | 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 | } | ||
| 206 | 198 | ||
| 207 | 199 | // draw column separator line | |
| 208 | 200 | if ( listView() && QString( listView()->name() ) == "PlaylistWidget" ) |
amarok/playlistitem.h
(0 / 4)
|   | |||
| 63 | 63 | void setGlowing( bool b ) { m_bIsGlowing = b; } | |
| 64 | 64 | void setGlowCol( QColor col ) { m_glowCol = col; } | |
| 65 | 65 | ||
| 66 | bool isMarker() const { return m_isMarker; } | ||
| 67 | void setMarker( bool on ) { m_isMarker = on; } | ||
| 68 | |||
| 69 | 66 | private: | |
| 70 | 67 | QString nameForUrl( const KURL &url ) const; | |
| 71 | 68 | void init(); | |
| … | … | ||
| 72 | 72 | bool m_hasMetaInfo; | |
| 73 | 73 | KURL m_url; | |
| 74 | 74 | bool m_bIsGlowing; | |
| 75 | bool m_isMarker; | ||
| 76 | 75 | bool m_isDir; | |
| 77 | 76 | QString m_sPath; | |
| 78 | 77 | QColor m_glowCol; |
amarok/playlistwidget.cpp
(103 / 90)
|   | |||
| 1 | 1 | /*************************************************************************** | |
| 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 : | ||
| 7 | 7 | ***************************************************************************/ | |
| 8 | 8 | ||
| 9 | 9 | /*************************************************************************** | |
| … | … | ||
| 22 | 22 | #include "browserwidget.h" | |
| 23 | 23 | #include "playlistitem.h" | |
| 24 | 24 | ||
| 25 | #include <qbrush.h> | ||
| 25 | 26 | #include <qcolor.h> | |
| 26 | 27 | #include <qcursor.h> | |
| 27 | 28 | #include <qevent.h> | |
| 28 | 29 | #include <qheader.h> | |
| 29 | 30 | #include <qmessagebox.h> | |
| 31 | #include <qpainter.h> | ||
| 30 | 32 | #include <qpoint.h> | |
| 31 | 33 | #include <qpopupmenu.h> | |
| 34 | #include <qrect.h> | ||
| 32 | 35 | #include <qstringlist.h> | |
| 33 | 36 | #include <qtimer.h> | |
| 34 | 37 | #include <qvaluelist.h> | |
| … | … | ||
| 53 | 53 | PlaylistWidget::PlaylistWidget( QWidget *parent, const char *name ) : | |
| 54 | 54 | KListView( parent, name ), | |
| 55 | 55 | m_GlowCount( 100 ), | |
| 56 | m_GlowAdd( 5 ), | ||
| 57 | m_pMarkerItem( NULL ), | ||
| 58 | m_pMarkerItemPrev( NULL ) | ||
| 56 | m_GlowAdd( 5 ) | ||
| 59 | 57 | { | |
| 60 | 58 | setName( "PlaylistWidget" ); | |
| 61 | 59 | setFocusPolicy( QWidget::ClickFocus ); | |
| 62 | 60 | setPaletteBackgroundColor( pApp->m_bgColor ); | |
| 63 | 61 | setShowSortIndicator( true ); | |
| 62 | setDropVisualizer( false ); // we handle the drawing for ourselves | ||
| 63 | setDropVisualizerWidth( 3 ); | ||
| 64 | 64 | ||
| 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 ); | ||
| 73 | 73 | ||
| 74 | 74 | setSorting( -1 ); | |
| 75 | 75 | connect( header(), SIGNAL( clicked( int ) ), this, SLOT( slotHeaderClicked( int ) ) ); | |
| 76 | 76 | ||
| 77 | connect( this, SIGNAL( contentsMoving( int, int ) ), this, SLOT( slotEraseMarker() ) ); | ||
| 78 | |||
| 77 | 79 | setCurrentTrack( NULL ); | |
| 78 | 80 | m_GlowColor.setRgb( 0xff, 0x40, 0x40 ); | |
| 79 | 81 | ||
| … | … | ||
| 97 | 97 | void PlaylistWidget::contentsDragMoveEvent( QDragMoveEvent* e ) | |
| 98 | 98 | { | |
| 99 | 99 | e->acceptAction(); | |
| 100 | m_pMarkerItem = static_cast<PlaylistItem*>( itemAt( contentsToViewport( e->pos() ) ) ); | ||
| 101 | 100 | ||
| 102 | if ( m_pMarkerItem != m_pMarkerItemPrev ) | ||
| 103 | { | ||
| 104 | eraseMarker(); | ||
| 101 | QListViewItem *parent; | ||
| 102 | QListViewItem *after; | ||
| 103 | findDrop( e->pos(), parent, after ); | ||
| 105 | 104 | ||
| 106 | if ( m_pMarkerItem != NULL ) | ||
| 107 | { | ||
| 108 | m_pMarkerItem->setMarker( true ); | ||
| 109 | repaintItem( m_pMarkerItem ); | ||
| 110 | } | ||
| 105 | QRect tmpRect = drawDropVisualizer( 0, parent, after ); | ||
| 111 | 106 | ||
| 112 | m_pMarkerItemPrev = m_pMarkerItem; | ||
| 107 | if ( tmpRect != m_marker ) | ||
| 108 | { | ||
| 109 | slotEraseMarker(); | ||
| 110 | m_marker = tmpRect; | ||
| 111 | viewport() ->repaint( tmpRect ); | ||
| 113 | 112 | } | |
| 114 | 113 | } | |
| 115 | 114 | ||
| 116 | 115 | ||
| 117 | 116 | void PlaylistWidget::contentsDragLeaveEvent( QDragLeaveEvent* ) | |
| 118 | 117 | { | |
| 119 | eraseMarker(); | ||
| 118 | slotEraseMarker(); | ||
| 120 | 119 | } | |
| 121 | 120 | ||
| 122 | 121 | ||
| 123 | 122 | void PlaylistWidget::contentsDropEvent( QDropEvent* e ) | |
| 124 | 123 | { | |
| 125 | eraseMarker(); | ||
| 126 | m_dropRecursionCounter = 0; | ||
| 124 | slotEraseMarker(); | ||
| 127 | 125 | ||
| 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 ); | ||
| 132 | 128 | ||
| 133 | KURL::List urlList; | ||
| 134 | |||
| 135 | if ( e->source() == NULL ) // dragging from outside amarok | ||
| 129 | if ( e->source() == viewport() ) | ||
| 136 | 130 | { | |
| 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 ); | ||
| 143 | 132 | } | |
| 144 | 133 | else | |
| 145 | 134 | { | |
| 146 | PlaylistItem *srcItem, *newItem; | ||
| 135 | m_dropRecursionCounter = 0; | ||
| 147 | 136 | ||
| 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; | ||
| 155 | 139 | else | |
| 156 | srcItem = static_cast<PlaylistItem*>( pApp->m_pBrowserWin->m_pBrowserWidget->firstChild() ); | ||
| 140 | m_dropRecursively = false; | ||
| 157 | 141 | ||
| 158 | bool containsDirs = false; | ||
| 142 | KURL::List urlList; | ||
| 159 | 143 | ||
| 160 | setUpdatesEnabled( false ); | ||
| 144 | if ( e->source() == NULL ) // dragging from outside amarok | ||
| 145 | { | ||
| 146 | if ( !KURLDrag::decode( e, urlList ) || urlList.isEmpty() ) | ||
| 147 | return ; | ||
| 161 | 148 | ||
| 162 | while ( srcItem != NULL ) | ||
| 149 | m_pDropCurrentItem = static_cast<PlaylistItem*>( after ); | ||
| 150 | playlistDrop( urlList ); | ||
| 151 | } | ||
| 152 | else | ||
| 163 | 153 | { | |
| 164 | newItem = static_cast<PlaylistItem*>( srcItem->nextSibling() ); | ||
| 154 | PlaylistItem *srcItem, *newItem; | ||
| 155 | m_pDropCurrentItem = static_cast<PlaylistItem*>( after ); | ||
| 165 | 156 | ||
| 166 | if ( srcItem->isSelected() ) | ||
| 157 | srcItem = static_cast<PlaylistItem*>( pApp->m_pBrowserWin->m_pBrowserWidget->firstChild() ); | ||
| 158 | bool containsDirs = false; | ||
| 159 | |||
| 160 | while ( srcItem != NULL ) | ||
| 167 | 161 | { | |
| 168 | urlList.append( srcItem->url() ); | ||
| 162 | newItem = static_cast<PlaylistItem*>( srcItem->nextSibling() ); | ||
| 169 | 163 | ||
| 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; | ||
| 175 | 172 | } | |
| 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 | } | ||
| 184 | 179 | ||
| 185 | playlistDrop( urlList ); | ||
| 180 | playlistDrop( urlList ); | ||
| 181 | } | ||
| 186 | 182 | } | |
| 187 | |||
| 188 | setUpdatesEnabled( true ); | ||
| 189 | triggerUpdate(); | ||
| 190 | e->acceptAction(); | ||
| 191 | 183 | } | |
| 192 | 184 | ||
| 193 | 185 | ||
| … | … | ||
| 203 | 203 | if ( fileItem->isLink() && !pApp->m_optFollowSymlinks && m_dropRecursionCounter >= 2 ) | |
| 204 | 204 | continue; | |
| 205 | 205 | ||
| 206 | if ( m_dropRecursionCounter >= 50 ) //no infinite loops, please | ||
| 206 | if ( m_dropRecursionCounter >= 50 ) //no infinite loops, please | ||
| 207 | 207 | continue; | |
| 208 | 208 | ||
| 209 | 209 | if ( !m_dropRecursively && m_dropRecursionCounter >= 2 ) | |
| … | … | ||
| 243 | 243 | } | |
| 244 | 244 | ||
| 245 | 245 | ||
| 246 | void PlaylistWidget::viewportPaintEvent( QPaintEvent *e ) | ||
| 247 | { | ||
| 248 | QListView::viewportPaintEvent( e ); | ||
| 246 | 249 | ||
| 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 | |||
| 247 | 262 | QListViewItem* PlaylistWidget::currentTrack() | |
| 248 | 263 | { | |
| 249 | 264 | return m_pCurrentTrack; | |
| … | … | ||
| 304 | 304 | ||
| 305 | 305 | PlaylistItem* PlaylistWidget::addItem( PlaylistItem *after, KURL url ) | |
| 306 | 306 | { | |
| 307 | PlaylistItem *pNewItem; | ||
| 307 | PlaylistItem * pNewItem; | ||
| 308 | 308 | ||
| 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 | ||
| 310 | 310 | if ( ( unsigned long ) after == 1 ) | |
| 311 | 311 | { | |
| 312 | 312 | pNewItem = new PlaylistItem( this, lastItem(), url ); | |
| … | … | ||
| 326 | 326 | } | |
| 327 | 327 | ||
| 328 | 328 | ||
| 329 | void PlaylistWidget::eraseMarker() | ||
| 330 | { | ||
| 331 | if ( m_pMarkerItemPrev != NULL ) | ||
| 332 | { | ||
| 333 | m_pMarkerItemPrev->setMarker( false ); | ||
| 334 | repaintItem( m_pMarkerItemPrev ); | ||
| 335 | } | ||
| 336 | } | ||
| 337 | |||
| 338 | |||
| 339 | 329 | // SLOTS ---------------------------------------------- | |
| 340 | 330 | ||
| 341 | 331 | void PlaylistWidget::slotGlowTimer() | |
| … | … | ||
| 393 | 393 | void PlaylistWidget::slotHeaderClicked( int section ) | |
| 394 | 394 | { | |
| 395 | 395 | 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" ) ); | ||
| 398 | 398 | ||
| 399 | 399 | QPoint menuPos = QCursor::pos(); | |
| 400 | 400 | menuPos.setX( menuPos.x() - 20 ); | |
| … | … | ||
| 412 | 412 | setSorting( section, false ); | |
| 413 | 413 | sort(); | |
| 414 | 414 | setSorting( -1 ); | |
| 415 | } | ||
| 416 | } | ||
| 417 | |||
| 418 | |||
| 419 | void PlaylistWidget::slotEraseMarker() | ||
| 420 | { | ||
| 421 | if ( m_marker.isValid() ) | ||
| 422 | { | ||
| 423 | QRect rect = m_marker; | ||
| 424 | m_marker = QRect(); | ||
| 425 | viewport() ->repaint( rect, true ); | ||
| 415 | 426 | } | |
| 416 | 427 | } | |
| 417 | 428 |
amarok/playlistwidget.h
(5 / 4)
|   | |||
| 28 | 28 | class QDragMoveEvent; | |
| 29 | 29 | class QDropEvent; | |
| 30 | 30 | class QFocusEvent; | |
| 31 | class QPaintEvent; | ||
| 31 | 32 | class QPoint; | |
| 33 | class QRect; | ||
| 32 | 34 | class QString; | |
| 33 | 35 | class QStringList; | |
| 34 | 36 | class QTimer; | |
| … | … | ||
| 54 | 54 | void unglowItems(); | |
| 55 | 55 | void triggerSignalPlay(); | |
| 56 | 56 | PlaylistItem* addItem( PlaylistItem *after, KURL url ); | |
| 57 | void eraseMarker(); | ||
| 58 | |||
| 59 | 57 | void contentsDropEvent( QDropEvent* e); | |
| 60 | 58 | ||
| 61 | 59 | // ATTRIBUTES ------ | |
| … | … | ||
| 63 | 63 | void slotSetRecursive(); | |
| 64 | 64 | void slotTextChanged( const QString &str ); | |
| 65 | 65 | void slotHeaderClicked( int section ); | |
| 66 | void slotEraseMarker(); | ||
| 66 | 67 | ||
| 67 | 68 | signals: | |
| 68 | 69 | void signalJump(); | |
| … | … | ||
| 73 | 73 | void contentsDragMoveEvent( QDragMoveEvent* e ); | |
| 74 | 74 | void contentsDragLeaveEvent( QDragLeaveEvent* ); | |
| 75 | 75 | void focusInEvent( QFocusEvent *e ); | |
| 76 | void viewportPaintEvent( QPaintEvent *e ); | ||
| 76 | 77 | ||
| 77 | 78 | void playlistDrop( KURL::List urlList ); | |
| 78 | 79 | PlaylistItem* playlistInsertItem( KURL srcUrl, PlaylistItem* dstItem ); | |
| … | … | ||
| 91 | 91 | int m_GlowAdd; | |
| 92 | 92 | QColor m_GlowColor; | |
| 93 | 93 | QListViewItem *m_pCurrentTrack; | |
| 94 | PlaylistItem *m_pMarkerItem; | ||
| 95 | PlaylistItem *m_pMarkerItemPrev; | ||
| 94 | QRect m_marker; | ||
| 96 | 95 | }; | |
| 97 | 96 | #endif |

