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(); }
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(); }
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 VSCVWidget::videoMouseMove(QMouseEvent *e) { VDC_DEBUG( "%s mouseMoveEvent %d\n",__FUNCTION__, m_nId); //if (e->pos().y() > height() - ui.videoControl->height()) { if (1) { //ui.videoControl->show(); emit ShowFocusClicked(m_nId); m_lastMoveTime = time(NULL); } if (m_pStarted == TRUE || m_InstantPbMode == TRUE) { if (m_DragStart == TRUE) { VDC_DEBUG( "%s mouseMoveEvent %d event x %d\n",__FUNCTION__, m_nId, e->x()); if (abs(e->x() - m_lastDragX) < 5) { return; } }else if (m_PtzStart == TRUE) { if (abs(e->x() - m_lastPtzX) < 10 || abs(e->y() - m_lastPtzY) < 10 ) { return; } gFactory->DrawPtzDirection(m_nPlayId, m_videoWindow, width()/2, height()/2, e->x(), e->y()); PtzAction(width()/2, height()/2, e->x(), e->y()); m_lastPtzX = e->x(); m_lastPtzY = e->y(); return; } else { return; } u32 nId = m_nId; m_DragStart = FALSE; VDC_DEBUG( "%s id %d\n",__FUNCTION__, nId); QMimeData *mimeData = new QMimeData(); mimeData->setText(QString::number(nId + VWIDGET_ID_OFFSET)); // Create drag QPixmap pixmap(":/device/resources/camera1.png"); QPainter painter(&pixmap); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()/2)); drag->exec(); } }
// ************************************************************ void SymbolWidget::mouseMoveEvent(QMouseEvent*) { QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData; mimeData->setText("QucsComponent:"+theModel()); drag->setMimeData(mimeData); drag->setPixmap( QPixmap(empty_xpm)); drag->setHotSpot(QPoint(drag->pixmap().width()/2,drag->pixmap().height())); drag->exec(); }
Q3DragObject* KonqSidebarTree::dragObject() { KonqSidebarTreeItem* item = static_cast<KonqSidebarTreeItem *>( selectedItem() ); if ( !item ) return 0; QMimeData *mimeData = new QMimeData; if ( item->populateMimeData( mimeData, false ) ) { QDrag* drag = new QDrag( viewport() ); drag->setMimeData(mimeData); const QPixmap *pix = item->pixmap(0); if ( pix && drag->pixmap().isNull() ) drag->setPixmap( *pix ); } else { delete mimeData; mimeData = 0; } #ifdef __GNUC__ #warning TODO port to QDrag (only possible once porting away from Q3ListView?) #endif return 0; //return drag; }
void ImageWindow::startDrag() { QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData(); QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); uintptr_t ptr = reinterpret_cast<uintptr_t>(this); stream << QVariant::fromValue(ptr); if(_imageView->mode() == ImageView::MODE_MOUSE) { mimeData->setData("application/detiqt.genericinterface.stdimgwnd", encodedData); drag->setPixmap(_imageView->pixmap().scaled(QSize(76,76), Qt::KeepAspectRatio, Qt::FastTransformation)); } else { mimeData->setData("application/detiqt.genericinterface.stdimgwnd.copy", encodedData); drag->setPixmap(_imageView->pixmap().copy(_imageView->select()).scaled(QSize(76,76), Qt::KeepAspectRatio, Qt::FastTransformation)); } drag->setMimeData(mimeData); drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()/2)); drag->exec(); }
void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if ( !m_enabled || QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length() < m_startDragDistance) { return; } emit dragStarted(); QDrag *drag = new QDrag(event->widget()); DeclarativeMimeData* dataCopy = new DeclarativeMimeData(m_data); //Qt will take ownership of this copy and delete it. drag->setMimeData(dataCopy); if (!m_delegateImage.isNull()) { drag->setPixmap(QPixmap::fromImage(m_delegateImage)); } else if (m_delegate) { // Render the delegate to a Pixmap QDeclarativeItem* item = qobject_cast<QDeclarativeItem *>(m_delegate->create(m_delegate->creationContext())); QGraphicsScene scene; scene.addItem(item); QPixmap pixmap(scene.sceneRect().width(), scene.sceneRect().height()); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); scene.render(&painter); painter.end(); delete item; drag->setPixmap(pixmap); } drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()/2)); // TODO: Make a property for that //setCursor(Qt::OpenHandCursor); //TODO? Make a property for the cursor Qt::DropAction action = drag->exec(m_supportedActions, m_defaultAction); emit drop(action); }
void UBDocumentThumbnailWidget::mouseMoveEvent(QMouseEvent *event) { if (!dragEnabled()) { event->ignore(); return; } if (!(event->buttons() & Qt::LeftButton)) return; if ((event->pos() - mMousePressPos).manhattanLength() < QApplication::startDragDistance()) return; QList<QGraphicsItem*> graphicsItems = items(mMousePressPos); UBSceneThumbnailPixmap* sceneItem = 0; while (!graphicsItems.isEmpty() && !sceneItem) { sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(graphicsItems.takeFirst()); } if (sceneItem) { QDrag *drag = new QDrag(this); QList<UBMimeDataItem> mimeDataItems; foreach (QGraphicsItem *item, selectedItems()) mimeDataItems.append(UBMimeDataItem(sceneItem->proxy(), mGraphicItems.indexOf(item))); UBMimeData *mime = new UBMimeData(mimeDataItems); drag->setMimeData(mime); drag->setPixmap(sceneItem->pixmap().scaledToWidth(100)); drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height() / 2)); drag->exec(Qt::MoveAction); } UBThumbnailWidget::mouseMoveEvent(event); }
void CardsList::startDrag(int index) { if(index >= ls.size()) { return; } QMimeData *mimedata = new QMimeData; quint32 id = ls[index]; mimedata->setText(QString::number(id)); QDrag *drag = new QDrag(this); drag->setMimeData(mimedata); auto &item = items.find(index).value(); if(item.getPixmap()) { drag->setPixmap(item.getPixmap()->scaled(cardSize)); drag->setHotSpot(QPoint(drag->pixmap().width() / 2, drag->pixmap().height() / 2)); } dragHelper.moved = false; drag->exec(Qt::MoveAction); }
void VSCDeviceTree::mousePressEvent(QMouseEvent *event) { VDC_DEBUG( "%s \n",__FUNCTION__); // Get current selection QTreeWidgetItem *selectedItem = currentItem(); if (event->buttons() & Qt::RightButton) { return; } // If the selected Item exists if (selectedItem) { VSCDeviceIPC *pIpc = dynamic_cast<VSCDeviceIPC * >(selectedItem); //VSCDeviceIPC *pIpc = (VSCDeviceIPC * )(selectedItem); // Create data if (pIpc) { u32 nId = pIpc->GetDeviceId(); VDC_DEBUG( "%s id %d\n",__FUNCTION__, nId); QMimeData *mimeData = new QMimeData(); mimeData->setText(QString::number(nId)); // Create drag QPixmap pixmap(":/device/resources/camera1.png"); QPainter painter(&pixmap); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()/2)); drag->exec(); } } QTreeWidget::mousePressEvent(event); }
void HItemList::mouseMoveEvent(QMouseEvent *event) { if (!(event->buttons() & Qt::LeftButton)) return; if ((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance()) return; QListWidgetItem *item = currentItem(); if(item == NULL) return; QString filename = "file://"+item->data(Qt::UserRole).toString(); QMimeData *mimeData = new QMimeData; mimeData->setData("text/plain", filename.toUtf8()); mimeData->setData("text/uri-list", filename.toUtf8()); mimeData->setData("text/x-moz-url", filename.toUtf8()); mimeData->setData("application/x-desktop", filename.toUtf8()); mimeData->setData("application/x-qabstractitemmodeldatalist", filename.toUtf8()); QList<QUrl> urls; urls.append(filename); mimeData->setUrls(urls); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(getItemLable(item)); drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height())); Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction); Q_UNUSED(dropAction) QListWidget::mouseMoveEvent(event); }