Ejemplo n.º 1
0
QPixmap
createDragPixmap( int itemCount )
{
    // If more than one item is dragged, align the items inside a
    // rectangular grid. The maximum grid size is limited to 5 x 5 items.
    int xCount = 3;
    int size = 32;

    if ( itemCount > 16 )
    {
        xCount = 5;
        size = 16;
    } else if( itemCount > 9 )
    {
        xCount = 4;
        size = 22;
    }

    if( itemCount < xCount )
    {
        xCount = itemCount;
    }

    int yCount = itemCount / xCount;
    if( itemCount % xCount != 0 )
    {
        ++yCount;
    }
    if( yCount > xCount )
    {
        yCount = xCount;
    }
    // Draw the selected items into the grid cells
    QPixmap dragPixmap( xCount * size + xCount - 1, yCount * size + yCount - 1 );
    dragPixmap.fill( Qt::transparent );

    QPainter painter( &dragPixmap );
    painter.setRenderHint( QPainter::Antialiasing );
    int x = 0;
    int y = 0;
    for( int i = 0; i < itemCount; ++i )
    {
        const QPixmap pixmap = QPixmap( QString( ":/data/icons/audio-x-generic-%2x%2.png" ).arg( size ) );
        painter.drawPixmap( x, y, pixmap );

        x += size + 1;
        if ( x >= dragPixmap.width() )
        {
            x = 0;
            y += size + 1;
        }
        if ( y >= dragPixmap.height() )
        {
            break;
        }
    }

    return dragPixmap;
}
Ejemplo n.º 2
0
/* Proxy icon creation */
QPixmap darwinCreateDragPixmap(const QPixmap& aPixmap, const QString &aText)
{
    QFontMetrics fm(qApp->font());
    QRect tbRect = fm.boundingRect(aText);
    const int h = qMax(aPixmap.height(), fm.ascent() + 1);
    const int m = 2;
    QPixmap dragPixmap(aPixmap.width() + tbRect.width() + m, h);
    dragPixmap.fill(Qt::transparent);
    QPainter painter(&dragPixmap);
    painter.drawPixmap(0, qAbs(h - aPixmap.height()) / 2.0, aPixmap);
    painter.setPen(Qt::white);
    painter.drawText(QRect(aPixmap.width() + m, 1, tbRect.width(), h - 1), Qt::AlignLeft | Qt::AlignVCenter, aText);
    painter.setPen(Qt::black);
    painter.drawText(QRect(aPixmap.width() + m, 0, tbRect.width(), h - 1), Qt::AlignLeft | Qt::AlignVCenter, aText);
    painter.end();
    return dragPixmap;
}
Ejemplo n.º 3
0
        void startDrag(Qt::DropActions supportedDropActions)
        {
            QList<QListWidgetItem *> items = selectedItems();
            int count = items.size();
            if (count < 1 || !m_pictureService)
                return;

            // make the drag pixmap and the indices data
            QStringList indices;
            QPixmap dragPixmap(50 + 10 * (count - 1), 50 + 10 * (count - 1));
            dragPixmap.fill(Qt::transparent);
            QPainter dragPainter(&dragPixmap);
            int i = 0;
            foreach (QListWidgetItem * item, items) {
                int idx = row(item);
                m_pictureService->startPrefetch(idx);
                dragPainter.drawPixmap(i * 10, i * 10, item->icon().pixmap(50, 50));
                indices.append(QString::number(idx));
                i++;
            }
Ejemplo n.º 4
0
void DraggableLabel::mouseMoveEvent(QMouseEvent *event)
{
	if (!dragStartPosition.isNull())
	{
		if (!(event->buttons() & Qt::LeftButton))
			return;

		if ((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance())
			return;
		
		dragPixmap();

		dragStartPosition = QPoint();

		event->accept();
		return;
	}

	QLabel::mouseMoveEvent(event);
}
Ejemplo n.º 5
0
QPixmap KFileItemListView::createDragPixmap(const QSet<int>& indexes) const
{
    if (!model()) {
        return QPixmap();
    }

    const int itemCount = indexes.count();
    Q_ASSERT(itemCount > 0);
    if (itemCount == 1) {
        return KItemListView::createDragPixmap(indexes);
    }

    // If more than one item is dragged, align the items inside a
    // rectangular grid. The maximum grid size is limited to 5 x 5 items.
    int xCount;
    int size;
    if (itemCount > 16) {
        xCount = 5;
        size = KIconLoader::SizeSmall;
    } else if (itemCount > 9) {
        xCount = 4;
        size = KIconLoader::SizeSmallMedium;
    } else {
        xCount = 3;
        size = KIconLoader::SizeMedium;
    }

    if (itemCount < xCount) {
        xCount = itemCount;
    }

    int yCount = itemCount / xCount;
    if (itemCount % xCount != 0) {
        ++yCount;
    }
    if (yCount > xCount) {
        yCount = xCount;
    }

    // Draw the selected items into the grid cells.
    QPixmap dragPixmap(xCount * size + xCount, yCount * size + yCount);
    dragPixmap.fill(Qt::transparent);

    QPainter painter(&dragPixmap);
    int x = 0;
    int y = 0;
    QSetIterator<int> it(indexes);
    while (it.hasNext()) {
        const int index = it.next();

        QPixmap pixmap = model()->data(index).value("iconPixmap").value<QPixmap>();
        if (pixmap.isNull()) {
            KIcon icon(model()->data(index).value("iconName").toString());
            pixmap = icon.pixmap(size, size);
        } else {
            KPixmapModifier::scale(pixmap, QSize(size, size));
        }

        painter.drawPixmap(x, y, pixmap);

        x += size + 1;
        if (x >= dragPixmap.width()) {
            x = 0;
            y += size + 1;
        }

        if (y >= dragPixmap.height()) {
            break;
        }
    }

    return dragPixmap;
}
Ejemplo n.º 6
0
QPixmap
createDragPixmap( MediaType type, int itemCount )
{
    // If more than one item is dragged, align the items inside a
    // rectangular grid. The maximum grid size is limited to 5 x 5 items.
    int xCount = 3;
    int size = 32;

    if ( itemCount > 16 )
    {
        xCount = 5;
        size = 16;
    }
    else if( itemCount > 9 )
    {
        xCount = 4;
        size = 22;
    }

    if ( itemCount < xCount )
    {
        xCount = itemCount;
    }

    int yCount = itemCount / xCount;
    if ( itemCount % xCount != 0 )
    {
        ++yCount;
    }
    if ( yCount > xCount )
    {
        yCount = xCount;
    }
    // Draw the selected items into the grid cells
    QPixmap dragPixmap( xCount * size + xCount - 1, yCount * size + yCount - 1 );
    dragPixmap.fill( Qt::transparent );

    QPainter painter( &dragPixmap );
    painter.setRenderHint( QPainter::Antialiasing );

    QPixmap pixmap;
    switch ( type )
    {
        case MediaTypeArtist:
            pixmap = QPixmap( ":/data/images/artist-icon.png" ).scaledToWidth( size, Qt::SmoothTransformation );
            break;
        case MediaTypeAlbum:
            pixmap = QPixmap( ":/data/images/album-icon.png" ).scaledToWidth( size, Qt::SmoothTransformation );
            break;
        case MediaTypeTrack:
            pixmap = QPixmap( QString( ":/data/images/track-icon-%2x%2.png" ).arg( size ) );
            break;
    }

    int x = 0;
    int y = 0;
    for ( int i = 0; i < itemCount; ++i )
    {

        painter.drawPixmap( x, y, pixmap );

        x += size + 1;
        if ( x >= dragPixmap.width() )
        {
            x = 0;
            y += size + 1;
        }
        if ( y >= dragPixmap.height() )
        {
            break;
        }
    }

    return dragPixmap;
}
Ejemplo n.º 7
0
 void MacroTreeView::startDrag(Qt::DropActions supportedActions)
 {
   QModelIndexList indexes = selectionModel()->selectedRows();
   for(int i = indexes.count() - 1 ; i >= 0; --i)
   {
     if (!(indexes.at(i).isValid()) || !(model()->flags(indexes.at(i)) & Qt::ItemIsDragEnabled))
     {
       indexes.removeAt(i);
     }
   }
   if (indexes.count() > 0)
   {
     QMimeData *data = model()->mimeData(indexes);
     if (!data)
     {
       return;
     }
     QPixmap dragPixmap(":/icons/resources/macro.png");
     QModelIndex srcIndex = dynamic_cast<QSortFilterProxyModel*>(model())->mapToSource(indexes[0]);
     const ModelItemMacro* item = static_cast<const ModelItemMacro*>(srcIndex.internalPointer());
     graph::Vertex::Ptr dummyVertex = app::MacroManager::instance().createVertexInstance(item->macro().signature());
     if (!dummyVertex.isNull())
     {
       graph::VertexItem::Ptr vertexItem = dummyVertex->sceneItem().staticCast<graph::VertexItem>();
       if (!vertexItem.isNull())
       {
         dragPixmap = vertexItem->paintToPixmap();
       }
       app::MacroManager::instance().deleteVertexInstance(dummyVertex);
     }
     data->setImageData(dragPixmap.toImage());
     QDrag* dragObjectPtr = new QDrag(this);
     dragObjectPtr->setPixmap(dragPixmap);
     dragObjectPtr->setMimeData(data);
     dragObjectPtr->setHotSpot(dragPixmap.rect().center());
     Qt::DropAction defDropAction = Qt::IgnoreAction;
     if (defaultDropAction() != Qt::IgnoreAction && (supportedActions & defaultDropAction()))
     {
       defDropAction = defaultDropAction();
     }
     else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)
     {
       defDropAction = Qt::CopyAction;
     }
     if (dragObjectPtr->exec(supportedActions, defDropAction) == Qt::MoveAction)
     {
       // clear or remove dragged items
       const QItemSelection selection = selectionModel()->selection();
       QList<QItemSelectionRange>::const_iterator it = selection.constBegin();
       if (!dragDropOverwriteMode())
       {
         for (; it != selection.constEnd(); ++it)
         {
           QModelIndex parent = (*it).parent();
           if ((*it).left() != 0)
             continue;
           if ((*it).right() != (model()->columnCount(parent) - 1))
             continue;
           int count = (*it).bottom() - (*it).top() + 1;
           model()->removeRows((*it).top(), count, parent);
         }
       }
       else
       {
         QModelIndexList list = selection.indexes();
         for (int i=0; i < list.size(); ++i)
         {
           QModelIndex index = list.at(i);
           QMap<int, QVariant> roles = model()->itemData(index);
           for (QMap<int, QVariant>::Iterator it = roles.begin(); it != roles.end(); ++it)
           {
             it.value() = QVariant();
           }
           model()->setItemData(index, roles);
         }
       }
     }
   }
 }
Ejemplo n.º 8
0
QPixmap
createDragPixmap( MediaType type, int itemCount )
{
    // If more than one item is dragged, align the items inside a
    // rectangular grid. The maximum grid size is limited to 5 x 5 items.
    int xCount = 3;
    int size = 32;

    if ( itemCount > 16 )
    {
        xCount = 5;
        size = 16;
    }
    else if( itemCount > 9 )
    {
        xCount = 4;
        size = 22;
    }

    if ( itemCount < xCount )
    {
        xCount = itemCount;
    }

    int yCount = itemCount / xCount;
    if ( itemCount % xCount != 0 )
    {
        ++yCount;
    }
    if ( yCount > xCount )
    {
        yCount = xCount;
    }
    // Draw the selected items into the grid cells
    QPixmap dragPixmap( xCount * size + xCount - 1, yCount * size + yCount - 1 );
    dragPixmap.fill( Qt::transparent );

    QPainter painter( &dragPixmap );
    painter.setRenderHint( QPainter::Antialiasing );

    QPixmap pixmap;
    switch ( type )
    {
        case MediaTypeArtist:
            pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::Original, QSize( size, size ) );
            break;
        case MediaTypeAlbum:
            pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::Original, QSize( size, size ) );
            break;
        case MediaTypeTrack:
            pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::Original, QSize( size, size ) );
            break;
    }

    int x = 0;
    int y = 0;
    for ( int i = 0; i < itemCount; ++i )
    {

        painter.drawPixmap( x, y, pixmap );

        x += size + 1;
        if ( x >= dragPixmap.width() )
        {
            x = 0;
            y += size + 1;
        }
        if ( y >= dragPixmap.height() )
        {
            break;
        }
    }

    return dragPixmap;
}
Ejemplo n.º 9
0
QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const
{
    if (!model()) {
        return QPixmap();
    }

    const int itemCount = indexes.count();
    Q_ASSERT(itemCount > 0);
    if (itemCount == 1) {
        return KItemListView::createDragPixmap(indexes);
    }

    // If more than one item is dragged, align the items inside a
    // rectangular grid. The maximum grid size is limited to 5 x 5 items.
    int xCount;
    int size;
    if (itemCount > 16) {
        xCount = 5;
        size = KIconLoader::SizeSmall;
    } else if (itemCount > 9) {
        xCount = 4;
        size = KIconLoader::SizeSmallMedium;
    } else {
        xCount = 3;
        size = KIconLoader::SizeMedium;
    }

    if (itemCount < xCount) {
        xCount = itemCount;
    }

    int yCount = itemCount / xCount;
    if (itemCount % xCount != 0) {
        ++yCount;
    }
    if (yCount > xCount) {
        yCount = xCount;
    }

    const qreal dpr = scene()->views()[0]->devicePixelRatio();
    // Draw the selected items into the grid cells.
    QPixmap dragPixmap(QSize(xCount * size + xCount, yCount * size + yCount) * dpr);
    dragPixmap.setDevicePixelRatio(dpr);
    dragPixmap.fill(Qt::transparent);

    QPainter painter(&dragPixmap);
    int x = 0;
    int y = 0;

    foreach (int index, indexes) {
        QPixmap pixmap = model()->data(index).value("iconPixmap").value<QPixmap>();
        if (pixmap.isNull()) {
            QIcon icon = QIcon::fromTheme(model()->data(index).value("iconName").toString());
            pixmap = icon.pixmap(size, size);
        } else {
            KPixmapModifier::scale(pixmap, QSize(size, size) * dpr);
        }

        painter.drawPixmap(x, y, pixmap);

        x += size + 1;
        if (x >= dragPixmap.width()) {
            x = 0;
            y += size + 1;
        }

        if (y >= dragPixmap.height()) {
            break;
        }
    }