119void QQuickDropArea::setKeys(
const QStringList &keys)
122 if (d->keys != keys) {
125 if (keys.isEmpty()) {
126 d->keyRegExp = QRegularExpression();
128 QString pattern = QLatin1Char(
'(') + QRegularExpression::escape(keys.first());
129 for (
int i = 1; i < keys.size(); ++i)
130 pattern += QLatin1Char(
'|') + QRegularExpression::escape(keys.at(i));
131 pattern += QLatin1Char(
')');
132 d->keyRegExp = QRegularExpression(
133 QRegularExpression::anchoredPattern(pattern.replace(QLatin1String(
"\\*"),
134 QLatin1String(
".+"))));
183void QQuickDropArea::dragMoveEvent(QDragMoveEvent *event)
186 if (!d->containsDrag)
189 d->dragPosition = event->position().toPoint();
191 emit d->drag->positionChanged();
194 QQuickDragEvent dragTargetEvent(d, event);
195 emit positionChanged(&dragTargetEvent);
223void QQuickDropArea::dragEnterEvent(QDragEnterEvent *event)
226 const QMimeData *mimeData = event->mimeData();
227 if (!d->effectiveEnable || d->containsDrag || !mimeData || !d->hasMatchingKey(d->getKeys(mimeData)))
230 const QQuickDragMimeData *dragMime = qobject_cast<
const QQuickDragMimeData *>(mimeData);
231 auto dragSource = dragMime ? dragMime->source() : event->source();
235 if (QQuickItem *dragSourceItem = qobject_cast<QQuickItem *>(dragSource)) {
236 if (dragSourceItem->isAncestorOf(
this))
240 d->dragPosition = event->position().toPoint();
244 QQuickDragEvent dragTargetEvent(d, event);
245 emit entered(&dragTargetEvent);
246 if (!event->isAccepted())
249 d->containsDrag =
true;
250 d->source = dragSource;
251 d->dragPosition = event->position().toPoint();
253 emit d->drag->positionChanged();
254 emit d->drag->sourceChanged();
256 emit containsDragChanged();
287void QQuickDropArea::dropEvent(QDropEvent *event)
290 if (!d->containsDrag)
293 QQuickDragEvent dragTargetEvent(d, event);
294 emit dropped(&dragTargetEvent);
296 d->containsDrag =
false;
298 emit containsDragChanged();
300 emit d->drag->sourceChanged();