playlistwindow.cpp

来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 1,244 行 · 第 1/4 页

CPP
1,244
字号
        //there are a few keypresses that we intercept        #define e static_cast<QKeyEvent*>(e)        if( e->key() == Key_F2 )        {            // currentItem is ALWAYS visible.            QListViewItem *item = pl->currentItem();            // intercept F2 for inline tag renaming            // NOTE: tab will move to the next tag            // NOTE: if item is still null don't select first item in playlist, user wouldn't want that. It's silly.            // TODO: berkus has solved the "inability to cancel" issue with KListView, but it's not in kdelibs yet..            // item may still be null, but this is safe            // NOTE: column 0 cannot be edited currently, hence we pick column 1            pl->rename( item, 1 ); //TODO what if this column is hidden?            return true;        }        if( e->state() & ControlButton )        {            int n = -1;            switch( e->key() )            {                case Key_0: n = 0; break;                case Key_1: n = 1; break;                case Key_2: n = 2; break;                case Key_3: n = 3; break;                case Key_4: n = 4; break;                case Key_5: n = 5; break;            }            if( n == 0 )            {                m_browsers->closeCurrentBrowser();                return true;            }            else if( n > 0 && n <= m_browsers->visibleCount() )            {                m_browsers->showHideVisibleBrowser( n - 1 );                return true;            }        }        if( o == m_lineEdit ) //the search lineedit        {            QListViewItem *item;            switch( e->key() )            {            case Key_Up:            case Key_Down:            case Key_PageDown:            case Key_PageUp:                pl->setFocus();                QApplication::sendEvent( pl, e );                return true;            case Key_Return:            case Key_Enter:                item = *It( pl, It::Visible );                m_lineEdit->clear();                pl->m_filtertimer->stop(); //HACK HACK HACK                if( e->state() & ControlButton )                {                    PLItemList in, out;                    if( e->state() & ShiftButton )                        for( It it( pl, It::Visible ); PlaylistItem *x = static_cast<PlaylistItem*>( *it ); ++it )                        {                            pl->queue( x, true );                            ( pl->m_nextTracks.contains( x ) ? in : out ).append( x );                        }                    else                    {                        It it( pl, It::Visible );                        pl->activate( *it );                        ++it;                        for( int i = 0; PlaylistItem *x = static_cast<PlaylistItem*>( *it ); ++i, ++it )                        {                            in.append( x );                            pl->m_nextTracks.insert( i, x );                        }                    }                    if( !in.isEmpty() || !out.isEmpty() )                        emit pl->queueChanged( in, out );                    pl->setFilter( "" );                    pl->ensureItemCentered( ( e->state() & ShiftButton ) ? item : pl->currentTrack() );                }                else                {                    pl->setFilter( "" );                    if( ( e->state() & ShiftButton ) && item )                    {                        pl->queue( item );                        pl->ensureItemCentered( item );                    }                    else                    {                        pl->activate( item );                        pl->showCurrentTrack();                    }                }                return true;            case Key_Escape:                m_lineEdit->clear();                return true;            default:                return false;            }        }        //following are for Playlist::instance() only        //we don't handle these in the playlist because often we manipulate the lineEdit too        if( o == pl )        {            if( pl->currentItem() && ( e->key() == Key_Up && pl->currentItem()->itemAbove() == 0 && !(e->state() & Qt::ShiftButton) ) )            {                QListViewItem *lastitem = *It( pl, It::Visible );                if ( !lastitem )                    return false;                while( lastitem->itemBelow() )                    lastitem = lastitem->itemBelow();                pl->currentItem()->setSelected( false );                pl->setCurrentItem( lastitem );                lastitem->setSelected( true );                pl->ensureItemVisible( lastitem );                return true;            }            if( pl->currentItem() && ( e->key() == Key_Down && pl->currentItem()->itemBelow() == 0 && !(e->state() & Qt::ShiftButton) ) )            {                pl->currentItem()->setSelected( false );                pl->setCurrentItem( *It( pl, It::Visible ) );                (*It( pl, It::Visible ))->setSelected( true );                pl->ensureItemVisible( *It( pl, It::Visible ) );                return true;            }            if( e->key() == Key_Delete )            {                pl->removeSelectedItems();                return true;            }            if( ( ( e->key() >= Key_0 && e->key() <= Key_Z ) || e->key() == Key_Backspace || e->key() == Key_Escape ) && ( !e->state() || e->state() == Qt::ShiftButton ) ) //only if shift or no modifier key is pressed and 0-Z or backspace or escape            {                m_lineEdit->setFocus();                QApplication::sendEvent( m_lineEdit, e );                return true;            }        }        #undef e        break;    default:        break;    }    return QWidget::eventFilter( o, e );}void PlaylistWindow::closeEvent( QCloseEvent *e ){#ifdef Q_WS_MAC    Q_UNUSED( e );    hide();#else    Amarok::genericEventHandler( this, e );#endif}void PlaylistWindow::showEvent( QShowEvent* ){    static bool firstTime = true;    if( firstTime )        Playlist::instance()->setFocus();    firstTime = false;}#include <qdesktopwidget.h>QSize PlaylistWindow::sizeHint() const{    return QApplication::desktop()->screenGeometry( (QWidget*)this ).size() / 1.5;}void PlaylistWindow::savePlaylist() const //SLOT{    Playlist *pl = Playlist::instance();    PlaylistItem *item = pl->firstChild();    if( item && !item->isVisible() )        item = static_cast<PlaylistItem*>( item->itemBelow() );    QString title = pl->playlistName();    if( item && title == i18n( "Untitled" ) )    {        QString artist = item->artist();        QString album  = item->album();        bool useArtist = true, useAlbum = true;        item = static_cast<PlaylistItem*>( item->itemBelow() );        for( ; item; item = static_cast<PlaylistItem*>( item->itemBelow() ) )        {            if( artist != item->artist() )                useArtist = false;            if( album  != item->album() )                useAlbum = false;            if( !useArtist && !useAlbum )                break;        }        if( useArtist && useAlbum )            title = i18n("%1 - %2").arg( artist, album );        else if( useArtist )            title = artist;        else if( useAlbum )            title = album;    }    QString path = PlaylistDialog::getSaveFileName( title, pl->proposeOverwriteOnSave() );    if( !path.isEmpty() && Playlist::instance()->saveM3U( path ) )        PlaylistWindow::self()->showBrowser( "PlaylistBrowser" );}void PlaylistWindow::slotBurnPlaylist() const //SLOT{    K3bExporter::instance()->exportCurrentPlaylist();}void PlaylistWindow::slotPlayMedia() //SLOT{    // Request location and immediately start playback    slotAddLocation( true );}void PlaylistWindow::slotAddLocation( bool directPlay ) //SLOT{    // open a file selector to add media to the playlist    KURL::List files;    //files = KFileDialog::getOpenURLs( QString::null, "*.*|" + i18n("All Files"), this, i18n("Add Media") );    KFileDialog dlg( QString::null, "*.*|", this, "openMediaDialog", true );    dlg.setCaption( directPlay ? i18n("Play Media (Files or URLs)") : i18n("Add Media (Files or URLs)") );    dlg.setMode( KFile::Files | KFile::Directory );    dlg.exec();    files = dlg.selectedURLs();    if( files.isEmpty() ) return;    const int options = directPlay ? Playlist::Append | Playlist::DirectPlay : Playlist::Append;    const KURL::List::ConstIterator end  = files.constEnd();    for(  KURL::List::ConstIterator it = files.constBegin(); it != end; ++it )        if( it == files.constBegin() )            Playlist::instance()->insertMedia( *it, options );        else            Playlist::instance()->insertMedia( *it, Playlist::Append );}void PlaylistWindow::slotAddStream() //SLOT{    bool ok;    QString url = KInputDialog::getText( i18n("Add Stream"), i18n("URL"), QString::null, &ok, this );    if ( !ok ) return;    KURL::List media( KURL::fromPathOrURL( url ) );    Playlist::instance()->insertMedia( media );}void PlaylistWindow::playLastfmPersonal() //SLOT{    if( !LastFm::Controller::checkCredentials() ) return;    const KURL url( QString( "lastfm://user/%1/personal" )                    .arg( AmarokConfig::scrobblerUsername() ) );    Playlist::instance()->insertMedia( url, Playlist::Append|Playlist::DirectPlay );}void PlaylistWindow::addLastfmPersonal() //SLOT{    if( !LastFm::Controller::checkCredentials() ) return;    const KURL url( QString( "lastfm://user/%1/personal" )                    .arg( AmarokConfig::scrobblerUsername() ) );    Playlist::instance()->insertMedia( url );}void PlaylistWindow::playLastfmNeighbor() //SLOT{    if( !LastFm::Controller::checkCredentials() ) return;    const KURL url( QString( "lastfm://user/%1/neighbours" )                    .arg( AmarokConfig::scrobblerUsername() ) );    Playlist::instance()->insertMedia( url, Playlist::Append|Playlist::DirectPlay );}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?