Documentation DragAndDrop

From BibleTime
Revision as of 10:21, 30 November 2007 by Mgruner (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Old system

Old system used a complicated class which created and parsed XML.

New system

New system uses QDrag and especially QMimeData classes. Drag works almost like before but dropping and data store are a bit different.

BTMimeData inherits QMimeData. QMimeData is the data store. Plain text is stored and retrieved with QMimeData members. Actually any MIME type and data (QByteArray) can be used with the standard interface. There can also be more than one type simultaneously (maybe we could use this to store data in different formats for e.g. different word processors - I'm not sure but I suppose Qt supports universal DnD with QMimeData standard interface).

Drop event object has mimeData() function. To see if the data includes some MIME type hasFormat("mime/type") function is used. With the old system canDecode() and our own types were used.

Our BTMimeData includes a list of bookmarks. Bookmarks are BookmarkItems. The list is created with BTMimeData constructor or and/or it can be appended to. If there is at least one bookmark, "BibleTime/Bookmark" MIME type is set. Note that the MIME type is different from the old system. This is on purpose: there is no reason why there couldn't be many data types simultaneously so that user could drag the verse link into BibleTime window to see the verse or into a word processor to copy the verse contents.

BTMimeData::bookmark() gives the first bookmark item, bookmarks() gives the whole list. The list is used quite much the same way as in the old system, but it is created only through BTMimeData convenience functions, not separately as with the old system.

If bookmarks are to be handled after dropping, the QMimeData must be first cast into BTMimeData as described in QMimeData documentation.

There are examples in cplainwritedisplay.cpp (dragEnterEvent, dragMoveEvent, dropEvent) and chtmlreaddisplay.cpp (those same and khtmlMouseMoveEvent). I have left in some old code for documentation purposes. The new DnD system is in cdragrop.h/cpp.

Links: