1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29//
30// W A R N I N G
31// -------------
32//
33// This file is not part of the Qt API. It exists for the convenience
34// of Qt Designer. This header
35// file may change from version to version without notice, or even be removed.
36//
37// We mean it.
38//
39
40#ifndef QDESIGNER_DNDITEM_H
41#define QDESIGNER_DNDITEM_H
42
43#include "shared_global_p.h"
44#include <QtDesigner/abstractdnditem.h>
45
46#include <QtCore/qpoint.h>
47#include <QtCore/qlist.h>
48#include <QtCore/qmimedata.h>
49
50QT_BEGIN_NAMESPACE
51
52class QDrag;
53class QImage;
54class QDropEvent;
55
56namespace qdesigner_internal {
57
58class QDESIGNER_SHARED_EXPORT QDesignerDnDItem: public QDesignerDnDItemInterface
59{
60public:
61 explicit QDesignerDnDItem(DropType type, QWidget *source = nullptr);
62 ~QDesignerDnDItem() override;
63
64 DomUI *domUi() const override;
65 QWidget *decoration() const override;
66 QWidget *widget() const override;
67 QPoint hotSpot() const override;
68 QWidget *source() const override;
69
70 DropType type() const override;
71
72protected:
73 void setDomUi(DomUI *dom_ui);
74 void init(DomUI *ui, QWidget *widget, QWidget *decoration, const QPoint &global_mouse_pos);
75
76private:
77 QWidget *m_source;
78 const DropType m_type;
79 const QPoint m_globalStartPos;
80 DomUI *m_dom_ui;
81 QWidget *m_widget;
82 QWidget *m_decoration;
83 QPoint m_hot_spot;
84
85 Q_DISABLE_COPY_MOVE(QDesignerDnDItem)
86};
87
88// Mime data for use with designer drag and drop operations.
89
90class QDESIGNER_SHARED_EXPORT QDesignerMimeData : public QMimeData {
91 Q_OBJECT
92
93public:
94 using QDesignerDnDItems = QList<QDesignerDnDItemInterface *>;
95
96 ~QDesignerMimeData() override;
97
98 const QDesignerDnDItems &items() const { return m_items; }
99
100 // Execute a drag and drop operation.
101 static Qt::DropAction execDrag(const QDesignerDnDItems &items, QWidget * dragSource);
102
103 QPoint hotSpot() const { return m_hotSpot; }
104
105 // Move the decoration. Required for drops over form windows as the position
106 // is derived from the decoration position.
107 void moveDecoration(const QPoint &globalPos) const;
108
109 // For a move operation, create the undo command sequence to remove
110 // the widgets from the source form.
111 static void removeMovedWidgetsFromSourceForm(const QDesignerDnDItems &items);
112
113 // Accept an event with the proper action.
114 void acceptEvent(QDropEvent *e) const;
115
116 // Helper to accept an event with the desired action.
117 static void acceptEventWithAction(Qt::DropAction desiredAction, QDropEvent *e);
118
119private:
120 QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag);
121 Qt::DropAction proposedDropAction() const;
122
123 static void setImageTransparency(QImage &image, int alpha);
124
125 const QDesignerDnDItems m_items;
126 QPoint m_globalStartPos;
127 QPoint m_hotSpot;
128};
129
130} // namespace qdesigner_internal
131
132QT_END_NAMESPACE
133
134#endif // QDESIGNER_DNDITEM_H
135