Ejemplo n.º 1
0
Q3DragObject* NoteDrag::dragObject(NoteSelection *noteList, bool cutting, QWidget *source)
{
	if (noteList->count() <= 0)
		return 0;

	// The MimeSource:
	K3MultipleDrag *multipleDrag = new K3MultipleDrag(source);

	// Make sure the temporary folder exists and is empty (we delete previously moved file(s) (if exists)
	// since we override the content of the clipboard and previous file willn't be accessable anymore):
	createAndEmptyCuttingTmpFolder();

	// The "Native Format" Serialization:
	QBuffer buffer;
	if (buffer.open(QIODevice::WriteOnly)) {
		QDataStream stream(&buffer);
		// First append a pointer to the basket:
		stream << (quint64)(noteList->firstStacked()->note->basket());
		// Then a list of pointers to all notes, and parent groups:
		for (NoteSelection *node = noteList->firstStacked(); node; node = node->nextStacked())
			stream << (quint64)(node->note);
		Q3ValueList<Note*> groups = noteList->parentGroups();
		for (Q3ValueList<Note*>::iterator it = groups.begin(); it != groups.end(); ++it)
			stream << (quint64)(*it);
		stream << (quint64)0;
		// And finally the notes themselves:
		serializeNotes(noteList, stream, cutting);
		// Append the object:
		buffer.close();
		Q3StoredDrag *dragObject = new Q3StoredDrag(NOTE_MIME_STRING, source);
		dragObject->setEncodedData(buffer.buffer());
		multipleDrag->addDragObject(dragObject);
	}

	// The "Other Flavours" Serialization:
	serializeText(  noteList, multipleDrag          );
	serializeHtml(  noteList, multipleDrag          );
	serializeImage( noteList, multipleDrag          );
	serializeLinks( noteList, multipleDrag, cutting );

	// The Alternate Flavours:
	if (noteList->count() == 1)
		noteList->firstStacked()->note->content()->addAlternateDragObjects(multipleDrag);

	// If it is a drag, and not a copy/cut, add the feedback pixmap:
	if (source)
		setFeedbackPixmap(noteList, multipleDrag);

	return multipleDrag;
}
Ejemplo n.º 2
0
Q3DragObject *TreeView::dragObject()
{
    m_dragPath.clear();
    TreeItem *item = (TreeItem*)selectedItem();
    if(item == 0) return 0;

    K3MultipleDrag *drag = new K3MultipleDrag( this );

    if (item->isDirectory())
    {
       m_drag = MOVE_FOLDER;
       m_dragInfo = item->folderInfo();
       m_dragItem = item;
    }
    else if (item->isEntry())
    {
       m_drag = MOVE_FILE;
       m_dragInfo = 0;
       m_dragItem = item;
       QString menuId = item->menuId();
       m_dragPath = item->entryInfo()->service->entryPath();
       if (!m_dragPath.isEmpty())
          m_dragPath = KStandardDirs::locate("apps", m_dragPath);
       if (!m_dragPath.isEmpty())
       {
          KUrl url;
          url.setPath(m_dragPath);
          drag->addDragObject( new K3URLDrag(url, 0));
       }
    }
    else
    {
       m_drag = COPY_SEPARATOR;
       m_dragInfo = 0;
       m_dragItem = item;
    }

    drag->addDragObject( new Q3StoredDrag("application/x-kmenuedit-internal", 0));
    if ( item->pixmap(0) )
        drag->setPixmap(*item->pixmap(0));
    return drag;
}