void DragTool::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { const QMargins margins = contentsMargins(); const QRect iconRect((width() - d->iconSize.width()) / 2, margins.top(), d->iconSize.width(), d->iconSize.height()); if (iconRect.contains(event->pos())) { auto drag = new QDrag(this); auto mimeData = new QMimeData; QByteArray data; QDataStream dataStream(&data, QIODevice::WriteOnly); dataStream << d->newElementId << d->title << d->stereotype; mimeData->setData(QLatin1String(qmt::MIME_TYPE_NEW_MODEL_ELEMENTS), data); drag->setMimeData(mimeData); QPixmap pixmap = d->icon.pixmap(d->iconSize, QIcon::Normal, QIcon::Off); QPainter painter(&pixmap); painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); painter.fillRect(pixmap.rect(), QColor(0, 0, 0, 96)); drag->setPixmap(pixmap); drag->setHotSpot(QPoint(drag->pixmap().width() / 2, drag->pixmap().height() / 2)); d->disableFrame = true; update(); Qt::DropAction dropAction = drag->exec(); Q_UNUSED(dropAction); d->disableFrame = false; update(); } } }
void FlatLabel::onExecuteDrag() { if (_dragAction != Dragging) return; auto state = getTextState(_dragStartPosition); bool uponSelected = state.uponSymbol && _selection.from <= state.symbol; if (uponSelected) { if (_dragSymbol < _selection.from || _dragSymbol >= _selection.to) { uponSelected = false; } } ClickHandlerPtr pressedHandler = ClickHandler::getPressed(); QString selectedText; if (uponSelected) { selectedText = _text.originalText(_selection, ExpandLinksAll); } else if (pressedHandler) { selectedText = pressedHandler->dragText(); } if (!selectedText.isEmpty()) { auto mimeData = new QMimeData(); mimeData->setText(selectedText); auto drag = new QDrag(App::wnd()); drag->setMimeData(mimeData); drag->exec(Qt::CopyAction); // We don't receive mouseReleaseEvent when drag is finished. ClickHandler::unpressed(); } }
void CanvasMode_ObjImport::deactivate(bool forGesture) { // qDebug() << "CanvasMode_ObjImport::deactivate" << forGesture; setMimeData(NULL); setTransactionSettings(NULL); m_view->setRedrawMarkerShown(false); }
QT_BEGIN_NAMESPACE QT_USE_NAMESPACE void QClipboard::clear(Mode mode) { setMimeData(0,mode); }
void QClipboard::clear(Mode mode) { if (!supportsMode(mode)) return; qt_mac_updateScrap(mode); qt_mac_pasteboard(mode)->clear(); setMimeData(0, mode); }
/*! \fn void QClipboard::setData(QMimeSource *src, Mode mode) \compat Use setMimeData() instead. */ void QClipboard::setData(QMimeSource *source, Mode mode) { Q_D(QClipboard); if (supportsMode(mode) == false) return; d->compat_data[mode] = source; setMimeData(new QMimeSourceWrapper(d, mode)); }
void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) { auto weak = QPointer<MainWindow>(this); auto drag = std::make_unique<QDrag>(App::wnd()); drag->setMimeData(data.release()); drag->exec(Qt::CopyAction); // We don't receive mouseReleaseEvent when drag is finished. ClickHandler::unpressed(); if (weak) { weak->dragFinished().notify(); } }
HtmlDragObject::HtmlDragObject(QWidget* source, const QString className) : QDrag(source) { QByteArray byteData; { QDataStream ds(&byteData, QIODevice::WriteOnly); ds << className; } QMimeData* mimeData = new QMimeData; mimeData->setData(mimeType, byteData); mimeData->setData("text/plain", className.toLatin1().data()); setMimeData(mimeData); start(Qt::MoveAction); }
void BlockTreeWidget::mouseMoveEvent(QMouseEvent *event) { if(!(event->buttons() & Qt::LeftButton)) { QTreeWidget::mouseMoveEvent(event); return; } if((event->pos() - _dragStartPos).manhattanLength() < QApplication::startDragDistance()) { QTreeWidget::mouseMoveEvent(event); return; } //get the block data auto blockItem = dynamic_cast<BlockTreeWidgetItem *>(itemAt(_dragStartPos)); if (not blockItem->getBlockDesc()) return; //create a block object to render the image auto draw = dynamic_cast<GraphEditorTabs *>(getObjectMap()["editorTabs"])->getCurrentGraphEditor()->getCurrentGraphDraw(); std::shared_ptr<GraphBlock> renderBlock(new GraphBlock(draw)); renderBlock->setBlockDesc(blockItem->getBlockDesc()); renderBlock->prerender(); //precalculate so we can get bounds const auto bounds = renderBlock->boundingRect(); //draw the block's preview onto a mini pixmap QPixmap pixmap(bounds.size().toSize()+QSize(2,2)); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); painter.translate(-bounds.topLeft()+QPoint(1,1)); //painter.scale(zoomScale, zoomScale); //TODO get zoomscale from draw painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); renderBlock->render(painter); renderBlock.reset(); painter.end(); //create the drag object auto mimeData = new QMimeData(); std::ostringstream oss; blockItem->getBlockDesc()->stringify(oss); QByteArray byteArray(oss.str().c_str(), oss.str().size()); mimeData->setData("text/json/pothos_block", byteArray); auto drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(-bounds.topLeft().toPoint()); drag->exec(Qt::CopyAction | Qt::MoveAction); }
void SeparateTabBar::mouseMoveEvent (QMouseEvent *event) { if (isMovable ()) { QTabBar::mouseMoveEvent (event); return; } if (!(event->buttons () & Qt::LeftButton)) return; if ((event->pos () - DragStartPos_).manhattanLength () < QApplication::startDragDistance ()) return; const int dragIdx = tabAt (DragStartPos_); auto widget = TabWidget_->Widget (dragIdx); auto itw = qobject_cast<ITabWidget*> (widget); if (!itw) { qWarning () << Q_FUNC_INFO << "widget at" << dragIdx << "doesn't implement ITabWidget"; return; } auto px = QPixmap::grabWidget (widget); px = px.scaledToWidth (px.width () / 2, Qt::SmoothTransformation); auto idt = qobject_cast<IDNDTab*> (widget); auto data = new QMimeData (); if (!idt || QApplication::keyboardModifiers () == Qt::ControlModifier) { data->setData ("x-leechcraft/tab-drag-action", "reordering"); data->setData ("x-leechcraft/tab-tabclass", itw->GetTabClassInfo ().TabClass_); } else if (idt) idt->FillMimeData (data); auto drag = new QDrag (this); drag->setMimeData (data); drag->setPixmap (px); drag->exec (); }
void OSItem::mouseMoveEvent(QMouseEvent *event) { if (!m_draggable){ return; } if (!m_mouseDown){ return; } if (!(event->buttons() && Qt::LeftButton)){ return; } if ((event->pos() - m_dragStartPosition).manhattanLength() < QApplication::startDragDistance()){ return; } // start a drag m_mouseDown = false; QString mimeDataText = m_itemId.mimeDataText(); auto mimeData = new QMimeData; mimeData->setText(mimeDataText); QWidget* parent = this->parentWidget(); OS_ASSERT(parent); // parent the QDrag on this parent instead of this, in case this item is deleted during drag auto drag = new QDrag(parent); drag->setMimeData(mimeData); QPixmap _pixmap(size()); _pixmap.fill(Qt::transparent); render(&_pixmap,QPoint(),QRegion(),RenderFlags(DrawChildren)); drag->setPixmap(_pixmap); drag->setHotSpot(event->pos()); drag->exec(Qt::CopyAction); }
StringPairDrag::StringPairDrag( const QString & _key, const QString & _value, const QPixmap & _icon, QWidget * _w ) : QDrag( _w ) { if( _icon.isNull() && _w ) { setPixmap( QPixmap::grabWidget( _w ).scaled( 64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); } else { setPixmap( _icon ); } QString txt = _key + ":" + _value; QMimeData * m = new QMimeData(); m->setData( mimeType(), txt.toUtf8() ); setMimeData( m ); start( Qt::IgnoreAction ); }
void MyItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { bool isDrag = QLineF(e->screenPos(), e->buttonDownScreenPos(Qt::LeftButton)).length() >= QApplication::startDragDistance(); if (!isDrag) { return; } auto drag = new QDrag(e->widget()); auto mime = new QMimeData; drag->setMimeData(mime); mime->setColorData(color); QPixmap pix(21, 21); pix.fill(Qt::transparent); QPainter painter(&pix); paint(&painter, nullptr, nullptr); drag->setPixmap(pix); drag->setHotSpot(QPoint(10, 15)); drag->exec(); setCursor(QCursor(Qt::OpenHandCursor)); }
void mousePressEvent(QMouseEvent* event) override { if (event->button() == Qt::LeftButton) { auto as = Engine::ossia_to_iscore::ToFullAddressSettings(m_node); auto drag = new QDrag(this); auto mimeData = new QMimeData; { Mime<Device::FullAddressSettings>::Serializer s{*mimeData}; s.serialize(as); } { Mime<State::MessageList>::Serializer s{*mimeData}; s.serialize({State::Message{State::AddressAccessor{as.address}, as.value}}); } drag->setMimeData(mimeData); drag->setPixmap(grab()); drag->setHotSpot(rect().center()); drag->exec(); } }
/* void TabDropDock::mousePressEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) m_startDragPos = e->pos(); } void TabDropDock::mouseMoveEvent(QMouseEvent *e) { if (e->buttons() & Qt::LeftButton) { int distance = (e->pos() - m_startDragPos).manhattanLength(); if (distance >= QApplication::startDragDistance()) performDrag(); } } */ void TabDropDock::slotPerformDrag() { // emit(signalFloatOrDockMe(this)); auto drag = new QDrag(this); QWidget *widget = currentWidget(); if (widget) { auto mimeData = new WidgetMimeData(widget); drag->setMimeData(mimeData); if (drag->exec(Qt::MoveAction) != Qt::MoveAction) { if (widget->parent() != nullptr) { widget->setParent(nullptr); widget->setGeometry(QCursor::pos().x(),QCursor::pos().y(),width(),height()); widget->show(); widget->raise(); widget->activateWindow(); // removeTab(currentIndex()); } } } // this->repaint(); }
/*! Copies \a pixmap into the clipboard. Note that this is slower than setImage() because it needs to convert the QPixmap to a QImage first. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, the pixmap is stored in the global clipboard. If \a mode is QClipboard::Selection, the pixmap is stored in the global mouse selection. \sa pixmap() setImage() setMimeData() */ void QClipboard::setPixmap(const QPixmap &pixmap, Mode mode) { QMimeData *data = new QMimeData; data->setImageData(pixmap); setMimeData(data, mode); }
/*! Copies the \a image into the clipboard. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, the image is stored in the global clipboard. If \a mode is QClipboard::Selection, the data is stored in the global mouse selection. This is shorthand for: \code QMimeData *data = new QMimeData; data->setImageData(image); clipboard->setMimeData(data, mode); \endcode \sa image(), setPixmap() setMimeData() */ void QClipboard::setImage(const QImage &image, Mode mode) { QMimeData *data = new QMimeData; data->setImageData(image); setMimeData(data, mode); }
/*! Copies \a text into the clipboard as plain text. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, the text is stored in the global clipboard. If \a mode is QClipboard::Selection, the text is stored in the global mouse selection. If \a mode is QClipboard::FindBuffer, the text is stored in the search string buffer. \sa text(), setMimeData() */ void QClipboard::setText(const QString &text, Mode mode) { QMimeData *data = new QMimeData; data->setText(text); setMimeData(data, mode); }
/*! \fn void QClipboard::clear(Mode mode) Clear the clipboard contents. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, this function clears the global clipboard contents. If \a mode is QClipboard::Selection, this function clears the global mouse selection contents. If \a mode is QClipboard::FindBuffer, this function clears the search string buffer. \sa QClipboard::Mode, supportsSelection() */ void QClipboard::clear(Mode mode) { setMimeData(0, mode); }