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); }
//! [5] void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)) .length() < QApplication::startDragDistance()) { return; } QDrag *drag = new QDrag(event->widget()); QMimeData *mime = new QMimeData; drag->setMimeData(mime); //! [5] //! [6] static int n = 0; if (n++ > 2 && (qrand() % 3) == 0) { QImage image(":/images/head.png"); mime->setImageData(image); drag->setPixmap(QPixmap::fromImage(image).scaled(30, 40)); drag->setHotSpot(QPoint(15, 30)); //! [6] //! [7] } else { mime->setColorData(color); mime->setText(QString("#%1%2%3") .arg(color.red(), 2, 16, QLatin1Char('0')) .arg(color.green(), 2, 16, QLatin1Char('0')) .arg(color.blue(), 2, 16, QLatin1Char('0'))); QPixmap pixmap(34, 34); pixmap.fill(Qt::white); QPainter painter(&pixmap); painter.translate(15, 15); painter.setRenderHint(QPainter::Antialiasing); paint(&painter, 0, 0); painter.end(); pixmap.setMask(pixmap.createHeuristicMask()); drag->setPixmap(pixmap); drag->setHotSpot(QPoint(15, 20)); } //! [7] //! [8] drag->exec(); setCursor(Qt::OpenHandCursor); }
void Scene::startDrag(QPointF start) { QGraphicsPixmapItem *item = dynamic_cast<QGraphicsPixmapItem *> (itemAt(start, QTransform())); QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); stream << item->pixmap(); // Сохраняем картинку в буфер QDrag *drag = new QDrag(this); QMimeData *data = new QMimeData(); data->setData("Picture", buffer); drag->setMimeData(data); drag->setPixmap(item->pixmap()); relativePoint = item->mapFromScene(start); qDebug() << "Position at image:" << relativePoint; drag->setHotSpot(QPoint(relativePoint.x(), relativePoint.y())); removeItem(item); // удалить картинку internalMoving = true; update(); drag->exec(Qt::MoveAction); // Начать выполнение Drag & Drop }
void ResourceListWidget::startDrag(Qt::DropActions supportedActions) { if (supportedActions == Qt::MoveAction) return; QListWidgetItem *item = currentItem(); if (!item) return; const QString filePath = item->data(Qt::UserRole).toString(); const QIcon icon = item->icon(); QMimeData *mimeData = new QMimeData; const QtResourceView::ResourceType type = icon.isNull() ? QtResourceView::ResourceOther : QtResourceView::ResourceImage; mimeData->setText(QtResourceView::encodeMimeData(type , filePath)); QDrag *drag = new QDrag(this); if (!icon.isNull()) { const QSize size = icon.actualSize(iconSize()); drag->setPixmap(icon.pixmap(size)); drag->setHotSpot(QPoint(size.width() / 2, size.height() / 2)); } drag->setMimeData(mimeData); drag->exec(Qt::CopyAction); }
// this is reimplemented from QAbstractItemView::startDrag() void ScreenSetupView::startDrag(Qt::DropActions) { QModelIndexList indexes = selectedIndexes(); if (indexes.count() != 1) return; QMimeData* pData = model()->mimeData(indexes); if (pData == NULL) return; QPixmap pixmap = *model()->screen(indexes[0]).pixmap(); QDrag* pDrag = new QDrag(this); pDrag->setPixmap(pixmap); pDrag->setMimeData(pData); pDrag->setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2)); if (pDrag->exec(Qt::MoveAction, Qt::MoveAction) == Qt::MoveAction) { selectionModel()->clear(); // make sure to only delete the drag source if screens weren't swapped // see ScreenSetupModel::dropMimeData if (!model()->screen(indexes[0]).swapped()) model()->screen(indexes[0]) = Screen(); else model()->screen(indexes[0]).setSwapped(false); } }
void GLWidget::mouseMoveEvent(QMouseEvent* event) { QQuickWidget::mouseMoveEvent(event); if (event->isAccepted()) return; if (event->modifiers() == Qt::ShiftModifier && m_producer) { emit seekTo(m_producer->get_length() * event->x() / width()); return; } if (!(event->buttons() & Qt::LeftButton)) return; if ((event->pos() - m_dragStart).manhattanLength() < QApplication::startDragDistance()) return; if (!MLT.producer() || !MLT.isClip()) return; QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; mimeData->setData(Mlt::XmlMimeType, MLT.XML().toUtf8()); drag->setMimeData(mimeData); mimeData->setText(QString::number(MLT.producer()->get_playtime())); if (m_frameRenderer && !m_glslManager && m_frameRenderer->getDisplayFrame().is_valid()) { Mlt::Frame displayFrame(m_frameRenderer->getDisplayFrame().clone(false, true)); QImage displayImage = MLT.image(&displayFrame, 45 * MLT.profile().dar(), 45).scaledToHeight(45); drag->setPixmap(QPixmap::fromImage(displayImage)); } drag->setHotSpot(QPoint(0, 0)); drag->exec(Qt::LinkAction); }
void PlayerCardListWidget::mousePressEvent(QMouseEvent *event) { PlayerCardWidget *child = static_cast<PlayerCardWidget*>(childAt(event->pos())); if (!child) return; // Float up the hierachy until the PlayerCardWidget is found, or we hit the current widget while ((!child->property("PlayerCardWidget").isValid()) && ((PlayerCardListWidget*)child != this)) { child = static_cast<PlayerCardWidget*>(child->parent()); } // If the child is not a PlayerCardWidget, return if (!child->property("PlayerCardWidget").isValid()) return; QPoint hotSpot = event->pos() - child->pos(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << child->playerNumber() << QPoint(hotSpot); QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-chessplayer", itemData); mimeData->setText(child->player()->name()); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(QPixmap::grabWidget(child)); drag->setHotSpot(hotSpot); child->hide(); if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction) child->close(); else child->show(); }
void MainWindow::mousePressEvent(QMouseEvent *event) { //1,获取图片 QLabel *child = static_cast<QLabel*>(childAt(event->pos())); if(!child->inherits("QLabel")) return; QPixmap pixmap = *child->pixmap(); //2,自定义MIME类型 QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream<<pixmap<<QPoint(event->pos()-child->pos()); //3,将数据放入QMimeData中 QMimeData *mimeData = new QMimeData; mimeData->setData("image/png", itemData); //4,将数据放到QDrag中 QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(event->pos()-child->pos()); //5,原图添加阴影 QPixmap tempPixmap = pixmap; QPainter painter; painter.begin(&tempPixmap); painter.fillRect(pixmap.rect(),QColor(127,127,127,127)); painter.end(); child->setPixmap(tempPixmap); //6,执行拖放操作 if(drag->exec(Qt::CopyAction|Qt::MoveAction, Qt::CopyAction) ==Qt::MoveAction) child->close(); else{ child->show(); child->setPixmap(pixmap); } }
void ListItem::mousePressEvent(QMouseEvent *event) { QPixmap pixmap(this->size()); this->render(&pixmap); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << (qint64)this; QMimeData *mimeData = new QMimeData; mimeData->setData(draggableType, itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(event->pos()); QPixmap tempPixmap = pixmap; QPainter painter; painter.begin(&tempPixmap); painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127)); painter.end(); if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) { this->close(); } else { this->show(); } }
void PredefinedElementView::startDrag(Qt::DropActions supportedActions) { // get the item at this position QMimeData * mimeData = model()->mimeData(selectedIndexes()); if(mimeData == 0) return; // this should contains an element Element * element = mimeDataToElement(mimeData); if(element == 0) return QListView::startDrag(supportedActions); // create the pixmap ElementGraphicsItem * item = ElementFactory::Instance()->createGraphicsItem(element); QPoint hotSpot; QPixmap p = elementToPixmap(item, &hotSpot); delete item; // start the drag QDrag * d = new QDrag(this); d->setMimeData(mimeData); d->setPixmap(p); d->setHotSpot(QPoint(p.size().width()/2, p.size().height()/2)); d->exec(supportedActions); }
/** * @brief Slot triggers drag-and-drop. * The user start draging the pattern he wants to add to the timeline. * @param[in] mouse pressed event. */ void BARPatternBarScrollAreaContents::mousePressEvent(QMouseEvent *event) { int x=event->pos().x(); /**< retrieves the position of the cursor. */ BARPatternBar *pBar = static_cast<BARPatternBar*>(childAt(event->pos())); /**< childAt returns a pointer to the child that was clicked. This pointer, of type "widget", is then converted into a BARPatternBar type. */ if (!pBar){return;} /**< checks that the object created isn't empty (NULL). */ QSize patternSize(100,60); /**< the following lines created a pixmap that will be displayed on the cursor during drag-and-drop. */ QPixmap pixmap(patternSize); pixmap.fill(pBar->getBgColor()); QByteArray itemData; /**< the following lines pack up the data to be sent through the drag-and-drop. */ QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << pBar->getBgColor(); /**< stores the color of the bar being dragged. */ dataStream << pBar->getPatternLength(); /**< stores the duration of the pattern associated to the bar being dragged. */ QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-dnditemdata", itemData); /**< store the data we prepared into the QMimeFile. */ mimeData->setText(childAt(event->pos())->accessibleName()); /**< store the name of the pattern associated to the bar being dragged. */ QDrag *drag = new QDrag(this); /**< crates the QDrag object. */ drag->setMimeData(mimeData); /**< stores the data we packed up into the drag object. */ drag->setPixmap(pixmap); /**< sets the image to be displayed on the cursor during the drag-and-drop. */ drag->setHotSpot(event->pos() - pBar->pos()); /**< actually displays the pixmap on the cursor during drag-and-drop. */ if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction){pBar->close();} /**< lines found on the Internet... */ else {pBar->show();} }
void LayerEditScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if(!event->buttons() & Qt::LeftButton) { return; } if((event->scenePos() - _dragStartPosition).manhattanLength() < QApplication::startDragDistance()) { return; } qDebug() << "LayerEditScene::mouseMoveEvent - Starting a drag"; // Get the pixmap item related to the start of the drag. QGraphicsItem *item = itemAt(_dragStartPosition, QTransform()); if(item == 0) { // Couldn't find an item at the location for some reason. qDebug() << "LayerEditScene::mouseMoveEvent - Could not find a sprite at the drag location."; return; } // Static cast is safe because this scene only adds QGraphicsPixmapItem QGraphicsPixmapItem *pixmapItem = static_cast<QGraphicsPixmapItem *>(item); // Remove item from scene Sprite sprite = _pixmapToSprite[pixmapItem]; // Save sprite before it's removed. qDebug() << "LayerEditScene::mouseMoveEvent - Dragging " << sprite.getFileInfo().fileName(); int index = _previews.indexOf(pixmapItem); if(index != -1) { removeSprite(index); recalculatePositions(); } // Create a new drag event and put the source image into the mime data. QDrag *drag = new QDrag((QObject *)event->widget()); QMimeData *data = new QMimeData(); data->setImageData(sprite.getTexture()); data->setText(sprite.getFileInfo().absoluteFilePath()); drag->setMimeData(data); // Put the pixmap that was selected onto the cursor QPixmap pixmap = pixmapItem->pixmap(); drag->setPixmap(pixmap); drag->setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2)); // Execute the drag with a move action. qDebug() << "LayerEditScene::mouseMoveEvent - Executing drag as MoveAction"; Qt::DropAction action = drag->exec(Qt::MoveAction, Qt::MoveAction); if(action != Qt::MoveAction) { // Put sprite back qDebug() << "LayerEditScene::mouseMoveEvent - Move action failed, putting sprite back where it was."; insertSprite(index, sprite); recalculatePositions(); } else { // Delete the old item qDebug() << "LayerEditScene::mouseMoveEvent - Move succeeded, deleting old sprite."; delete pixmapItem; } }
void DragDropArea::mousePressEvent(QMouseEvent *event) { QLabel *child = static_cast<QLabel*>(childAt(event->pos())); if (!child) return; // Only drag children with dynamic property: "drag" if (!child->property("drag").toBool()) return; QPoint hotSpot = event->pos() - child->pos(); QMimeData *mimeData = new QMimeData; mimeData->setText(child->text()); mimeData->setData("application/x-hotspot", QByteArray::number(hotSpot.x()) + " " + QByteArray::number(hotSpot.y())); QPixmap pixmap(child->size()); child->render(&pixmap); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(hotSpot); drag->exec(); }
void AssemblyCreateAndDrag::createAndDrag() { QByteArray itemData(sizeof(QScriptValue*),0); QScriptValue * copy = new QScriptValue( scriptValue.engine()->newObject() ); QScriptValueIterator iter(scriptValue); while( iter.hasNext() ) { iter.next(); copy->setProperty( iter.name() , iter.value() ); } memcpy( itemData.data() , © , sizeof(QScriptValue*) ); QMimeData * mimeData = new QMimeData; mimeData->setData( type , itemData ); this->setDown(false); QDrag * drag = new QDrag(this); drag->setMimeData( mimeData ); drag->setPixmap( icon ); drag->setHotSpot( QPoint( drag->pixmap().width()/2 , drag->pixmap().height()/2 ) ); drag->exec(); }
virtual Q3DragObject *dragObject () { int count = 0; for ( Q3IconViewItem *it = firstItem(); it; it = it->nextItem() ) { if ( it->isSelected() ) { ++count; } } QPixmap pixmap; if ( count > 1 ) { pixmap = KIconLoader::global()->loadIcon( "mail-attachment", KIconLoader::Desktop ); } if ( pixmap.isNull() ) { pixmap = static_cast<AttachmentIconItem *>( currentItem() )->icon(); } QPoint hotspot( pixmap.width() / 2, pixmap.height() / 2 ); QDrag *drag = new QDrag( this ); drag->setMimeData( mimeData() ); drag->setPixmap( pixmap ); drag->setHotSpot( hotspot ); drag->exec( Qt::CopyAction ); return 0; }
void FinalWidget::mouseMoveEvent(QMouseEvent *event) { if (!(event->buttons() & Qt::LeftButton)) return; if ((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance()) return; if (!hasImage) return; QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; //! [0] QByteArray output; QBuffer outputBuffer(&output); outputBuffer.open(QIODevice::WriteOnly); imageLabel->pixmap()->toImage().save(&outputBuffer, "PNG"); mimeData->setData("image/png", output); //! [0] /* //! [1] mimeData->setImageData(QVariant(*imageLabel->pixmap())); //! [1] */ drag->setMimeData(mimeData); drag->setPixmap(imageLabel->pixmap()->scaled(64, 64, Qt::KeepAspectRatio)); //! [2] drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height())); //! [2] drag->start(); }
//---------------------------------------------mouseMoveEvent void QtIOWidget::mouseMoveEvent(QMouseEvent* pEvent) { QByteArray aItemData; QDataStream aDataStream(&aItemData, QIODevice::WriteOnly); QtIOWidget* pThis = this; aDataStream.writeRawData(reinterpret_cast<char*>(&pThis), sizeof(pThis)); QMimeData* pMimeData = new QMimeData; pMimeData->setData(getDragDropFormat(), aItemData); QPixmap tempPixmap(width(), height()); QPainter painter; painter.begin(&tempPixmap); painter.fillRect(rect(), QColor(127, 127, 127, 127)); painter.end(); QDrag* pDrag = new QDrag(this); pDrag->setMimeData(pMimeData); pDrag->setPixmap(tempPixmap); pDrag->setHotSpot(pEvent->pos()); if (pDrag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) { return; } }
void Peg::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)) .length() < QApplication::startDragDistance()) { return; } dragged = true; QDrag *drag = new QDrag(event->widget()); QMimeData *mime = new QMimeData; drag->setMimeData(mime); mime->setColorData(color); mime->setText(QString("#%1%2%3") .arg(color.red(), 2, 16, QLatin1Char('0')) .arg(color.green(), 2, 16, QLatin1Char('0')) .arg(color.blue(), 2, 16, QLatin1Char('0'))); QPixmap pixmap(34, 34); pixmap.fill(Qt::white); QPainter painter(&pixmap); painter.translate(15, 15); painter.setRenderHint(QPainter::Antialiasing); paint(&painter, 0, 0); painter.end(); pixmap.setMask(pixmap.createHeuristicMask()); drag->setPixmap(pixmap); drag->setHotSpot(QPoint(15, 20)); drag->exec(); setCursor(Qt::OpenHandCursor); dragged = false; }
// ドラッグアンドドロップ開始 void CGridLabel::startDragAndDrop( QMouseEvent *ev ) { Q_UNUSED(ev) ; CEditData::ImageData *p = m_pEditData->getImageDataFromNo(m_Index) ; if ( !p ) { return ; } QImage img = p->Image.copy(m_pEditData->getCatchRect().toRect()) ; QPixmap pix = QPixmap::fromImage(img); QByteArray itemData ; QDataStream stream(&itemData, QIODevice::WriteOnly) ; CRectF rect = m_pEditData->getCatchRect() ; // stream << rect << mScale << m_Index ; stream << rect.left() << rect.top() << rect.right() << rect.bottom() << mScale << m_Index ; QMimeData *mimeData = new QMimeData ; mimeData->setData("editor/selected-image", itemData); QPainter painter ; painter.begin(&pix) ; painter.fillRect(pix.rect(), QColor(127, 127, 127, 127)); painter.end() ; QDrag *drag = new QDrag(this) ; drag->setMimeData(mimeData); drag->setPixmap(pix); drag->setHotSpot(QPoint((rect.right()-rect.left())/2, (rect.bottom()-rect.top())/2)); // qDebug() << "x:" << ev->pos().x() << " y:" << ev->pos().y() ; m_pEditData->setDraggingImage(true); drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) ; m_pEditData->setDraggingImage(false); }
void DragLabel::mousePressEvent(QMouseEvent *event) { // if(this->tempo_setup){ //desabilita ação de drag para labels que representarem tempo_setup de maquina // //return; // } // qDebug() << "mousePressEvent called"; dragstart = event->pos(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); //passar variavel tamanho como float zoa o drop dataStream << labelText << tooltip << QPoint(event->pos() - rect().topLeft()) << (int)tamanho << cor.red() << cor.green() << cor.blue() << cor.alpha() << tempo_setup << coordenada; QMimeData *mimeData = new QMimeData; //pra que serve mimeData? mimeData->setData("application/x-fridgemagnet", itemData); mimeData->setText(labelText); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setHotSpot(event->pos() - rect().topLeft()); drag->setPixmap(*pixmap()); hide(); //como funciona drag->exec() ? if(drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction) close(); else show(); }
void BoardSetupDialog::startDrag(QWidget* w, QMouseEvent* event) { if (inDrag) { return; } BoardSetupToolButton *child = qobject_cast<BoardSetupToolButton*>(w); if(!child) { return; } Piece p = child->m_piece; QPoint hotSpot = event->pos(); BoardViewMimeData *mimeData = new BoardViewMimeData; mimeData->m_piece = p; QPixmap pixmap = *child->pixmap(); QDrag* pDrag = new QDrag(this); pDrag->setMimeData(mimeData); pDrag->setPixmap(pixmap); pDrag->setHotSpot(hotSpot); inDrag = true; pDrag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); inDrag = false; }
void DragLabel::mousePressEvent(QMouseEvent * e) { QString str = text(); QPixmap pix; pix = pix.grabWidget(this); QByteArray data; QDataStream stream(&data,QIODevice::WriteOnly); stream << str << QPoint(e->pos()-rect().topLeft()); QMimeData *mimeData = new QMimeData; mimeData->setData("Drag-Text",data); mimeData->setText(str); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setHotSpot(QPoint(e->pos() - rect().topLeft())); drag->setPixmap(pix); hide(); Qt::DropAction dropAction = drag->start(Qt::CopyAction | Qt::MoveAction); if (dropAction == Qt::MoveAction) close(); else show(); }
void DivePictureWidget::mousePressEvent(QMouseEvent *event) { ulong doubleClickInterval = static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval()); static qint64 lasttime = 0L; qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); if (timestamp - lasttime <= doubleClickInterval) { doubleClicked(indexAt(event->pos())); } else { lasttime = timestamp; QPixmap pixmap = model()->data(indexAt(event->pos()), Qt::DecorationRole).value<QPixmap>(); QString filename = model()->data(indexAt(event->pos()), Qt::DisplayPropertyRole).toString(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << filename << event->pos(); QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-subsurfaceimagedrop", itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(event->pos() - rectForIndex(indexAt(event->pos())).topLeft()); drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); } }
void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ ) { QListWidgetItem *item = currentItem(); QByteArray itemData; QDataStream dataStream( &itemData, QIODevice::WriteOnly ); int i_type = item->data( Qt::UserRole ).toInt(); int i_option = parent->getOptions(); dataStream << i_type << i_option; /* Create a new dragging event */ QDrag *drag = new QDrag( this ); /* With correct mimedata */ QMimeData *mimeData = new QMimeData; mimeData->setData( "vlc/button-bar", itemData ); drag->setMimeData( mimeData ); /* And correct pixmap */ QPixmap aPixmap = item->icon().pixmap( QSize( 22, 22 ) ); drag->setPixmap( aPixmap ); drag->setHotSpot( QPoint( 20, 20 ) ); /* We want to keep a copy */ drag->exec( Qt::CopyAction | Qt::MoveAction ); }
void DragClientQt::startDrag(DragImageRef dragImage, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard* clipboard, Frame* frame, bool) { #ifndef QT_NO_DRAGANDDROP QMimeData* clipboardData = clipboard->pasteboard().clipboardData(); clipboard->pasteboard().invalidateWritableData(); PlatformPageClient pageClient = m_chromeClient->platformPageClient(); QObject* view = pageClient ? pageClient->ownerWidget() : 0; if (view) { QDrag* drag = new QDrag(view); if (dragImage) { drag->setPixmap(*dragImage); drag->setHotSpot(IntPoint(eventPos - dragImageOrigin)); } else if (clipboardData && clipboardData->hasImage()) drag->setPixmap(qvariant_cast<QPixmap>(clipboardData->imageData())); DragOperation dragOperationMask = clipboard->sourceOperation(); drag->setMimeData(clipboardData); Qt::DropAction actualDropAction = drag->exec(dragOperationsToDropActions(dragOperationMask)); // Send dragEnd event PlatformMouseEvent me(m_chromeClient->screenToRootView(QCursor::pos()), QCursor::pos(), LeftButton, PlatformEvent::MouseMoved, 0, false, false, false, false, 0); frame->eventHandler()->dragSourceEndedAt(me, dropActionToDragOperation(actualDropAction)); } frame->page()->dragController()->dragEnded(); #endif }
void GridView::startDrag( Qt::DropActions supportedActions ) { QList<QPersistentModelIndex> pindexes; QModelIndexList indexes; foreach( const QModelIndex& idx, selectedIndexes() ) { if ( ( m_proxyModel->flags( idx ) & Qt::ItemIsDragEnabled ) ) { indexes << idx; pindexes << idx; } } if ( indexes.count() == 0 ) return; qDebug() << "Dragging" << indexes.count() << "indexes"; QMimeData* data = m_proxyModel->mimeData( indexes ); if ( !data ) return; QDrag* drag = new QDrag( this ); drag->setMimeData( data ); const QPixmap p = TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeAlbum, indexes.count() ); drag->setPixmap( p ); drag->setHotSpot( QPoint( -20, -20 ) ); /* Qt::DropAction action = */ drag->exec( supportedActions, Qt::CopyAction ); }
void ActorDragTree::startDrag(Qt::DropActions /*supportedActions*/) { ActorTypeTreeWidget *item = dynamic_cast<ActorTypeTreeWidget*>(currentItem()); // Only resource items can be dragged. if (!item || !item->isLeafNode()) { return; } QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); QIcon icon = item->icon(0); QPixmap pixmap = icon.pixmap(16); dtCore::RefPtr<const dtDAL::ActorType> actorType = item->getActorType(); QString category = actorType->GetCategory().c_str(); QString name = actorType->GetName().c_str(); dataStream << category << name; QMimeData *mimeData = new QMimeData; mimeData->setData("Actor", itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2)); drag->setPixmap(pixmap); if (drag->exec(Qt::MoveAction) == Qt::MoveAction) { } }
void TabButton::mouseMoveEvent(QMouseEvent *e){ if (!isLeftBtnHold){ QPushButton::mouseMoveEvent(e); return; } QPixmap pxm = QPixmap::grabWidget(this, rect()); QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); stream << pxm << QPoint(mapFromGlobal(QCursor::pos())); QMimeData *mimeData = new QMimeData(); mimeData->setData("application/x-dnditemdata", data); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pxm); drag->setHotSpot(mapFromGlobal(QCursor::pos())); drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); e->accept(); }
bool QtDNDTabBar::event(QEvent* event) { QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event); if (mouseEvent) { QWidget* childAtPoint = window()->childAt(mapTo(window(), mouseEvent->pos())); QtDNDTabBar* underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint); if (!underMouse && childAtPoint) { underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint->parent()); } if (!underMouse && currentIndex() >= 0) { // detach and drag // stop move event QMouseEvent* finishMoveEvent = new QMouseEvent (QEvent::MouseMove, mouseEvent->pos (), Qt::NoButton, Qt::NoButton, Qt::NoModifier); QTabBar::event(finishMoveEvent); delete finishMoveEvent; finishMoveEvent = NULL; // start drag QDrag* drag = new QDrag(this); QMimeData* mimeData = new QMimeData; // distinguish tab-reordering drops from other ones mimeData->setData("action", "application/tab-detach") ; drag->setMimeData(mimeData); // set drag image QRect rect = tabRect( currentIndex() ); #if QT_VERSION >= 0x050000 QPixmap pixmap = grab(rect); #else QPixmap pixmap = QPixmap::grabWidget(this, rect); #endif QPixmap targetPixmap (pixmap.size ()); QPainter painter (&targetPixmap); painter.setOpacity(0.9); painter.drawPixmap(0,0, pixmap); painter.end (); drag->setPixmap (targetPixmap); drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height())); dragIndex = currentIndex(); dragText = tabText(dragIndex); dragWidget = dynamic_cast<QTabWidget*>(parent())->widget(dragIndex); assert(dragWidget); dynamic_cast<QTabWidget*>(parent())->removeTab(currentIndex()); Qt::DropAction dropAction = drag->exec(); if (dropAction == Qt::IgnoreAction) { // aborted drag, put tab back in place // disable event handling during the insert for the tab to prevent infinite recursion (stack overflow) dragWidget->blockSignals(true); dynamic_cast<QTabWidget*>(parent())->insertTab(dragIndex, dragWidget, dragText); dragWidget->blockSignals(false); } return true; } } return QTabBar::event(event); }
void TreeView::startDrag(Qt::DropActions supportedActions) { QModelIndex index = selectedIndexes().value(0); if (!index.isValid()) return; QMimeData *data = model()->mimeData(QModelIndexList() << index); if (!data) return; QRect rect; QPixmap pixmap; QPoint point; { QAbstractItemDelegate *delegate = itemDelegate(index); QStyleOptionViewItemV4 option = viewOptions(); option.locale = this->locale(); option.locale.setNumberOptions(QLocale::OmitGroupSeparator); option.widget = this; option.state |= QStyle::State_Selected; option.rect = visualRect(index); point = option.rect.topLeft(); option.rect.moveTo(0, 0); option.rect.setSize(delegate->sizeHint(option, index)); rect = option.rect; pixmap = QPixmap(rect.size()); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); delegate->paint(&painter, option, index); } QDrag *drag = new QDrag(this); drag->setPixmap(pixmap); drag->setMimeData(data); point = QCursor::pos() - viewport()->mapToGlobal(point); drag->setHotSpot(point); // drag->setHotSpot(QCursor::pos() - rect.topLeft()); Qt::DropAction setDefaultDropAction = QAbstractItemView::defaultDropAction(); Qt::DropAction defaultDropAction = Qt::IgnoreAction; if (setDefaultDropAction != Qt::IgnoreAction && (supportedActions & setDefaultDropAction)) defaultDropAction = setDefaultDropAction; else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove) defaultDropAction = Qt::CopyAction; if (drag->exec(supportedActions, defaultDropAction) == Qt::IgnoreAction && index.data(ItemTypeRole).toInt() == ContactType) { if (QWidget *widget = QApplication::topLevelAt(QCursor::pos())) { if (widget->window() == this->window()) return; } Event ev("contact-list-drop", QCursor::pos() - point, index.data(BuddyRole)); ev.send(); } // debug() << "DropAction" << drag->exec(supportedActions, defaultDropAction); // if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction) // d->clearOrRemove(); // {} }