9#include <QtGui/private/qcoregraphics_p.h>
10#include <QtGui/qutimimeconverter.h>
11#include <QtCore/qsysinfo.h>
12#include <QtCore/private/qcore_mac_p.h>
37 m_lastEvent = [
event copy];
73 qDebug(
"possible actions : %s", dragActionsToString(possibleActions).latin1());
77 if (!(possibleActions & default_action)) {
89 qDebug(
"default action : %s", dragActionsToString(default_action).latin1());
92 return default_action;
105 if (maybeDragMultipleItems())
106 return m_executed_drop_action;
109 QPixmap pm = dragPixmap(m_drag, hotSpot);
110 NSImage *dragImage = [NSImage imageFromQImage:pm.
toImage()];
113 NSPoint event_location = [m_lastEvent locationInWindow];
114 NSWindow *theWindow = [m_lastEvent
window];
116 event_location.x -= hotSpot.
x();
117 CGFloat flippedY = dragImage.size.height - hotSpot.
y();
118 event_location.y -= flippedY;
119 NSSize mouseOffset_unused = NSMakeSize(0.0, 0.0);
120 NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSPasteboardNameDrag];
122 [theWindow dragImage:dragImage
131 return m_executed_drop_action;
134bool QCocoaDrag::maybeDragMultipleItems()
146 NSView *
view = m_lastView ? m_lastView : m_lastEvent.window.contentView;
147 if (![
view respondsToSelector:@
selector(draggingSession:sourceOperationMaskForDraggingContext:)])
150 auto *sourceView =
static_cast<NSView<NSDraggingSource>*
>(
view);
153 NSPasteboard *dragBoard = [NSPasteboard pasteboardWithName:NSPasteboardNameDrag];
155 if (qtUrls.size() <= 1) {
160 std::vector<NSPasteboardItem *> nonUrls;
161 for (NSPasteboardItem *
item in dragBoard.pasteboardItems) {
164 using NSStringRef = NSString *;
165 if ([
type isEqualToString:NSStringRef(kUTTypeFileURL)]) {
176 const auto pixmap = dragPixmap(m_drag, hotSpot);
177 NSImage *dragImage = [NSImage imageFromQImage:
pixmap.toImage()];
180 NSMutableArray<NSDraggingItem *> *dragItems = [[[NSMutableArray alloc]
init] autorelease];
181 const NSPoint itemLocation = m_drag->
hotSpot().toCGPoint();
187 auto imageOrNil = dragImage;
188 for (
const auto &qtUrl : qtUrls) {
189 if (!qtUrl.isValid())
192 if (qtUrl.isRelative())
195 NSURL *nsUrl = qtUrl.toNSURL();
196 auto *newItem = [[[NSDraggingItem alloc] initWithPasteboardWriter:nsUrl] autorelease];
197 const NSRect itemFrame = NSMakeRect(itemLocation.x, itemLocation.y,
198 dragImage.size.width,
199 dragImage.size.height);
201 [newItem setDraggingFrame:itemFrame
contents:imageOrNil];
203 [dragItems addObject:newItem];
206 for (
auto *pbItem : nonUrls) {
207 auto *newItem = [[[NSDraggingItem alloc] initWithPasteboardWriter:pbItem] autorelease];
208 const NSRect itemFrame = NSMakeRect(itemLocation.x, itemLocation.y,
209 dragImage.size.width,
210 dragImage.size.height);
211 [newItem setDraggingFrame:itemFrame
contents:imageOrNil];
212 [dragItems addObject:newItem];
215 [sourceView beginDraggingSessionWithItems:dragItems
event:m_lastEvent
source:sourceView];
224 m_executed_drop_action = act;
229 if (m_internalDragLoop) {
231 m_internalDragLoop->
exit();
246 if (
data->hasImage()) {
258 const int width = fm.horizontalAdvance(
s);
259 const int height = fm.height();
263 if (!
window &&
drag->source()->metaObject()->indexOfMethod(
"_q_closestWindowHandle()") != -1) {
279 p.drawText(0, fm.ascent(),
s);
295 dropPasteboard =
reinterpret_cast<CFStringRef
>(
const_cast<const NSString *
>([pasteboard
name]));
309 qDebug(
"DnD: Cannot get PasteBoard!");
321 qDebug(
"DnD: Cannot get PasteBoard!");
334 qDebug(
"DnD: Cannot get PasteBoard!");
void setLastMouseEvent(NSEvent *event, NSView *view)
Qt::DropAction defaultAction(Qt::DropActions possibleActions, Qt::KeyboardModifiers modifiers) const override
Qt::DropAction drag(QDrag *m_drag) override
void setAcceptedAction(Qt::DropAction act)
QMimeData * dragMimeData()
QVariant retrieveData_sys(const QString &mimeType, QMetaType type) const
QStringList formats_sys() const
QCocoaDropData(NSPasteboard *pasteboard)
bool hasFormat_sys(const QString &mimeType) const
CFStringRef dropPasteboard
QMimeData * mimeData() const
Returns the MIME data that is encapsulated by the drag object.
Qt::DropAction defaultAction() const
Returns the default proposed drop action for this drag operation.
QPoint hotSpot() const
Returns the position of the hot spot relative to the top-left corner of the cursor.
Qt::DropActions supportedActions() const
Returns the set of possible drop actions for this drag operation.
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
void exit(int returnCode=0)
Tells the event loop to exit with a return code.
bool isRunning() const
Returns true if the event loop is running; otherwise returns false.
\reentrant \inmodule QtGui
QStringList formats() const override
Returns a list of formats supported by the object.
void push_back(parameter_type t)
QStringList formats() const
void setMimeData(QMimeData *mime, DataRequestType dataRequestType=EagerRequest)
QVariant retrieveData(const QString &format) const
bool hasFormat(const QString &format) const
void setData(const QString &mimetype, const QByteArray &data)
Sets the data associated with the MIME type given by mimeType to the specified data.
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
static constexpr QOperatingSystemVersionBase MacOSMojave
\variable QOperatingSystemVersion::MacOSMojave
static QOperatingSystemVersion current()
[0]
The QPainter class performs low-level painting on widgets and other paint devices.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
int height() const
Returns the height of the pixmap.
QImage toImage() const
Converts the pixmap to a QImage.
QPixmap scaledToWidth(int w, Qt::TransformationMode mode=Qt::FastTransformation) const
Returns a scaled copy of the image.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
int width() const
Returns the width of the pixmap.
void setDevicePixelRatio(qreal scaleFactor)
Sets the device pixel ratio for the pixmap.
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
\inmodule QtCore\reentrant
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString first(qsizetype n) const
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
EGLImageKHR int int EGLuint64KHR * modifiers
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
static const int dragImageMaxChars
#define Q_RETURN_ARG(Type, data)
GLint GLsizei GLsizei height
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLsizei GLsizei GLchar * source
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
QWindow * qobject_cast< QWindow * >(QObject *o)
QFileSelector selector
[1]