当前位置: 首页>>代码示例>>C++>>正文


C++ TrackModelItem类代码示例

本文整理汇总了C++中TrackModelItem的典型用法代码示例。如果您正苦于以下问题:C++ TrackModelItem类的具体用法?C++ TrackModelItem怎么用?C++ TrackModelItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TrackModelItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QModelIndex

void
DynamicWidget::steeringChanged()
{
    // When steering changes, toss all the tracks that are upcoming, and re-fetch.
    // We have to find the currently playing item
    QModelIndex playing;
    for ( int i = 0; i < m_view->proxyModel()->rowCount( QModelIndex() ); ++i )
    {
        const QModelIndex  cur = m_view->proxyModel()->index( i, 0, QModelIndex() );
        TrackModelItem* item = m_view->proxyModel()->itemFromIndex( m_view->proxyModel()->mapToSource( cur ) );
        if ( item && item->isPlaying() )
        {
            playing = cur;
            break;
        }
    }
    if ( !playing.isValid() )
        return;

    const int upcoming = m_view->proxyModel()->rowCount( QModelIndex() ) - 1 - playing.row();
    tDebug() << "Removing tracks after current in station, found" << upcoming;

    QModelIndexList toRemove;
    for ( int i = playing.row() + 1; i < m_view->proxyModel()->rowCount( QModelIndex() ); i++ )
    {
        toRemove << m_view->proxyModel()->index( i, 0, QModelIndex() );
    }

    m_view->proxyModel()->remove( toRemove );

    m_playlist->generator()->fetchNext();
}
开发者ID:tehzed,项目名称:tomahawk,代码行数:32,代码来源:DynamicWidget.cpp

示例2: qDebug

QMimeData*
TrackModel::mimeData( const QModelIndexList &indexes ) const
{
    qDebug() << Q_FUNC_INFO;

    QByteArray queryData;
    QDataStream queryStream( &queryData, QIODevice::WriteOnly );

    foreach ( const QModelIndex& i, indexes )
    {
        if ( i.column() > 0 )
            continue;

        QModelIndex idx = index( i.row(), 0, i.parent() );
        TrackModelItem* item = itemFromIndex( idx );
        if ( item )
        {
            const query_ptr& query = item->query();
            queryStream << qlonglong( &query );
        }
    }

    QMimeData* mimeData = new QMimeData();
    mimeData->setData( "application/tomahawk.query.list", queryData );

    return mimeData;
}
开发者ID:tiegz,项目名称:tomahawk,代码行数:27,代码来源:trackmodel.cpp

示例3: indexAt

void
TrackView::onCustomContextMenu( const QPoint& pos )
{
    m_contextMenu->clear();

    QModelIndex idx = indexAt( pos );
    idx = idx.sibling( idx.row(), 0 );
    setContextMenuIndex( idx );

    if ( !idx.isValid() )
        return;

    if ( model() && !model()->isReadOnly() )
        m_contextMenu->setSupportedActions( m_contextMenu->supportedActions() | ContextMenu::ActionDelete );

    QList<query_ptr> queries;
    foreach ( const QModelIndex& index, selectedIndexes() )
    {
        if ( index.column() )
            continue;

        TrackModelItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( index ) );
        if ( item && !item->query().isNull() )
            queries << item->query();
    }

    m_contextMenu->setQueries( queries );
    m_contextMenu->exec( mapToGlobal( pos ) );
}
开发者ID:jamesaxl,项目名称:tomahawk,代码行数:29,代码来源:trackview.cpp

示例4: QVariant

QVariant
CollectionModel::data( const QModelIndex& index, int role ) const
{
    if ( role != Qt::DisplayRole )
        return QVariant();

    TrackModelItem* entry = itemFromIndex( index );
    if ( !entry )
        return QVariant();

    const query_ptr& query = entry->query();
    if ( query.isNull() )
    {
        if ( !index.column() )
        {
            return entry->caption.isEmpty() ? "Unknown" : entry->caption;
        }

        if ( index.column() == 1 )
        {
            return entry->childCount;
        }

        return QVariant( "" );
    }

    if ( !query->numResults() )
    {
        switch( index.column() )
        {
            case 0:
                return query->track();
                break;
        }
    }
    else
    {
        switch( index.column() )
        {
            case 0:
                return query->results().first()->track();
                break;

            case 1:
                return QVariant();
                break;

            case 2:
                return TomahawkUtils::timeToString( query->results().first()->duration() );
                break;

            case 3:
                return query->results().first()->collection()->source()->friendlyName();
                break;
        }
    }

    return QVariant();
}
开发者ID:LittleForker,项目名称:tomahawk,代码行数:59,代码来源:collectionmodel.cpp

示例5: itemFromIndex

Tomahawk::result_ptr
TrackProxyModel::currentItem() const
{
    TrackModelItem* item = itemFromIndex( mapToSource( currentIndex() ) );
    if ( item && !item->query().isNull() && item->query()->playable() )
        return item->query()->results().at( 0 );
    return Tomahawk::result_ptr();
}
开发者ID:sawdog,项目名称:tomahawk,代码行数:8,代码来源:trackproxymodel.cpp

示例6: result_ptr

Tomahawk::result_ptr
TrackProxyModelPlaylistInterface::currentItem() const
{
    if ( m_proxyModel.isNull() )
        return Tomahawk::result_ptr();

    TrackProxyModel* proxyModel = m_proxyModel.data();

    TrackModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->currentIndex() ) );
    if ( item && !item->query().isNull() && item->query()->playable() )
        return item->query()->results().at( 0 );
    return Tomahawk::result_ptr();
}
开发者ID:mguentner,项目名称:tomahawk,代码行数:13,代码来源:TrackProxyModelPlaylistInterface.cpp

示例7:

void
TrackView::currentChanged( const QModelIndex& current, const QModelIndex& previous )
{
    QTreeView::currentChanged( current, previous );

    if ( !m_updateContextView )
        return;

    TrackModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( current ) );
    if ( item )
    {
        ViewManager::instance()->context()->setQuery( item->query() );
    }
}
开发者ID:MechanisM,项目名称:tomahawk,代码行数:14,代码来源:trackview.cpp

示例8: itemFromIndex

QList< Tomahawk::query_ptr >
TrackProxyModel::tracks()
{
    QList<Tomahawk::query_ptr> queries;

    for ( int i = 0; i < rowCount( QModelIndex() ); i++ )
    {
        TrackModelItem* item = itemFromIndex( mapToSource( index( i, 0 ) ) );
        if ( item )
            queries << item->query();
    }

    return queries;
}
开发者ID:LittleForker,项目名称:tomahawk,代码行数:14,代码来源:trackproxymodel.cpp

示例9: NewClosure

void
TrackView::startAutoPlay( const QModelIndex& index )
{
    if ( tryToPlayItem( index ) )
        return;

    // item isn't playable but still resolving
    TrackModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( index ) );
    if ( item && !item->query().isNull() && !item->query()->resolvingFinished() )
    {
        m_autoPlaying = item->query(); // So we can kill it if user starts autoplaying this playlist again
        NewClosure( item->query().data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( autoPlayResolveFinished( Tomahawk::query_ptr, int ) ),
                    item->query(), index.row() );
        return;
    }
开发者ID:MechanisM,项目名称:tomahawk,代码行数:15,代码来源:trackview.cpp

示例10:

QList< Tomahawk::query_ptr >
TrackProxyModelPlaylistInterface::tracks()
{
    if ( m_proxyModel.isNull() )
        return QList< Tomahawk::query_ptr >();

    TrackProxyModel* proxyModel = m_proxyModel.data();
    QList<Tomahawk::query_ptr> queries;

    for ( int i = 0; i < proxyModel->rowCount( QModelIndex() ); i++ )
    {
        TrackModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->index( i, 0 ) ) );
        if ( item )
            queries << item->query();
    }

    return queries;
}
开发者ID:mguentner,项目名称:tomahawk,代码行数:18,代码来源:TrackProxyModelPlaylistInterface.cpp

示例11: trackCount

void
RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::query_ptr& query )
{
    int count = trackCount();
    unsigned int playtime = query->playedBy().second;

    if ( count )
    {
        TrackModelItem* oldestItem = itemFromIndex( index( count - 1, 0, QModelIndex() ) );
        if ( oldestItem->query()->playedBy().second >= playtime )
            return;

        TrackModelItem* youngestItem = itemFromIndex( index( 0, 0, QModelIndex() ) );
        if ( youngestItem->query()->playedBy().second <= playtime )
            insert( query, 0 );
        else
        {
            for ( int i = 0; i < count - 1; i++ )
            {
                TrackModelItem* item1 = itemFromIndex( index( i, 0, QModelIndex() ) );
                TrackModelItem* item2 = itemFromIndex( index( i + 1, 0, QModelIndex() ) );

                if ( item1->query()->playedBy().second >= playtime && item2->query()->playedBy().second <= playtime )
                {
                    insert( query, i + 1 );
                    break;
                }
            }
        }
    }
    else
        insert( query, 0 );

    if ( trackCount() > (int)m_limit )
        remove( m_limit );

    ensureResolved();
}
开发者ID:Ramblurr,项目名称:tomahawk,代码行数:38,代码来源:RecentlyPlayedModel.cpp

示例12: itemActivated

void
TrackView::onItemActivated( const QModelIndex& index )
{
    if ( !index.isValid() )
        return;

    TrackModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( index ) );
    if ( item && !item->query().isNull() && item->query()->numResults() )
    {
        tDebug() << "Result activated:" << item->query()->toString() << item->query()->results().first()->url();
        m_proxyModel->setCurrentIndex( index );
        AudioEngine::instance()->playItem( m_proxyModel->getPlaylistInterface(), item->query()->results().first() );
    }

    emit itemActivated( index );
}
开发者ID:jamesaxl,项目名称:tomahawk,代码行数:16,代码来源:trackview.cpp

示例13: itemFromIndex

void
TrackModel::setCurrentItem( const QModelIndex& index )
{
    TrackModelItem* oldEntry = itemFromIndex( m_currentIndex );
    if ( oldEntry )
    {
        oldEntry->setIsPlaying( false );
    }

    TrackModelItem* entry = itemFromIndex( index );
    if ( index.isValid() && entry && !entry->query().isNull() )
    {
        m_currentIndex = index;
        m_currentUuid = entry->query()->id();
        entry->setIsPlaying( true );
    }
    else
    {
        m_currentIndex = QModelIndex();
        m_currentUuid = QString();
    }
}
开发者ID:chakra-project,项目名称:tomahawk,代码行数:22,代码来源:trackmodel.cpp

示例14: if

void
PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, bool useAvatars ) const
{
    TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
    Q_ASSERT( item );

    QStyleOptionViewItemV4 opt = option;
    prepareStyleOption( &opt, index, item );
    opt.text.clear();

    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( m_view->header()->visualIndex( index.column() ) > 0 )
        return;

    QPixmap pixmap;
    QString artist, track, upperText, lowerText;
    source_ptr source = item->query()->playedBy().first;

    if ( item->query()->results().count() )
    {
        artist = item->query()->results().first()->artist()->name();
        track = item->query()->results().first()->track();
    }
    else
    {
        artist = item->query()->artist();
        track = item->query()->track();
    }

    if ( source.isNull() )
    {
        upperText = artist;
        lowerText = track;
    }
    else
    {
        upperText = QString( "%1 - %2" ).arg( artist ).arg( track );
        QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ) );

        if ( source == SourceList::instance()->getLocal() )
            lowerText = QString( "played %1 ago by you" ).arg( playtime );
        else
            lowerText = QString( "played %1 ago by %2" ).arg( playtime ).arg( source->friendlyName() );

        if ( useAvatars )
            pixmap = source->avatar( Source::FancyStyle );
    }

    if ( pixmap.isNull() && !useAvatars )
        pixmap = QPixmap( RESPATH "images/track-placeholder.png" );
    else if ( pixmap.isNull() && useAvatars )
        pixmap = m_defaultAvatar;

    painter->save();
    {
        QRect r = opt.rect.adjusted( 3, 6, 0, -6 );

        // Paint Now Playing Speaker Icon
        if ( item->isPlaying() )
        {
            r.adjust( 0, 0, 0, 0 );
            QRect npr = r.adjusted( 3, r.height() / 2 - m_nowPlayingIcon.height() / 2, 18 - r.width(), -r.height() / 2 + m_nowPlayingIcon.height() / 2  );
            painter->drawPixmap( npr, m_nowPlayingIcon );
            r.adjust( 22, 0, 0, 0 );
        }

        painter->setPen( opt.palette.text().color() );

        QRect ir = r.adjusted( 4, 0, -option.rect.width() + option.rect.height() - 8 + r.left(), 0 );

        QPixmap scover;
        if ( m_cache.contains( pixmap.cacheKey() ) )
        {
            scover = m_cache.value( pixmap.cacheKey() );
        }
        else
        {
            scover = pixmap.scaled( ir.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
            m_cache.insert( pixmap.cacheKey(), scover );
        }
        painter->drawPixmap( ir, scover );

        QFont boldFont = opt.font;
        boldFont.setBold( true );

        r.adjust( ir.width() + 12, 0, -12, 0 );
        painter->setFont( boldFont );
        QString text = painter->fontMetrics().elidedText( upperText, Qt::ElideRight, r.width() );
        painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_topOption );


        painter->setFont( opt.font);
        text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, r.width() );
        painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_bottomOption );
    }
    painter->restore();
}
开发者ID:ralepinski,项目名称:tomahawk,代码行数:98,代码来源:playlistitemdelegate.cpp

示例15: arrowRect

void
PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
    Q_ASSERT( item );

    QStyleOptionViewItemV4 opt = option;
    prepareStyleOption( &opt, index, item );
    opt.text.clear();
    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( m_view->hoveredIndex().row() == index.row() && m_view->hoveredIndex().column() == index.column() &&
       ( index.column() == TrackModel::Artist || index.column() == TrackModel::Album ) )
    {
        opt.rect.setWidth( opt.rect.width() - 16 );
        QRect arrowRect( opt.rect.x() + opt.rect.width(), opt.rect.y() + 1, opt.rect.height() - 2, opt.rect.height() - 2 );

        if ( m_arrowIcon.height() != arrowRect.height() )
            m_arrowIcon = m_arrowIcon.scaled( arrowRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
        painter->drawPixmap( arrowRect, m_arrowIcon );
    }

    painter->save();

    if ( index.column() == TrackModel::Score )
    {
        QColor barColor( 167, 183, 211 ); // This matches the sidebar (sourcetreeview.cpp:672)
        if ( opt.state & QStyle::State_Selected )
            painter->setPen( opt.palette.brightText().color() );
        else
            painter->setPen( barColor );

        QRect r = opt.rect.adjusted( 3, 3, -6, -4 );
        painter->drawRect( r );

        QRect fillR = r;
        int fillerWidth = (int)( index.data().toFloat() * (float)fillR.width() );
        fillR.adjust( 0, 0, -( fillR.width() - fillerWidth ), 0 );

        if ( opt.state & QStyle::State_Selected )
            painter->setBrush( opt.palette.brightText().color() );
        else
            painter->setBrush( barColor );

        painter->drawRect( fillR );
    }
    else if ( item->isPlaying() )
    {
        {
            QRect r = opt.rect.adjusted( 3, 0, 0, 0 );

            // Paint Now Playing Speaker Icon
            if ( m_view->header()->visualIndex( index.column() ) == 0 )
            {
                r.adjust( 0, 0, 0, -3 );
                painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), m_nowPlayingIcon );
                r.adjust( 25, 0, 0, 3 );
            }

            painter->setPen( opt.palette.text().color() );
            QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
            painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_centerOption );
        }
    }
    else
    {
        painter->setPen( opt.palette.text().color() );
        QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, opt.rect.width() - 3 );
        painter->drawText( opt.rect.adjusted( 3, 1, 0, 0 ), text, m_centerOption );
    }

    painter->restore();
}
开发者ID:ralepinski,项目名称:tomahawk,代码行数:73,代码来源:playlistitemdelegate.cpp


注:本文中的TrackModelItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。