Exemple #1
0
bool
SourcesModel::removeItem( const Tomahawk::source_ptr& source )
{
//    qDebug() << "Removing source item from SourceTree:" << source->friendlyName();

    QModelIndex idx;
    int rows = rowCount();
    for ( int row = 0; row < rows; row++ )
    {
        QModelIndex idx = index( row, 0, QModelIndex() );
        CollectionItem* item = static_cast< CollectionItem* >( idx.internalPointer() );
        if ( item && item->source() == source )
        {
//            qDebug() << "Found removed source item:" << item->source()->userName();
            beginRemoveRows( QModelIndex(), row, row );
            m_rootItem->removeChild( item );
            endRemoveRows();

//             onItemOffline( idx );

            delete item;
            return true;
        }
    }

    return false;
}
Exemple #2
0
CollectionItem<Entity, Assembly, AssemblyItem>* AssemblyItem::add_multi_model_collection_item(EntityContainer& entities)
{
    CollectionItem<Entity, Assembly, AssemblyItem>* item =
        new MultiModelCollectionItem<Entity, Assembly, AssemblyItem>(
            m_editor_context,
            new_guid(),
            EntityTraits<Entity>::get_human_readable_collection_type_name(),
            m_assembly,
            this);

    item->add_items(entities);

    return item;
}
Exemple #3
0
CollectionItem<Entity, Assembly, AssemblyItem>* AssemblyItem::add_single_model_collection_item(EntityContainer& entities)
{
    CollectionItem<Entity, Assembly, AssemblyItem>* item =
        new SingleModelCollectionItem<Entity, Assembly, AssemblyItem>(
            new_guid(),
            EntityTraits<Entity>::get_human_readable_collection_type_name(),
            m_assembly,
            this,
            m_project_builder);

    item->add_items(entities);

    return item;
}
Exemple #4
0
    CollectionItem<Entity, Assembly>* add_multi_model_collection_item(EntityContainer& entities)
    {
        CollectionItem<Entity, Assembly>* item =
            new MultiModelCollectionItem<Entity, Assembly>(
                new_guid(),
                EntityTraits<Entity>::get_human_readable_collection_type_name(),
                *m_assembly,
                m_project_builder);

        item->add_items(entities);

        m_assembly_item->addChild(item);

        return item;
    }
Exemple #5
0
    CollectionItem<Entity, Scene>* add_multi_model_collection_item(
        Scene&              scene,
        EntityContainer&    entities,
        ProjectBuilder&     project_builder)
    {
        CollectionItem<Entity, Scene>* item =
            new MultiModelCollectionItem<Entity, Scene>(
            new_guid(),
            EntityTraits<Entity>::get_human_readable_collection_type_name(),
            scene,
            project_builder);

        item->add_items(entities);

        m_tree_widget->addTopLevelItem(item);

        return item;
    }
void KNMemoryManager::updateCacheEntry( KNArticleCollection::Ptr c )
{
  CollectionItem *ci;
  int oldSize=0;

  if( (ci=findCacheEntry(c, true)) ) { // item is taken from the list
    oldSize=ci->storageSize;
    ci->sync();
    kDebug(5003) <<"KNMemoryManager::updateCacheEntry() : collection (" << c->name() <<") updated";
  }
  else {
    ci=new CollectionItem(c);
    kDebug(5003) <<"KNMemoryManager::updateCacheEntry() : collection (" << c->name() <<") added";
  }

  mColList.append(ci);
  c_ollCacheSize += (ci->storageSize - oldSize);
  checkMemoryUsageCollections();
}
void CollectionItemDialogPrivate::dialogFinished(const int &ret)
{

    if (itemPtr && ret == KDialog::Accepted) {
        CollectionItem *item = itemPtr.data();

        item->setTitle(ui->titleEdit->text());
        item->setComment(ui->commentEdit->toPlainText());
        item->setAuthor(ui->authorEdit->text());
        item->setRating(ui->ratingEdit->rating());
        item->setDate(ui->dateEdit->dateTime());
        item->setUrl(ui->urlEdit->url());

        if (item->isCollection()) {
            static_cast<Collection*>(item)->setIcon(ui->iconButton->icon());
        }
    }

}
Exemple #8
0
    Impl(
        AssemblyItem*   assembly_item,
        Assembly*       assembly,
        Scene&          scene,
        ProjectBuilder& project_builder,
        ParamArray&     settings)
      : m_assembly_item(assembly_item)
      , m_assembly(assembly)
      , m_scene(scene)
      , m_project_builder(project_builder)
    {
        m_color_collection_item = add_single_model_collection_item<ColorEntity>(assembly->colors());

        m_assembly_item->addChild(
            m_texture_collection_item =
                new TextureCollectionItem(
                    *m_assembly,
                    assembly->textures(),
                    m_project_builder,
                    settings));

        m_texture_instance_collection_item = add_single_model_collection_item<TextureInstance>(assembly->texture_instances());
        m_texture_instance_collection_item->set_allow_creation(false);

        m_bsdf_collection_item = add_multi_model_collection_item<BSDF>(assembly->bsdfs());
        m_edf_collection_item = add_multi_model_collection_item<EDF>(assembly->edfs());
        m_surface_shader_collection_item = add_multi_model_collection_item<SurfaceShader>(assembly->surface_shaders());
        m_material_collection_item = add_single_model_collection_item<Material>(assembly->materials());
        m_light_collection_item = add_multi_model_collection_item<Light>(assembly->lights());
        
        m_assembly_item->addChild(
            m_object_collection_item =
                new ObjectCollectionItem(
                    *m_assembly,
                    assembly->objects(),
                    m_project_builder,
                    settings));
        
        m_object_instance_collection_item = add_collection_item(assembly->object_instances());
    }
Exemple #9
0
void
SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    if ( option.rect.height() == 0 )
        return;

    QStyleOptionViewItemV4 optIndentation = option;
    QStyleOptionViewItemV4 opt = option;

    painter->save();
    painter->setRenderHint( QPainter::TextAntialiasing );
    painter->setRenderHint( QPainter::SmoothPixmapTransform );

    const bool selected = ( option.state & QStyle::State_Selected ) == QStyle::State_Selected;
    if ( selected )
        painter->setOpacity( 1.0 );
    else
        painter->setOpacity( 0.7 );

    SourcesModel::RowType type = static_cast< SourcesModel::RowType >( index.data( SourcesModel::SourceTreeItemTypeRole ).toInt() );
    SourceTreeItem* item = index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >();
    Q_ASSERT( item );

    initStyleOption( &opt, index );
    opt.icon = QIcon();
    opt.text.clear();

    // shrink the indentations
    {
        int indentMult = 0;
        QModelIndex counter = index;
        while ( counter.parent().isValid() )
        {
            indentMult++;
            counter = counter.parent();
        }

        const int indentDelta = optIndentation.rect.x() - m_parent->viewport()->x();
        optIndentation.rect.setX( optIndentation.rect.x() - indentDelta + indentMult * TomahawkUtils::DpiScaler::scaledY( m_parent, TREEVIEW_INDENT_ADD ) );
        opt.rect.setX( 0 );
    }

    if ( type == SourcesModel::Source || type == SourcesModel::ScriptCollection )
    {
        paintSource( painter, optIndentation, index );
    }
    else if ( type == SourcesModel::Group )
    {
        paintGroup( painter, opt, index );
    }
    else if ( type == SourcesModel::Category )
    {
        paintCategory( painter, optIndentation, index );
    }
    else if ( type == SourcesModel::Divider )
    {
        const QRect middle = optIndentation.rect.adjusted( 0, m_margin / 16, 0, -m_margin / 16 );
        const QColor bgcolor = opt.palette.color( QPalette::Base );

        painter->setPen( bgcolor.darker( 120 ) );
        painter->drawLine( middle.topLeft(), middle.topRight() );
        painter->setPen( bgcolor.lighter( 120 ) );
        painter->drawLine( middle.bottomLeft(), middle.bottomRight() );
    }
    else
    {
        optIndentation.state &= ~QStyle::State_MouseOver;
        if ( !index.parent().parent().isValid() )
            optIndentation.rect.adjust( m_margin / 4, 0, 0, 0 );

        if ( type == SourcesModel::Inbox || type == SourcesModel::Queue || type == SourcesModel::Collection )
        {
            QString count;
            if ( type == SourcesModel::Inbox )
            {
                InboxItem* ii = qobject_cast< InboxItem* >( item );
                if ( ii && ii->unlistenedCount() )
                    count = QString::number( ii->unlistenedCount() );
            }
            else if ( type == SourcesModel::Queue )
            {
                QueueItem* qi = qobject_cast< QueueItem* >( item );
                if ( qi && qi->unlistenedCount() )
                    count = QString::number( qi->unlistenedCount() );
            }
            else if ( type == SourcesModel::Collection )
            {
                CollectionItem* ci = qobject_cast< CollectionItem* >( item );
                if ( ci )
                    count = QString::number( ci->trackCount() );
            }

            paintStandardItem( painter, optIndentation, index, count );
        }
        else if ( type == SourcesModel::TemporaryPage || type == SourcesModel::DeletablePage || type == SourcesModel::RemovablePage )
        {
            if ( opt.state & QStyle::State_MouseOver )
            {
                m_iconHeight = ( opt.rect.height() / 2 );
                paintStandardItem( painter, optIndentation, index );

                // draw close icon
                const QRect r( opt.rect.right() - m_margin / 8 - m_iconHeight, opt.rect.y() + ( opt.rect.height() - m_iconHeight ) / 2, m_iconHeight, m_iconHeight );
                painter->drawPixmap( r, TomahawkUtils::defaultPixmap( TomahawkUtils::ListRemove, TomahawkUtils::Original, r.size() ) );
            }
            else
                paintStandardItem( painter, optIndentation, index );
        }
        else if ( type == SourcesModel::StaticPlaylist )
        {
            paintStandardItem( painter, optIndentation, index );

            PlaylistItem* plItem = qobject_cast< PlaylistItem* >( item );
            if ( plItem->canSubscribe() && !plItem->subscribedIcon().isNull() )
            {
                const int imgWidth = optIndentation.rect.height() / 2;
                const QPixmap icon = plItem->subscribedIcon().scaled( imgWidth, imgWidth, Qt::KeepAspectRatio, Qt::SmoothTransformation );
                const QRect subRect( optIndentation.rect.right() - m_margin / 2 - imgWidth, optIndentation.rect.top() + ( optIndentation.rect.height() - imgWidth ) / 2, imgWidth, imgWidth );
                painter->drawPixmap( subRect, icon );
            }

            if ( plItem->collaborative() )
            {
                const int imgWidth = optIndentation.rect.height() / 2;
                const QRect subRect( optIndentation.rect.left(), optIndentation.rect.top(), imgWidth, imgWidth );

                painter->drawPixmap( subRect, TomahawkUtils::defaultPixmap( TomahawkUtils::GreenDot, TomahawkUtils::Original, subRect.size() ) );
            }
        }
        else
            paintStandardItem( painter, optIndentation, index );
    }

    paintDecorations( painter, opt, index );

    painter->restore();
}