1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of Qt Designer. This header
10// file may change from version to version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QDESIGNER_DNDITEM_H
16#define QDESIGNER_DNDITEM_H
17
18#include "shared_global_p.h"
19#include <QtDesigner/abstractdnditem.h>
20
21#include <QtCore/qpoint.h>
22#include <QtCore/qlist.h>
23#include <QtCore/qmimedata.h>
24
25QT_BEGIN_NAMESPACE
26
27class QDrag;
28class QImage;
29class QDropEvent;
30
31namespace qdesigner_internal {
32
33class QDESIGNER_SHARED_EXPORT QDesignerDnDItem: public QDesignerDnDItemInterface
34{
35public:
36 explicit QDesignerDnDItem(DropType type, QWidget *source = nullptr);
37 ~QDesignerDnDItem() override;
38
39 DomUI *domUi() const override;
40 QWidget *decoration() const override;
41 QWidget *widget() const override;
42 QPoint hotSpot() const override;
43 QWidget *source() const override;
44
45 DropType type() const override;
46
47protected:
48 void setDomUi(DomUI *dom_ui);
49 void init(DomUI *ui, QWidget *widget, QWidget *decoration, const QPoint &global_mouse_pos);
50
51private:
52 QWidget *m_source;
53 const DropType m_type;
54 const QPoint m_globalStartPos;
55 DomUI *m_dom_ui;
56 QWidget *m_widget;
57 QWidget *m_decoration;
58 QPoint m_hot_spot;
59
60 Q_DISABLE_COPY_MOVE(QDesignerDnDItem)
61};
62
63// Mime data for use with designer drag and drop operations.
64
65class QDESIGNER_SHARED_EXPORT QDesignerMimeData : public QMimeData {
66 Q_OBJECT
67
68public:
69 using QDesignerDnDItems = QList<QDesignerDnDItemInterface *>;
70
71 ~QDesignerMimeData() override;
72
73 const QDesignerDnDItems &items() const { return m_items; }
74
75 // Execute a drag and drop operation.
76 static Qt::DropAction execDrag(const QDesignerDnDItems &items, QWidget * dragSource);
77
78 QPoint hotSpot() const { return m_hotSpot; }
79
80 // Move the decoration. Required for drops over form windows as the position
81 // is derived from the decoration position.
82 void moveDecoration(const QPoint &globalPos) const;
83
84 // For a move operation, create the undo command sequence to remove
85 // the widgets from the source form.
86 static void removeMovedWidgetsFromSourceForm(const QDesignerDnDItems &items);
87
88 // Accept an event with the proper action.
89 void acceptEvent(QDropEvent *e) const;
90
91 // Helper to accept an event with the desired action.
92 static void acceptEventWithAction(Qt::DropAction desiredAction, QDropEvent *e);
93
94private:
95 QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag);
96 Qt::DropAction proposedDropAction() const;
97
98 static void setImageTransparency(QImage &image, int alpha);
99
100 const QDesignerDnDItems m_items;
101 QPoint m_globalStartPos;
102 QPoint m_hotSpot;
103};
104
105} // namespace qdesigner_internal
106
107QT_END_NAMESPACE
108
109#endif // QDESIGNER_DNDITEM_H
110

source code of qttools/src/designer/src/lib/shared/qdesigner_dnditem_p.h