/*** PROTECTED SLOTS ***/
void TemplateViewer::dragEnterEvent(QDragEnterEvent *event)
{
ImageViewer::dragEnterEvent(event);
event->accept();
if (event->mimeData()->hasUrls() || event->mimeData()->hasImage())
event->acceptProposedAction();
}
void TemplateViewer::dropEvent(QDropEvent *event)
{
ImageViewer::dropEvent(event);
event->accept();
event->acceptProposedAction();
const QMimeData *mimeData = event->mimeData();
if (mimeData->hasImage()) {
QImage input = qvariant_cast<QImage>(mimeData->imageData());
emit newInput(input);
} else if (event->mimeData()->hasUrls()) {
File input;
foreach (const QUrl &url, mimeData->urls()) {
if (!url.isValid()) continue;
if (url.toString().startsWith("http://images.google.com/search")) continue; // Not a true image URL
const QString localFile = url.toLocalFile();
if (localFile.isNull()) input.append(url.toString());
else input.append(localFile);
}
if (input.isNull()) return;
emit newInput(input);
}
}
void TemplateViewer::leaveEvent(QEvent *event)
{
ImageViewer::leaveEvent(event);
event->accept();
clearFocus();
nearestLandmark = -1;
mousePoint = QPointF();
emit newMousePoint(mousePoint);
unsetCursor();
update();
}
关键点就是MimeData的数据拦截了!!!