File indexing completed on 2024-04-28 09:43:42
0001 /** 0002 * SPDX-FileCopyrightText: (C) 2003 Sébastien Laoût <slaout@linux62.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef NOTEDRAG_H 0008 #define NOTEDRAG_H 0009 0010 #include <QDrag> 0011 #include <QGraphicsSceneDragDropEvent> 0012 #include <QList> 0013 0014 class QDataStream; 0015 class QDragEnterEvent; 0016 class QPixmap; 0017 class QString; 0018 0019 class BasketScene; 0020 class Note; 0021 class NoteSelection; 0022 0023 /** Dragging/Copying/Cutting Scenario: 0024 * - User select some notes and cut them; 0025 * - NoteDrag::toMultipleDrag() is called with a tree of the selected notes (see BasketScene::toSelectionTree()): 0026 * - This method create a new QDrag object, create a stream, 0027 * - And then browse all notes and call the virtual Note::serialize() with the stream as parameter for them to serialize their content in the "native format". 0028 * - This give the MIME type "application/x-basket-note" that will be used by the application to paste the notes exactly as they were. 0029 * - Then the method try to set alternate formats for the dragged objects: 0030 * - It call successively toText() for each notes and stack up the result so there is ONE big text flavour to add to the QDrag object 0031 * - It do the same with toHtml(), toImage() and toLink() to have those flavors as well, if possible... 0032 * - If there is only ONE copied note, addAlternateDragObjects() is called on it, so that Unknown objects can be dragged "as is". 0033 * - It's OK for the flavors. The method finally set the drag feedback pixmap by asking every selected notes to draw the content to a small pixmap. 0034 * - The pixmaps are joined to one big pixmap (but it should not exceed a defined size) and a border is drawn on this image. 0035 * 0036 * Pasting/Dropping Scenario: 0037 * 0038 * @author Sébastien Laoût 0039 */ 0040 class NoteDrag 0041 { 0042 protected: 0043 static void serializeNotes(NoteSelection *noteList, QDataStream &stream, bool cutting); 0044 static void serializeText(NoteSelection *noteList, QMimeData* mimeData); 0045 static void serializeHtml(NoteSelection *noteList, QMimeData* mimeData); 0046 static void serializeImage(NoteSelection *noteList, QMimeData* mimeData); 0047 static void serializeLinks(NoteSelection *noteList, QMimeData* mimeData, bool cutting); 0048 static void setFeedbackPixmap(NoteSelection *noteList, QDrag *multipleDrag); 0049 static Note *decodeHierarchy(QDataStream &stream, BasketScene *parent, bool moveFiles, bool moveNotes, BasketScene *originalBasket); 0050 0051 public: 0052 static QPixmap feedbackPixmap(NoteSelection *noteList); 0053 static QDrag *dragObject(NoteSelection *noteList, bool cutting, QWidget *source = nullptr); 0054 static bool canDecode(const QMimeData *source); 0055 static Note *decode(const QMimeData *source, BasketScene *parent, bool moveFiles, bool moveNotes); 0056 static BasketScene *basketOf(const QMimeData *source); 0057 static QList<Note *> notesOf(QGraphicsSceneDragDropEvent *source); 0058 static void saveNoteSelectionToList(NoteSelection *selection); ///< Traverse @p selection and save all note pointers to @p selectedNotes 0059 static void createAndEmptyCuttingTmpFolder(); 0060 0061 static const char *NOTE_MIME_STRING; 0062 0063 static QList<Note *> selectedNotes; ///< The notes being selected and dragged 0064 }; 0065 0066 /** QTextDrag with capabilities to drop GNOME and Mozilla texts 0067 * as well as UTF-16 texts even if it was supposed to be encoded 0068 * with local encoding! 0069 * @author Sébastien Laoût 0070 */ 0071 class ExtendedTextDrag : public QDrag 0072 { 0073 Q_OBJECT 0074 public: 0075 static bool decode(const QMimeData *e, QString &str); 0076 static bool decode(const QMimeData *e, QString &str, QString &subtype); 0077 }; 0078 0079 #endif // NOTEDRAG_H