void LXQtTaskButton::mouseMoveEvent(QMouseEvent* event)
{
    if (!(event->buttons() & Qt::LeftButton))
        return;

    if ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance())
        return;

    QDrag *drag = new QDrag(this);
    drag->setMimeData(mimeData());
    QIcon ico = icon();
    QPixmap img = ico.pixmap(ico.actualSize({32, 32}));
    drag->setPixmap(img);
    switch (parentTaskBar()->panel()->position())
    {
        case ILXQtPanel::PositionLeft:
        case ILXQtPanel::PositionTop:
            drag->setHotSpot({0, 0});
            break;
        case ILXQtPanel::PositionRight:
        case ILXQtPanel::PositionBottom:
            drag->setHotSpot(img.rect().bottomRight());
            break;
    }

    sDraggging = true;
    drag->exec();

    // if button is dropped out of panel (e.g. on desktop)
    // it is not deleted automatically by Qt
    drag->deleteLater();
    sDraggging = false;

    QAbstractButton::mouseMoveEvent(event);
}
void LocalVideoWidget::PerformDrag() {
  // TODO: 暂时将media_id作为uri
  MimeTextBuilder text_builder(media_id_);
  text_builder.AddVirtualURI(media_id_);
  QMimeData *mime_data = new QMimeData();
  mime_data->setText(text_builder.GetText());
  QDrag *drag = new QDrag(this);
  drag->setMimeData(mime_data);

  QPixmap p(image_url_);
  drag->setPixmap(p);
  drag->setHotSpot(QPoint(p.size().width() / 2, p.size().height() / 2));

  // 在windows上exec会阻塞event loop
  drag->exec();

  // 在windows上需要删除drag
  drag->deleteLater();
}
void VirtualTerminalWidget::PerformDrag() {
  MimeTextBuilder text_builder(uri_);
  text_builder.AddVirtualURI(virtual_uri_);

  QMimeData *mime_data = new QMimeData();
  mime_data->setText(text_builder.GetText());

  QDrag *drag = new QDrag(this);
  drag->setMimeData(mime_data);

  QPixmap p(image_url_);
  drag->setPixmap(p);
  drag->setHotSpot(QPoint(p.size().width() / 2, p.size().height() / 2));

  // 在windows上event loop会被阻塞
  drag->exec();

  // 在windwos需要删除drag
  drag->deleteLater();
}
Example #4
0
Qt::DropAction QQuickDragAttachedPrivate::startDrag(Qt::DropActions supportedActions)
{
    Q_Q(QQuickDragAttached);

    QDrag *drag = new QDrag(q);
    QMimeData *mimeData = new QMimeData();

    Q_FOREACH (const QString &key, externalMimeData.keys()) {
        mimeData->setData(key, externalMimeData[key].toString().toUtf8());
    }

    drag->setMimeData(mimeData);

    // TODO: how to handle drag image?
    // drag->setPixmap(iconPixmap);

    emit q->dragStarted();

    Qt::DropAction dropAction = drag->exec(supportedActions);

    if (!QGuiApplicationPrivate::platformIntegration()->drag()->ownsDragObject())
        drag->deleteLater();

    deliverLeaveEvent();

    if (target) {
        target = 0;
        emit q->targetChanged();
    }

    emit q->dragFinished(dropAction);

    active = false;
    emit q->activeChanged();

    return dropAction;
}