Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdesigner_dnditem.cpp
Go to the documentation of this file.
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
6#include <QtDesigner/private/ui4_p.h>
7
8#include <QtGui/qpainter.h>
9#include <QtGui/qbitmap.h>
10#include <QtGui/qpixmap.h>
11#include <QtGui/qimage.h>
12#include <QtWidgets/qlabel.h>
13#include <QtGui/qdrag.h>
14#include <QtGui/qcursor.h>
15#include <QtGui/qevent.h>
16#include <QtGui/qrgb.h>
17
18#include <QtCore/qmap.h>
19
21
22namespace qdesigner_internal {
23
26 m_type(type),
27 m_dom_ui(nullptr),
28 m_widget(nullptr),
29 m_decoration(nullptr)
30{
31}
32
45
47{
48 if (m_decoration != nullptr)
50 delete m_dom_ui;
51}
52
54{
55 return m_dom_ui;
56}
57
59{
60 return m_decoration;
61}
62
64{
65 return m_hot_spot;
66}
67
69{
70 return m_widget;
71}
72
77
79{
80 return m_source;
81}
82
84{
85 delete m_dom_ui;
87}
88
89// ---------- QDesignerMimeData
90
91// Make pixmap transparent on Windows only. Mac is transparent by default, Unix usually does not work.
92#ifdef Q_OS_WIN
93# define TRANSPARENT_DRAG_PIXMAP
94#endif
95
98{
99 enum { Alpha = 200 };
101 switch (m_items.size()) {
102 case 0:
103 break;
104 case 1: {
107 const QPixmap widgetPixmap = deco->grab(QRect(0, 0, -1, -1));
108#ifdef TRANSPARENT_DRAG_PIXMAP
114 painter.end();
117#else
119#endif
120 }
121 break;
122 default: {
123 // determine size of drag decoration by uniting all geometries
124 const auto cend = m_items.cend();
125 auto it = m_items.cbegin();
128 for (++it; it != cend; ++it )
130
131 // paint with offset. At the same time, create a mask bitmap, containing widget rectangles.
138 mask.clear();
139 // paint with offset, determine action
143 for (auto *item : std::as_const(m_items)) {
144 QWidget *w = item->decoration();
145 const QPixmap wp = w->grab(QRect(0, 0, -1, -1));
146 const QPoint pos = w->pos() - decorationTopLeft;
149 }
150 painter.end();
152#ifdef TRANSPARENT_DRAG_PIXMAP
154#endif
158 }
159 break;
160 }
161 // determine hot spot and reconstruct the exact starting position as form window
162 // introduces some offset when detecting DnD
166
167 drag->setMimeData(this);
168}
169
174
176{
178}
179
181{
182 if (items.isEmpty())
183 return Qt::IgnoreAction;
184
185 QDrag *drag = new QDrag(dragSource);
187
188 // Store pointers to widgets that are to be re-shown if a move operation is canceled
190 for (auto *item : items) {
191 if (QWidget *w = item->widget()) {
194 }
195 }
196
198
201 w->show();
202 }
203
204 return executedAction;
205}
206
207
209{
211 for (auto *item : m_items) {
212 QWidget *w = item->decoration();
213 w->move(w->pos() + relativeDistance);
214 }
215}
216
218{
220 // Find moved widgets per form
221 for (auto *item : items) {
223 if (QWidget *w = item->widget()) {
226 }
227 }
228 }
229
230 const auto &formWindows = formWidgetMap.uniqueKeys();
233}
234
244
249
251{
252 const int height = image.height();
253 for (int l = 0; l < height; l++) {
254 QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(l));
255 QRgb *lineEnd = line + image.width();
256 for ( ; line < lineEnd; line++) {
257 const QRgb rgba = *line;
259 }
260 }
261}
262
263} // namespace qdesigner_internal
264
265QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.