?? queuemanager.cpp
字號:
/*************************************************************************** * copyright : (C) 2005 Seb Ruiz <me@sebruiz.net> * **************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#define DEBUG_PREFIX "QueueManager"#include "debug.h"#include "amarok.h"#include "amarokconfig.h" //check if dynamic mode#include "playlist.h"#include "queuemanager.h"#include <kapplication.h>#include <kguiitem.h>#include <klocale.h>#include <kpushbutton.h>#include <kurldrag.h>#include <kwin.h>#include <qpainter.h>#include <qptrlist.h>#include <qsimplerichtext.h>#include <qtooltip.h>#include <qvbox.h>///////////////////////////////////////////////////////////////////////////////////////////// CLASS QueueItem//////////////////////////////////////////////////////////////////////////////////////////voidQueueItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align ){ KListViewItem::paintCell( p, cg, column, width, align ); QString str = QString::number( ( static_cast<KListView *>( listView() ) )->itemIndex( this ) + 1 ); //draw the symbol's outline uint fw = p->fontMetrics().width( str ) + 2; const uint w = 16; //keep this even const uint h = height() - 2; p->setBrush( cg.highlight() ); p->setPen( cg.highlight().dark() ); //TODO blend with background color p->drawEllipse( width - fw - w/2, 1, w, h ); p->drawRect( width - fw, 1, fw, h ); p->setPen( cg.highlight() ); p->drawLine( width - fw, 2, width - fw, h - 1 ); fw += 2; //add some more padding p->setPen( cg.highlightedText() ); p->drawText( width - fw, 2, fw, h-1, Qt::AlignCenter, str );}///////////////////////////////////////////////////////////////////////////////////////////// CLASS QueueList//////////////////////////////////////////////////////////////////////////////////////////QueueList::QueueList( QWidget *parent, const char *name ) : KListView( parent, name ){ addColumn( i18n("Name") ); setResizeMode( QListView::LastColumn ); setSelectionMode( QListView::Extended ); setSorting( -1 ); setAcceptDrops( true ); setDragEnabled( true ); setDropVisualizer( true ); //the visualizer (a line marker) is drawn when dragging over tracks setDropVisualizerWidth( 3 );}voidQueueList::viewportPaintEvent( QPaintEvent *e ){ if( e ) KListView::viewportPaintEvent( e ); if( !childCount() && e ) { QPainter p( viewport() ); QString minimumText(i18n( "<div align=center>" "<h3>The Queue Manager</h3>" "To create a queue, " "<b>drag</b> tracks from the playlist, and " "<b>drop</b> them here.<br><br>" "Drag and drop tracks within the manager to resort queue orders." "</div>" ) ); QSimpleRichText t( minimumText, QApplication::font() ); if ( t.width()+30 >= viewport()->width() || t.height()+30 >= viewport()->height() ) //too big, giving up return; const uint w = t.width(); const uint h = t.height(); const uint x = (viewport()->width() - w - 30) / 2 ; const uint y = (viewport()->height() - h - 30) / 2 ; p.setBrush( colorGroup().background() ); p.drawRoundRect( x, y, w+30, h+30, (8*200)/w, (8*200)/h ); t.draw( &p, x+15, y+15, QRect(), colorGroup() ); }}voidQueueList::keyPressEvent( QKeyEvent *e ){ switch( e->key() ) { case Key_Delete: //remove removeSelected(); break; case CTRL+Key_Up: moveSelectedUp(); break; case CTRL+Key_Down: moveSelectedDown(); break; }}boolQueueList::hasSelection(){ QListViewItemIterator it( this, QListViewItemIterator::Selected ); if( !it.current() ) return false; return true;}QPtrList<QListViewItem>QueueList::selectedItems(){ QPtrList<QListViewItem> selected; QListViewItemIterator it( this, QListViewItemIterator::Selected ); for( ; it.current(); ++it ) selected.append( it.current() ); return selected;}voidQueueList::moveSelectedUp() // SLOT{ QPtrList<QListViewItem> selected = selectedItems(); bool item_moved = false; // Whilst it would be substantially faster to do this: ((*it)->itemAbove())->move( *it ), // this would only work for sequentially ordered items for( QListViewItem *item = selected.first(); item; item = selected.next() ) { if( item == itemAtIndex(0) ) continue; QListViewItem *after; item == itemAtIndex(1) ? after = 0: after = ( item->itemAbove() )->itemAbove(); moveItem( item, 0, after ); item_moved = true; } ensureItemVisible( selected.first() ); if( item_moved ) emit changed();}voidQueueList::moveSelectedDown() // SLOT{ QPtrList<QListViewItem> list = selectedItems(); bool item_moved = false; for( QListViewItem *item = list.last(); item; item = list.prev() ) { QListViewItem *after = item->nextSibling(); if( !after ) continue; moveItem( item, 0, after ); item_moved = true; } ensureItemVisible( list.last() ); if( item_moved ) emit changed();}voidQueueList::removeSelected() //SLOT{ setSelected( currentItem(), true ); bool item_removed = false; QPtrList<QListViewItem> selected = selectedItems(); for( QListViewItem *item = selected.first(); item; item = selected.next() ) { delete item; item_removed = true; } if( isEmpty() ) QueueManager::instance()->updateButtons(); if( item_removed ) emit changed();}voidQueueList::clear() // SLOT{ KListView::clear(); emit changed();}voidQueueList::contentsDragEnterEvent( QDragEnterEvent *e ){ debug() << "contentsDrageEnterEvent()" << endl; e->accept( e->source() == reinterpret_cast<KListView*>( Playlist::instance() )->viewport() );}voidQueueList::contentsDragMoveEvent( QDragMoveEvent *e ){ debug() << "contentsDrageMoveEvent()" << endl; KListView::contentsDragMoveEvent( e ); // Must be overloaded for dnd to work e->accept( ( e->source() == reinterpret_cast<KListView*>( Playlist::instance() )->viewport() ) || e->source() == viewport() );}voidQueueList::contentsDropEvent( QDropEvent *e ){ debug() << "contentsDragDropEvent()" << endl; if( e->source() == viewport() ) { KListView::contentsDropEvent( e ); emit changed(); } else { QListViewItem *parent = 0; QListViewItem *after; findDrop( e->pos(), parent, after );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -