QDragObject *QtFileIconView::dragObject()
{
    if ( !currentItem() )
        return 0;

    QPoint orig = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );
    QtFileIconDrag *drag = new QtFileIconDrag( viewport() );
    drag->setPixmap( *currentItem()->pixmap(),
                     QPoint( currentItem()->pixmapRect().width() / 2, currentItem()->pixmapRect().height() / 2 ) );
    for ( QtFileIconViewItem *item = (QtFileIconViewItem*)firstItem(); item;
            item = (QtFileIconViewItem*)item->nextItem() ) {
        if ( item->isSelected() ) {
            QIconDragItem id;
            id.setData( QCString( item->filename() ) );
            drag->append( id,
                          QRect( item->pixmapRect( FALSE ).x() - orig.x(),
                                 item->pixmapRect( FALSE ).y() - orig.y(),
                                 item->pixmapRect().width(), item->pixmapRect().height() ),
                          QRect( item->textRect( FALSE ).x() - orig.x(),
                                 item->textRect( FALSE ).y() - orig.y(),
                                 item->textRect().width(), item->textRect().height() ),
                          QString( item->filename() ) );
        }
    }

    return drag;
}
Example #2
0
QDragObject *KivioIconView::dragObject()
{
  if( !currentItem() || !isReadWrite)
    return 0;

  QPoint orig = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );
  KivioSpawnerDrag *drag = new KivioSpawnerDrag( this, viewport() );

  const char*null_pix[]={
  "1 1 1 1",
  "# c None",
  "#"};
  drag->setPixmap(null_pix);

  KivioIconViewItem *item = (KivioIconViewItem *)currentItem();

  QIconDragItem id;
  QString full;
  full = item->spawner()->set()->dir() + "/" + item->spawner()->info()->title();
  id.setData( QCString(full.ascii()));

  drag->append( id,
      QRect( item->pixmapRect(FALSE).x() - orig.x(),
              item->pixmapRect(FALSE).y() - orig.y(),
              item->pixmapRect().width(),
              item->pixmapRect().height() ),
      QRect( item->textRect(FALSE).x() - orig.x(),
              item->textRect(FALSE).y() - orig.y(),
              item->textRect().width(),
              item->textRect().height() ),
      *(item->spawner()) );


  // Set the current dragged KivioStencilSpawner for use
  // when the drop occurs.  I don't actually encode the
  // data because it's a pain in the ass and I don't understand
  // how to do it.  So I store a pointer here and clear
  // it on the drop.
  m_pCurDrag = item->spawner();

  return drag;
}