QDrag *DndFactory::createDrag( Incidence *incidence, QWidget *owner ) { QDrag *drag = new QDrag( owner ); drag->setMimeData( createMimeData( incidence ) ); if ( incidence->type() == "Event" ) { drag->setPixmap( BarIcon( "view-calendar-day" ) ); } else if ( incidence->type() == "Todo" ) { drag->setPixmap( BarIcon( "view-calendar-tasks" ) ); } return drag; }
void DragHandle::mouseMoveEvent(QMouseEvent* ev) { assert(_panel != NULL); if(!_panel || !_pressed || (ev->pos() - _clickPosition).manhattanLength() < QApplication::startDragDistance()) return; QDrag* drag = new QDrag(_panel); PanelMimeType* mimedata = new PanelMimeType(); mimedata->setPanel(_panel); drag->setMimeData(mimedata); drag->setPixmap(_panel->view()->snapshot(QSize(100,100))); drag->exec(Qt::MoveAction); }
void BlockNavigationTreeWidget::performDrag() { QTreeWidgetItem *item = currentItem(); if(item) { QMimeData *mimeData = new QMimeData; QString text = item->text(0); mimeData->setText(item->text(0)); QDrag* drag = new QDrag(this); drag->setMimeData(mimeData); m_DropAction = drag->exec( Qt::CopyAction ); } }
void ImageWidget::mouseMoveEvent(QMouseEvent *event) { if ((event->buttons() & Qt::LeftButton) && (event->pos() - mDragStartPos).manhattanLength() > QApplication::startDragDistance()) { if (mHasImage) { QDrag *drag = new QDrag(this); drag->setMimeData(new QMimeData()); drag->mimeData()->setImageData(mPicture.data()); drag->start(); } } }
//![0] void SourceWidget::startDrag() { mimeData = new MimeData; connect(mimeData, SIGNAL(dataRequested(QString)), this, SLOT(createData(QString)), Qt::DirectConnection); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(QPixmap(":/images/drag.png")); drag->exec(Qt::CopyAction); }
void startActionDrag(QWidget *dragParent, ActionModel *model, const QModelIndexList &indexes, Qt::DropActions supportedActions) { if (indexes.empty()) return; QDrag *drag = new QDrag(dragParent); QMimeData *data = model->mimeData(indexes); drag->setMimeData(data); if (ActionRepositoryMimeData *actionMimeData = qobject_cast<ActionRepositoryMimeData *>(data)) drag->setPixmap(ActionRepositoryMimeData::actionDragPixmap(actionMimeData->actionList().front())); drag->start(supportedActions); }
void LayerControlWidgetBase::mouseMoveEvent(QMouseEvent *event) { if (!(event->buttons() & Qt::LeftButton)) return; if ((event->pos() - _dragStartPosition).manhattanLength() < QApplication::startDragDistance()) return; QDrag *drag = new QDrag(this); drag->setMimeData(new LayerWidgetMimeData(this)); Qt::DropAction dropAction = drag->exec(Qt::MoveAction); }
void NowPlayingListWidget::mousePressEvent(QMouseEvent *event) { //after checking if we are in presence of a drag operation, we can then encapsulate //the data to be sent and let start the drag operation if (event->button() == Qt::LeftButton && itemAt(event->pos())) { QDrag *drag = new QDrag(this); QMimeData *mimeData = new QMimeData(); mimeData->setText(itemAt(event->pos())->text()); //who receives expects plain text data drag->setMimeData(mimeData); drag->exec(); } }
void ImageWIdget::makeDrag() { QDrag *dr = new QDrag(this); // The data to be transferred by the drag and drop operation is contained in a QMimeData object QMimeData *data = new QMimeData; data->setText(myS.img.image_file); // Assign ownership of the QMimeData object to the QDrag object. dr->setMimeData(data); // Start the drag and drop operation dr->start(); }
void BlockButton::mouseMoveEvent( QMouseEvent *event ) { #ifndef ANDROID assert(block); QDrag *drag = new QDrag(this); drag->setMimeData(block->mimeData()); drag->setPixmap(QPixmap::fromImage(block->translucidImage(vpl->getViewScale()))); const qreal thisScale = width() / 256.; drag->setHotSpot(event->pos()*vpl->getViewScale() / thisScale); drag->exec(Qt::CopyAction); #endif // ANDROID }
void TabBar::mouseMoveEvent(QMouseEvent *event) { if(!(event->buttons() & Qt::LeftButton) || !tabsClosable()) return PlusTabBar::mouseMoveEvent(event); if((event->pos() - m_startDragPos).manhattanLength() < QApplication::startDragDistance()) return PlusTabBar::mouseMoveEvent(event); int idx = tabAt(event->pos()); if(idx == -1) return PlusTabBar::mouseMoveEvent(event); event->accept(); QDrag *drag = new QDrag(this); tabView()->createSplitOverlay(m_id, drag); QStyleOptionTabV3 tab; initStyleOption(&tab, idx); QWidget *tabWidget = ((QTabWidget*)parent())->widget(idx); QPixmap wMap(tabWidget->size()); tabWidget->render(&wMap); if(wMap.width() > 400 || wMap.height() > 400) wMap = wMap.scaled(400, 400, Qt::KeepAspectRatio, sConfig.get(CFG_BOOL_SMOOTH_SCALING) ? Qt::SmoothTransformation : Qt::FastTransformation); QSize size = tabRect(idx).size(); size.rwidth() = std::max(wMap.width(), size.width()); size.rheight() += wMap.height(); QPixmap map(size); map.fill(Qt::transparent); QStylePainter p(&map, this); p.initFrom(this); p.drawItemPixmap(QRect(0, tab.rect.height()-5, wMap.width(), wMap.height()), 0, wMap); tab.rect.moveTopLeft(QPoint(0, 0)); p.drawControl(QStyle::CE_TabBarTab, tab); p.end(); QMimeData *mime = new QMimeData(); mime->setData("data/tabinfo", QString("%1 %2 %3").arg(m_id).arg(idx).arg(tabView()->getWindowId()).toLatin1()); drag->setPixmap(map); drag->setMimeData(mime); drag->exec(); }
void CRenderClientsListView::performDrag() { qDebug() << QString("performDrag"); CRenderClientsListModel* lmodel = reinterpret_cast<CRenderClientsListModel*>(model()); QModelIndexList indexList = selectedIndexes(); CModelDiff md(m_role); for(int i = 0; i < indexList.size(); i++) { comb_hash_t combhash; CItemBase* item = lmodel->itemFromIndex(indexList.at(i)); switch(item->type()) { case CItemType::E_STREAM_CLIENT: { CStreamClientItem* scItem = reinterpret_cast<CStreamClientItem*>(item); combhash.type = scItem->type(); if(m_role == E_OWN_RENDER_CLIENT) { int filteredline = lmodel->own2availIndex(indexList.at(i).row()); combhash.line = filteredline; } else { combhash.line = indexList.at(i).row(); } md.appendToSelectedItems(combhash); } default: break; } } if (md.getNumSelected() > 0) { QMimeData *mimeData = new QMimeData; //mimeData->setText(item->asString()); mimeData->setData(dndMimeType, md.toQByteArray()); m_dragActive = true; QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); // drag->setPixmap(QPixmap(":/images/person.png")); Qt::DropAction action = drag->exec(Qt::MoveAction); m_dragActive = false; qDebug() << QString("DropAction: %1").arg(action); } }
void PushButton::mousePressEvent(QMouseEvent *e) { if (e->button() != Qt::LeftButton && e->button() != Qt::RightButton) { return; } *(button) = e->button(); *(first) = true; // Qt will clean up the QDrag and associated QMimeData objects, so they mustn't be deleted. QDrag *drag = new QDrag(this); QMimeData *md = new QMimeData(); drag->setMimeData(md); drag->exec(Qt::IgnoreAction); // After a drag action the released signal isn't auto-emitted, but we need it. emit released(); }
void pa_db::free_elements_widget::mouseMoveEvent( QMouseEvent *event ) { if ( event->buttons( ) & Qt::LeftButton ) { if ( currentItem( ) ) { QDrag *drag = new QDrag( this ); QMimeData *mimeData = new QMimeData; mimeData->setData( pa_db::text::free_element_mime_data( ), currentItem( )->data( Qt::UserRole ).toByteArray( ) ); drag->setMimeData( mimeData ); drag->start( Qt::MoveAction ); } } }
void ProjectListWidget::startDrag() { QListWidgetItem *item = currentItem(); if (item) { QMimeData *mimeData = new QMimeData; mimeData->setText(item->text()); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(QPixmap(":/images/person.png")); if (drag->start(Qt::MoveAction) == Qt::MoveAction) delete item; } }
void pa_db::species_widget::mouseMoveEvent( QMouseEvent *event ) { if ( event->buttons() & Qt::LeftButton ) { if ( currentItem() ) { QDrag *drag = new QDrag( this ); QMimeData *mimeData = new QMimeData; mimeData->setData( "application/x-qt-windows-mime;value=\"species_mime_data\"", currentItem()->data( Qt::UserRole ).toByteArray() ); drag->setMimeData( mimeData ); drag->start( Qt::CopyAction ); } } }
void ClassItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length() < QApplication::startDragDistance()) { return; } qfLogFuncFrame(); setCursor(Qt::ClosedHandCursor); QDrag *drag = new QDrag(event->widget()); QMimeData *mime = new QMimeData; drag->setMimeData(mime); { QVariantMap m; auto &dt = data(); int slot_ix = dt.startSlotIndex(); int class_ix = dt.classIndex(); m[QStringLiteral("slotIndex")] = slot_ix; m[QStringLiteral("classIndex")] = class_ix; QJsonDocument jsd = QJsonDocument::fromVariant(m); QString mime_text = QString::fromUtf8(jsd.toJson()); qfDebug() << "mime:" << mime_text; mime->setText(mime_text); QPixmap pixmap(rect().size().toSize()); pixmap.fill(Qt::white); QPainter painter(&pixmap); //painter.translate(15, 15); painter.setRenderHint(QPainter::Antialiasing); QStyleOptionGraphicsItem opt; paint(&painter, &opt, 0); { m_classText->paint(&painter, &opt, nullptr); painter.translate(m_courseText->pos()); m_courseText->paint(&painter, &opt, nullptr); painter.translate(m_classdefsText->pos() - m_courseText->pos()); m_classdefsText->paint(&painter, &opt, nullptr); } painter.end(); //pixmap.setMask(pixmap.createHeuristicMask()); drag->setPixmap(pixmap); drag->setHotSpot(QPoint(5 * ganttScene()->displayUnit(), 0)); } Qt::DropAction act = drag->exec(); qfDebug() << "drag exit:" << act; if(act == Qt::MoveAction) { } setCursor(Qt::ArrowCursor); }
void QDragLabel::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton){ QDrag* drag = new QDrag(this); QMimeData* mime = new QMimeData; mime->setText(this->class_name); mime->setImageData(this->pixmap()->toImage()); drag->setMimeData(mime); drag->setPixmap(*this->pixmap()); Qt::DropAction dropAction = drag->exec(); } }
void WTrackText::mouseMoveEvent(QMouseEvent *event) { if ((event->buttons() & Qt::LeftButton) && m_pCurrentTrack) { QList<QUrl> locationUrls; locationUrls.append(QUrl::fromLocalFile(m_pCurrentTrack->getLocation())); QMimeData* mimeData = new QMimeData(); mimeData->setUrls(locationUrls); QDrag* drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(QPixmap(":images/library/ic_library_drag_and_drop.png")); drag->exec(Qt::CopyAction); } }
void OperatorLibraryView::startDrag() { QModelIndex index = currentIndex(); if(index.isValid() && m_model->isOperator(index)) { // allocate a operator data object OperatorData* data = m_model->newOperatorData(index); QDrag* drag = new QDrag(this); drag->setMimeData(data); drag->exec(Qt::CopyAction, Qt::CopyAction); } }
void UBLibraryAPI::startDrag(QString pUrl) { QDrag *drag = new QDrag(mWebView); QMimeData *mimeData = new QMimeData; QList<QUrl> urls; urls << QUrl(pUrl); mimeData->setUrls(urls); drag->setMimeData(mimeData); drag->exec(Qt::CopyAction); }
void EntitiesTreeWidget::mouseMoveEvent(QMouseEvent *event) { if(selectedItems().count() <= 0){ return; } QTreeWidgetItem *selectedItem = selectedItems().at(0); if (selectedItem ){ if(!selectedItem->data(0,Qt::UserRole).isValid()){ QTreeWidget::mousePressEvent(event); return; } qlonglong pointer = selectedItem->data(0,Qt::UserRole + 1).toLongLong(); QMimeData *mimeData = new QMimeData; QByteArray strPointer = QString("%1").arg(pointer).toLatin1(); mimeData->setData("pointer",strPointer); if(selectedItem->data(0,Qt::UserRole).toInt() == (int)yarp::manager::MODULE){ mimeData->setText("module"); } if(selectedItem->data(0,Qt::UserRole).toInt() == (int)yarp::manager::APPLICATION){ mimeData->setText("application"); } QFontMetrics fontMetric(font()); int textWidth = fontMetric.width(selectedItem->text(0)); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); // QPixmap pix(textWidth + 40,18); // QPainter painter(&pix); // QPen pen(QBrush(QColor((Qt::blue))),1); // painter.setPen(pen); // painter.fillRect(0,0,textWidth + 40,18,QBrush(QColor((Qt::lightGray)))); // painter.drawRect(0,0,textWidth- + 39,17); // painter.drawImage(QRectF(1,1,16,16),QImage(":/module22.svg")); // painter.drawText(QRectF(16,1,textWidth + 20,16),Qt::AlignCenter,selectedItem->text(0)); // //pix.fill(QColor(Qt::red)); // drag->setPixmap(pix); drag->exec(Qt::CopyAction); } QTreeWidget::mouseMoveEvent(event); }
void PokemonBoxButton::startDrag() { QMimeData * data = new QMimeData(); data->setProperty("TeamSlot", num); data->setImageData(px); QDrag * drag = new QDrag(this); drag->setMimeData(data); drag->setPixmap(px); drag->setHotSpot(QPoint(px.width()/2,px.height()/2)); drag->exec(Qt::MoveAction); emit dragStarted(num); }
void TB_PokemonItem::startDrag() { QMimeData * data = new QMimeData(); QVariant v; v.setValue(box); data->setProperty("Box", v); data->setProperty("Item", box->getNumOf(this)); data->setImageData(pixmap()); QDrag * drag = new QDrag(box->parentWidget()); drag->setMimeData(data); drag->setPixmap(pixmap()); drag->setHotSpot(QPoint(pixmap().width()/2,pixmap().height()/2)); drag->exec(Qt::MoveAction); }
void DropTabBar::mouseMoveEvent(QMouseEvent* event) { if(!(event->buttons() == Qt::LeftButton)) { QTabBar::mouseMoveEvent(event) ; } if((event->pos() - _dragStartPos).manhattanLength() < QApplication::startDragDistance()) { QTabBar::mouseMoveEvent(event) ; } QDrag* drag = new QDrag(this) ; QMimeData* mime = new QMimeData ; mime->setData("action","tab-move") ; drag->setMimeData(mime) ; drag->exec() ; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void PipelineFilterWidget::mouseMoveEvent(QMouseEvent* event) { if(!(event->buttons() & Qt::LeftButton)) { return; } if((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance()) { return; } // The user is dragging the filter widget so we should set it as selected. setIsSelected(true); QPixmap pixmap = grab(); // Create new picture for transparent QPixmap transparent(pixmap.size()); // Do transparency transparent.fill(Qt::transparent); #if 1 QPainter p; p.begin(&transparent); p.setOpacity(0.70); p.drawPixmap(0, 0, pixmap); p.end(); #endif QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << transparent << QPoint(event->pos()); QMimeData* mimeData = new QMimeData; mimeData->setData("application/x-dnditemdata", itemData); QDrag* drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(transparent); drag->setHotSpot(event->pos()); emit dragStarted(this); // if(drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) // { // qDebug() << "Drag should close the widget because it was MOVE" << "\n"; // } // else // { // qDebug() << "Drag should leave Widget alone because it was COPY" << "\n"; // } drag->exec(Qt::MoveAction); }
void DraggableLabel::dragPixmap() { const QPixmap *currentPixmap = pixmap(); if (currentPixmap == NULL) return; // Make temp file QTemporaryFile *tempFile = new QTemporaryFile(AppTools::addPathSeparator(QDir::tempPath()) + DRAG_LABEL_FILENAME_TEMPLATE); tempFile->setAutoRemove(false); if (!tempFile->open()) { delete tempFile; return; } // Arrange data QMimeData *data = new QMimeData; data->setImageData(currentPixmap->toImage()); // Save pixmap QString tempFileName = tempFile->fileName(); currentPixmap->save(tempFileName); delete tempFile; QDEBUG("Dragged file saved to " << tempFileName); // Keep its name QList <QUrl> urls; urls.append(QUrl::fromLocalFile(tempFileName)); data->setUrls(urls); QPixmap preview = currentPixmap->scaled(DRAG_LABEL_PREVIEW_WIDTH, DRAG_LABEL_PREVIEW_HEIGHT, Qt::KeepAspectRatio); QPixmap preview2(preview.width(), preview.height()); preview2.fill(QColor(180, 180, 180)); preview.setAlphaChannel(preview2); // Go drag QDrag *drag = new QDrag(this); drag->setPixmap(preview); drag->setMimeData(data); drag->setHotSpot(QPoint(preview.width() / 2, preview.height() / 2)); // Let's go! drag->exec(Qt::MoveAction); }
void PaletteTree::DraggableElement::mousePressEvent(QMouseEvent *event) { QWidget *atMouse = childAt(event->pos()); if (!atMouse || atMouse == this) { return; } DraggableElement *child = dynamic_cast<DraggableElement *>(atMouse->parent()); if (!child) { child = dynamic_cast<DraggableElement *>(atMouse); } if (!child) { return; } Q_ASSERT(child->id().idSize() == 3); // it should be element type // new element's ID is being generated here // may this epic event should take place in some more appropriate place Id elementId(child->id(), QUuid::createUuid().toString()); QByteArray itemData; bool isFromLogicalModel = false; QDataStream stream(&itemData, QIODevice::WriteOnly); stream << elementId.toString(); // uuid stream << Id::rootId().toString(); // pathToItem stream << QString("(" + child->text() + ")"); stream << QPointF(0, 0); stream << isFromLogicalModel; QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-real-uml-data", itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); QPixmap p = child->icon().pixmap(96, 96); if (!p.isNull()) { drag->setPixmap(child->icon().pixmap(96, 96)); } if (drag->start(Qt::CopyAction | Qt::MoveAction) == Qt::MoveAction) { child->close(); } else { child->show(); } }
void CPlaylistView::performDrag() { qDebug() << QString("performDrag"); CMuroaListModel* plModel = reinterpret_cast<CMuroaListModel*>(model()); QModelIndexList indexList = selectedIndexes(); CModelDiff md(m_role); for(int i = 0; i < indexList.size(); i++) { comb_hash_t combhash; CItemBase* item = plModel->itemFromIndex(indexList.at(i)); switch(item->type()) { case CItemType::E_PLAYLISTITEM: { CPlaylistItem* plitem = reinterpret_cast<CPlaylistItem*>(item); combhash.type = plitem->type(); combhash.hash = plitem->getMediaItemHash(); combhash.pl_id = plitem->getHash(); combhash.line = indexList.at(i).row(); md.appendToSelectedItems(combhash); break; } default: // error, there should only be playlist items in the playlist. break; } } if (md.getNumSelected() > 0) { QMimeData *mimeData = new QMimeData; //mimeData->setText(item->asString()); mimeData->setData("application/x-muroa-playlist-diff", md.toQByteArray()); m_dragActive = true; QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); // drag->setPixmap(QPixmap(":/images/person.png")); Qt::DropAction action = drag->exec(Qt::MoveAction); m_dragActive = false; qDebug() << QString("DropAction: %1").arg(action); } }
void QRImageWidget::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton && pixmap()) { event->accept(); QMimeData *mimeData = new QMimeData; mimeData->setImageData(exportImage()); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->exec(); } else { QLabel::mousePressEvent(event); } }