Esempio n. 1
0
void
PlaylistBrowserNS::PlaylistBrowserView::keyPressEvent( QKeyEvent *event )
{
    QModelIndexList indices = selectedIndexes();
    // mind bug 305203
    if( indices.isEmpty() || state() != QAbstractItemView::NoState )
    {
        Amarok::PrettyTreeView::keyPressEvent( event );
        return;
    }

    switch( event->key() )
    {
        //activated() only works for current index, not all selected
        case Qt::Key_Enter:
        case Qt::Key_Return:
            insertIntoPlaylist( indices, Playlist::OnReturnPressedOnSelectedItems );
            return;
        case Qt::Key_Delete:
        {
            QActionList actions = actionsFor( indices ); // sets action targets
            if( actions.contains( m_removeTracksAction ) )
                m_removeTracksAction->trigger();
            else if( actions.contains( m_deletePlaylistAction ) )
                m_deletePlaylistAction->trigger();
            resetActionTargets();
            return;
        }
        default:
            break;
    }
    Amarok::PrettyTreeView::keyPressEvent( event );
}
Esempio n. 2
0
void PlaylistBrowserNS::PlaylistBrowserView::contextMenuEvent( QContextMenuEvent *event )
{
    QModelIndex clickedIdx = indexAt( event->pos() );

    QModelIndexList indices;
    if( clickedIdx.isValid() && selectedIndexes().contains( clickedIdx ) )
        indices << selectedIndexes();
    else if( clickedIdx.isValid() )
        indices << clickedIdx;

    QActionList actions = actionsFor( indices );
    if( actions.isEmpty() )
    {
        resetActionTargets();
        return;
    }

    KMenu menu;
    foreach( QAction *action, actions )
        menu.addAction( action );
    menu.exec( mapToGlobal( event->pos() ) );

    // We keep the items that the action need to be applied to.
    // Clear the data from all actions now that the context menu has executed.
    resetActionTargets();
}
Esempio n. 3
0
void
OpmlDirectoryView::contextMenuEvent( QContextMenuEvent *event )
{
    QModelIndex idx = indexAt( event->pos() );

    debug() << idx;

    event->accept();

    QVariant data = model()->data( idx, OpmlDirectoryModel::ActionRole );
    QActionList actions = data.value<QActionList>();

    if( actions.isEmpty() )
    {
        return;
    }

    KMenu menu;
    foreach( QAction *action, actions )
    {
        if( action )
            menu.addAction( action );
    }

    menu.exec( mapToGlobal( event->pos() ) );

    //We keep the items that the actions need to be applied to in the actions private data.
    //Clear the data from all actions now that the context menu has executed.
    foreach( QAction *action, actions )
        action->setData( QVariant() );
}
Esempio n. 4
0
QActionList LastFmTreeView::createBasicActions( const QModelIndexList & indices )
{
    Q_UNUSED( indices )
    QActionList actions;
    QModelIndex index = currentIndex();
    QVariant type = model()->data(index, LastFm::TypeRole);
    switch ( type.toInt() )
    {
        case LastFm::MyRecommendations:
        case LastFm::PersonalRadio:
        case LastFm::MixRadio:
        case LastFm::NeighborhoodRadio:
        case LastFm::FriendsChild:
        case LastFm::NeighborsChild:
        case LastFm::MyTagsChild:
        case LastFm::ArtistsChild:
        case LastFm::UserChildPersonal:
        case LastFm::UserChildNeighborhood:
        {
            if ( m_appendAction == 0 )
            {
                m_appendAction = new QAction ( KIcon ( "media-track-add-amarok" ), i18n ( "&Add to Playlist" ), this );
                m_appendAction->setProperty( "popupdropper_svg_id", "append" );
                connect ( m_appendAction, SIGNAL ( triggered() ), this, SLOT ( slotAppendChildTracks() ) );
            }

            actions.append ( m_appendAction );

            if ( m_loadAction == 0 )
            {
                m_loadAction = new QAction ( KIcon ( "folder-open" ), i18nc ( "Replace the currently loaded tracks with these", "&Replace Playlist" ), this );
                m_appendAction->setProperty( "popupdropper_svg_id", "load" );
                connect ( m_loadAction, SIGNAL ( triggered() ), this, SLOT ( slotPlayChildTracks() ) );
            }
            actions.append ( m_loadAction );
        }
        default:
            break;
    }
    return actions;
}
Esempio n. 5
0
void
LastFmTreeView::startDrag(Qt::DropActions supportedActions)
{
    DEBUG_BLOCK

    //setSelectionMode( QAbstractItemView::NoSelection );

    // When a parent item is dragged, startDrag() is called a bunch of times. Here we prevent that:
    m_dragMutex.lock();
    if( m_ongoingDrag )
    {
        m_dragMutex.unlock();
        return;
    }
    m_ongoingDrag = true;
    m_dragMutex.unlock();

    if( !m_pd )
        m_pd = The::popupDropperFactory()->createPopupDropper( Context::ContextView::self() );

    if( m_pd && m_pd->isHidden() )
    {

        QModelIndexList indices = selectedIndexes();

        QActionList actions = createBasicActions( indices );

        QFont font;
        font.setPointSize( 16 );
        font.setBold( true );

        foreach( QAction * action, actions )
            m_pd->addItem( The::popupDropperFactory()->createItem( action ) );


        m_currentItems.clear();
        foreach( const QModelIndex &index, indices )
        {
            if( index.isValid() && index.internalPointer() )
                m_currentItems << index;
        }

        PopupDropperItem* subItem;

        PopupDropper * morePud = 0;
        if ( actions.count() > 1 )
        {
            morePud = The::popupDropperFactory()->createPopupDropper( 0, true );

            foreach( QAction * action, actions )
                morePud->addItem( The::popupDropperFactory()->createItem( action ) );
        }
        else
            m_pd->addItem( The::popupDropperFactory()->createItem( actions[0] ) );

        //TODO: Keep bugging i18n team about problems with 3 dots
        if ( actions.count() > 1 )
        {
            subItem = m_pd->addSubmenu( &morePud, i18n( "More..." )  );
            The::popupDropperFactory()->adjustItem( subItem );
        }

        m_pd->show();
    }