コード例 #1
0
ファイル: ScreenSetupView.cpp プロジェクト: 335/synergy
// 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);
	}
}
コード例 #2
0
ファイル: bookmarkstoolbar.cpp プロジェクト: axasia/arora
void BookmarksToolBar::mouseMoveEvent(QMouseEvent *event)
{
    if (!(event->buttons() & Qt::LeftButton)) {
        QToolBar::mouseMoveEvent(event);
        return;
    }

    if ((event->pos() - m_dragStartPosition).manhattanLength()
        < QApplication::startDragDistance()) {
        QToolBar::mouseMoveEvent(event);
        return;
    }

    QAction *action = actionAt(m_dragStartPosition);
    QModelIndex index = this->index(action);
    if (!index.isValid()) {
        QToolBar::mouseMoveEvent(event);
        return;
    }

    QString title = index.data().toString();
    QUrl url = index.data(BookmarksModel::UrlRole).toUrl();

    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData();
    mimeData->setText(title);
    mimeData->setUrls(QList<QUrl>() << url);
    drag->setMimeData(mimeData);

    drag->exec(Qt::CopyAction);
}
コード例 #3
0
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();
}
コード例 #4
0
ファイル: GParamLabel.cpp プロジェクト: GaelReinaudi/LabExe
void GParamLabel::mouseMoveEvent(QMouseEvent *event)
{
    QLabel::mouseMoveEvent(event);
    Qt::KeyboardModifiers modif = event->modifiers();
    Qt::MouseButtons butts = event->buttons();
    // from qt "drag & drop" page
    if(butts != Qt::LeftButton || modif != Qt::NoModifier)
        return;
    if((event->pos() - m_DragStartPosition).manhattanLength() < QApplication::startDragDistance())
        return;
    if(!m_pParam)
        return;

    QDrag* drag = new QDrag(this);

    // extrapolation from qt help: "Using Drag and Drop with Item Views"
    QMimeData* mimeData = new QMimeData();
    QByteArray encodedData;
    // we store the UniqueSystemID() in the mime's "LabExe/parameter.single"
    QDataStream streamParamName(&encodedData, QIODevice::WriteOnly);
    QString paramUniqueID = m_pParam->UniqueSystemID();
    // lets check that it is in the Param manager so that it can be used by whoever will read this ID
    if(!GetParamFromParamManager(paramUniqueID)) {
        qDebug() << paramUniqueID << " is not in the Param Manager";
    }
    if(paramUniqueID != "") {
        streamParamName << paramUniqueID;
    }
    mimeData->setData("LabExe/parameter.single", encodedData);
    drag->setMimeData(mimeData);
    Qt::DropAction dropAction = drag->exec(Qt::CopyAction);
}
コード例 #5
0
//! [7]
void DragWidget::mouseMoveEvent(QMouseEvent *event)
{
    if (!(event->buttons() & Qt::LeftButton))
        return;
    if ((event->pos() - dragStartPosition).manhattanLength()
         < QApplication::startDragDistance())
        return;

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

    mimeData->setData(mimeType, data);
    drag->setMimeData(mimeData);

    Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
//! [7]

    switch (dropAction) {
        case Qt::CopyAction:
            emit dragResult(tr("The text was copied."));
            break;
        case Qt::MoveAction:
            emit dragResult(tr("The text was moved."));
            break;
        default:
            emit dragResult(tr("Unknown action."));
            break;
    }
//! [8]
}
コード例 #6
0
ファイル: tabbar.cpp プロジェクト: agnelterry/arora
void TabBar::mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() == Qt::LeftButton) {
#if QT_VERSION >= 0x040500
        int diffX = event->pos().x() - m_dragStartPos.x();
        int diffY = event->pos().y() - m_dragStartPos.y();
#endif
        if ((event->pos() - m_dragStartPos).manhattanLength() > QApplication::startDragDistance()
#if QT_VERSION >= 0x040500
            && diffX < 3 && diffX > -3
            && diffY < -10
#endif
            ) {
            QDrag *drag = new QDrag(this);
            QMimeData *mimeData = new QMimeData;
            QList<QUrl> urls;
            int index = tabAt(event->pos());
            QUrl url = tabData(index).toUrl();
            urls.append(url);
            mimeData->setUrls(urls);
            mimeData->setText(tabText(index));
            mimeData->setData(QLatin1String("action"), "tab-reordering");
            drag->setMimeData(mimeData);
            drag->exec();
        }
    }
    QTabBar::mouseMoveEvent(event);
}
コード例 #7
0
void Menu::mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() & Qt::LeftButton && (event->pos() - m_dragStartPosition).manhattanLength() >= QApplication::startDragDistance() && activeAction() && activeAction()->data().type() == QVariant::ULongLong)
    {
        QDrag *drag = new QDrag(this);
        QMimeData *mimeData = new QMimeData;
        QByteArray data;
        WId window = activeAction()->data().toULongLong();

        data.resize(sizeof(WId));

        memcpy(data.data(), &window, sizeof(WId));

        mimeData->setData("windowsystem/winid", data);

        drag->setMimeData(mimeData);
        drag->setPixmap(activeAction()->icon().pixmap(32, 32));

        close();

        drag->exec();
    }

    KMenu::mouseMoveEvent(event);
}
コード例 #8
0
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);
}
コード例 #9
0
ファイル: tabbar.cpp プロジェクト: mnunberg/yobot
void TabBar::mouseMoveEvent(QMouseEvent *event)
{
	if(!(event->buttons() & Qt::LeftButton))
		return;
	if((event->pos() - drag_pos).manhattanLength() < DRAG_OFFSET)
        return;
	fn_begin;
	event->accept();
    QDrag *drag = new QDrag(this);
	/*DEBUG*/
	drag->setObjectName("drag");
	connect(drag, SIGNAL(destroyed()), twutil, SLOT(dumpDestroyed()));
    QMimeData *mimedata = new QMimeData();
    QWidget *widget = currentWidget();
    mimedata->setData("action", "window_drag");
    drag->setMimeData(mimedata);

	QPixmap pixmap = QPixmap::grabWidget(widget).scaledToWidth(
			PIXMAP_MAXWIDTH(widget->width()), Qt::SmoothTransformation);
	DragPixmap *dragpixmap = new DragPixmap(pixmap, PIXMAP_OPACITY, widget);
	connect(drag, SIGNAL(destroyed()), dragpixmap, SLOT(deleteLater()));
	dragpixmap->setObjectName("dragpixmap");
	connect(dragpixmap, SIGNAL(destroyed()), twutil, SLOT(dumpDestroyed()));
    dragpixmap->show();

    drag->exec();
	emit widgetDnD(currentWidget(), drag->target());
	QTabBar::mouseMoveEvent(event);
	fn_end;
}
コード例 #10
0
void ShapeView::startDrag(Qt::DropActions supportedActions)
{
	QString key = currentItem()->data(Qt::UserRole).toString();
	if (m_Shapes.contains(key))
	{
		int w = m_Shapes[key].width;
		int h = m_Shapes[key].height;
		ScribusDoc *m_Doc = new ScribusDoc();
		m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom");
		m_Doc->setPage(w, h, 0, 0, 0, 0, 0, 0, false, false);
		m_Doc->addPage(0);
		m_Doc->setGUI(false, m_scMW, 0);
		int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset(), w, h, m_Doc->itemToolPrefs().shapeLineWidth, m_Doc->itemToolPrefs().shapeFillColor, m_Doc->itemToolPrefs().shapeLineColor, true);
		PageItem* ite = m_Doc->Items->at(z);
		ite->PoLine = m_Shapes[key].path.copy();
		FPoint wh = getMaxClipF(&ite->PoLine);
		ite->setWidthHeight(wh.x(),wh.y());
		ite->setTextFlowMode(PageItem::TextFlowDisabled);
		m_Doc->AdjustItemSize(ite);
		ite->OldB2 = ite->width();
		ite->OldH2 = ite->height();
		ite->updateClip();
		ite->ClipEdited = true;
		ite->FrameType = 3;
		m_Doc->m_Selection->addItem(ite, true);
		ScElemMimeData* md = ScriXmlDoc::WriteToMimeData(m_Doc, m_Doc->m_Selection);
		QDrag* dr = new QDrag(this);
		dr->setMimeData(md);
		dr->setPixmap(currentItem()->icon().pixmap(QSize(48, 48)));
		dr->exec();
		delete m_Doc;
	}
}
コード例 #11
0
ファイル: scripttableview.cpp プロジェクト: sakazuki/actiona
void ScriptTableView::startDrag(Qt::DropActions supportedActions)
{
	QModelIndexList indexes = selectedIndexes();
	for(int i = indexes.count() - 1 ; i >= 0; --i)
	{
		const QModelIndex &index = indexes.at(i);
		if(!(index.flags() & Qt::ItemIsDragEnabled))
			indexes.removeAt(i);
	}

	if(indexes.count() == 0)
		return;

	QMimeData *data = model()->mimeData(indexes);
	if(!data)
		return;

	QRect rect;
	QDrag *drag = new QDrag(this);
	drag->setMimeData(data);

	Qt::DropAction finalDefaultDropAction = Qt::IgnoreAction;
	if(defaultDropAction() != Qt::IgnoreAction && (supportedActions & defaultDropAction()))
		finalDefaultDropAction = defaultDropAction();
	else if(supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)
		finalDefaultDropAction = Qt::CopyAction;

	drag->exec(supportedActions, finalDefaultDropAction);
}
コード例 #12
0
ファイル: toolbutton.cpp プロジェクト: JT117/KFet
void ToolButton::mouseMoveEvent(QMouseEvent *event )
{
    if (!(event->buttons() & Qt::LeftButton))
    {
        return;
    }
    if( (event->pos() - startDragPosition).manhattanLength() < QApplication::startDragDistance() )
    {
        return;
    }

   /* gridLayout->removeWidget( this );
    gridLayout->update();
    qDebug() << "test";*/

    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData;
    mimeData->setText( "Drag and Drop" );
    mimeData->setData( "number", QString::number( numeroDansLaListe ).toUtf8() );
    drag->setMimeData( mimeData );
    drag->setPixmap( this->icon().pixmap( 64, 64 ) );
    event->accept();

    drag->exec(Qt::MoveAction);

    mainWindow->updateProduit();
}
コード例 #13
0
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);
}
コード例 #14
0
ファイル: glwidget.cpp プロジェクト: weijer/shotcut
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);
}
コード例 #15
0
void Context::mousePressEvent(QMouseEvent *e) {

	// Start dragging
	if(e->button() == Qt::LeftButton) {

		if(verbose) std::clog << "setOC: Start dragging" << std::endl;

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

		bool gotWidget = false;

		mimeData->setData("photo/menuitem","someaction");
		drag->setMimeData(mimeData);

		for(int i = 0; i < allTiles.length(); ++i) {

			ContextTile *tile = allTiles.at(i);

			// Take the tile
			if(tile->geometry().contains(e->pos()) && e->pos().x() < tile->x()+tile->dragLabel->x()+tile->dragLabel->width()) {
				drag->setPixmap(QPixmap::grabWidget(allTiles.at(i)));
				oldIndex = lay->indexOf(allTiles.at(i));
				gotWidget = true;
				break;
			}

		}
		if(gotWidget)
			drag->exec();

	}

}
コード例 #16
0
void bottom_label::mousePressEvent(QMouseEvent *event){
	if (event->button() == Qt::LeftButton) {
		QDrag* drag = new QDrag(this);

		//const QPixmap *pPixmap = pixmap();   
		//      drag->setPixmap(*pPixmap); //ÕâÀïÉèÖÃÍÏקʱ¸úËæÊó±êµÄͼƬ  
		//int w=pPixmap->size().width();
		//int h=pPixmap->size().height();
		//QPoint t;
		//t.setX(w);
		//t.setY(h);
		//      drag->setHotSpot(t); //ÉèÖøúËæͼƬµÄÖÐÐÄµã  



		QMimeData *mimeData = new QMimeData;
		QString send_mes = QString::number(id);
		send_mes += "|2";
		mimeData->setText(send_mes);
		drag->setMimeData(mimeData);
		//drag->setPixmap(iconPixmap);
		Qt::DropAction dropAction = drag->exec();
		drag->start(Qt::MoveAction);
	}
}
コード例 #17
0
void CWizDocumentListView::startDrag(Qt::DropActions supportedActions)
{
    Q_UNUSED(supportedActions);

    CWizDocumentDataArray arrayDocument;
    QList<QListWidgetItem*> items = selectedItems();
    foreach (QListWidgetItem* it, items) {
        if (CWizDocumentListViewItem* item = dynamic_cast<CWizDocumentListViewItem*>(it)) {
            arrayDocument.push_back(item->document());
        }
    }

    if (!arrayDocument.size())
        return;

    QString strMime = note2Mime(arrayDocument);

    QDrag* drag = new QDrag(this);
    QMimeData* mimeData = new QMimeData();
    mimeData->setData(WIZNOTE_MIMEFORMAT_DOCUMENTS, strMime.toUtf8());
    drag->setMimeData(mimeData);

    drag->setPixmap(WizGetDocumentDragBadget(items.size()));
    drag->exec();
}
コード例 #18
0
ファイル: peg.cpp プロジェクト: bmccorvey3/Mastermind
 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;
 }
コード例 #19
0
ファイル: siteicon.cpp プロジェクト: Fisiu/qupzilla
void SiteIcon::mouseMoveEvent(QMouseEvent* e)
{
    if (!m_locationBar || !(e->buttons() & Qt::LeftButton)) {
        ToolButton::mouseMoveEvent(e);
        return;
    }

    int manhattanLength = (e->pos() - m_dragStartPosition).manhattanLength();
    if (manhattanLength <= QApplication::startDragDistance()) {
        ToolButton::mouseMoveEvent(e);
        return;
    }

    const QUrl url = m_locationBar->webView()->url();
    const QString title = m_locationBar->webView()->title();

    if (url.isEmpty() || title.isEmpty()) {
        ToolButton::mouseMoveEvent(e);
        return;
    }

    QDrag* drag = new QDrag(this);
    QMimeData* mime = new QMimeData;
    mime->setUrls(QList<QUrl>() << url);
    mime->setText(title);
    mime->setImageData(icon().pixmap(16, 16).toImage());

    drag->setMimeData(mime);
    drag->setPixmap(QzTools::createPixmapForSite(icon(), title, url.toString()));

    drag->exec();
}
コード例 #20
0
ファイル: pagepalette.cpp プロジェクト: ivro/scribus
void SeView::mouseMoveEvent(QMouseEvent* e)
{
	if ((Mpressed) && ((Mpos - e->pos()).manhattanLength() > 4))
	{
		Mpressed = false;
		int a = rowAt(e->pos().y());
		int b = columnAt(e->pos().x());
		if ((a != -1) && (b != -1))
		{
			QTableWidgetItem* ite = item(a, b);
			if (ite != 0)
			{
				if (ite->type() == 1002)
				{
					SeItem* it = (SeItem*)ite;
					QString str(it->pageName);
					bool dummy;
					int p = GetPage(a, b, &dummy);
					QString tmp;
					QMimeData *mimeData = new QMimeData;
					mimeData->setData("page/magic", "2 "+tmp.setNum(p).toLocal8Bit()+" "+str.toLocal8Bit());
					mimeData->setText("2 "+tmp.setNum(p)+" "+str);
					QDrag *dr = new QDrag(this);
					dr->setMimeData(mimeData);
					const QPixmap& pm = loadIcon("doc.png");
					dr->setDragCursor(pm, Qt::CopyAction);
					dr->setDragCursor(pm, Qt::MoveAction);
					dr->exec(Qt::CopyAction | Qt::MoveAction);
					QApplication::setOverrideCursor(Qt::ArrowCursor);
				}
			}
		}
	}
	QTableWidget::mouseMoveEvent(e);
}
コード例 #21
0
// ドラッグアンドドロップ開始
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);
}
コード例 #22
0
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);
}
コード例 #23
0
ファイル: entitytreewidget.cpp プロジェクト: agnousse/netglub
void EntityTreeWidget::mouseMoveEvent(QMouseEvent *event)
{
  if (event->buttons() == Qt::LeftButton
      && (event->pos() - _startDragPos).manhattanLength() >= QApplication::startDragDistance())
  {
    EntityTreeWidgetItem * item = dynamic_cast<EntityTreeWidgetItem *>(currentItem());
    if (item&&!item->isDisabled())
    {

      _dragEntity = item;
      QByteArray itemData;
      QDataStream dataStream(&itemData, QIODevice::WriteOnly);
      NtgEntityModel entityModel = _entityModelHash.value(item->text(1));
      QPixmap pixmap = item->icon(0).pixmap(QSize(24,24));
      dataStream << entityModel;
      QMimeData * mimeData = new QMimeData;
      mimeData->setData("netglub/x-node-model", itemData);
      QDrag *drag = new QDrag(this);
      drag->setMimeData(mimeData);
      drag->setPixmap(pixmap);
      Qt::DropAction dropAction = drag->exec(Qt::CopyAction);
      Q_UNUSED(dropAction);
      _dragEntity = NULL;
    }
  }
}
コード例 #24
0
ファイル: draglabel.cpp プロジェクト: roahanramesh/testeqt
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();
}
コード例 #25
0
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 );
}
コード例 #26
0
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();
}
コード例 #27
0
void QtWebPageEventHandler::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
{
    QImage dragQImage;
    if (dragImage)
        dragQImage = dragImage->createQImage();
    else if (dragData.platformData() && dragData.platformData()->hasImage())
        dragQImage = qvariant_cast<QImage>(dragData.platformData()->imageData());

    DragOperation dragOperationMask = dragData.draggingSourceOperationMask();
    QMimeData* mimeData = const_cast<QMimeData*>(dragData.platformData());
    Qt::DropActions supportedDropActions = dragOperationToDropActions(dragOperationMask);

    QPoint clientPosition;
    QPoint globalPosition;
    Qt::DropAction actualDropAction = Qt::IgnoreAction;

    if (QWindow* window = m_webPage->canvas()) {
        QDrag* drag = new QDrag(window);
        drag->setPixmap(QPixmap::fromImage(dragQImage));
        drag->setMimeData(mimeData);
        actualDropAction = drag->exec(supportedDropActions);
        globalPosition = QCursor::pos();
        clientPosition = window->mapFromGlobal(globalPosition);
    }

    m_webPageProxy->dragEnded(clientPosition, globalPosition, dropActionToDragOperation(actualDropAction));
}
コード例 #28
0
void KisColorPatches::mouseMoveEvent(QMouseEvent *event)
{
    event->ignore();
    KisColorSelectorBase::mouseMoveEvent(event);
    if(event->isAccepted())
        return;

    if (!(event->buttons() & Qt::LeftButton))
        return;
    if ((event->pos() - m_dragStartPos).manhattanLength()
         < QApplication::startDragDistance())
        return;

    KoColor koColor;
    if(!colorAt(m_dragStartPos, &koColor))
        return;

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

    QColor color = koColor.toQColor();
    mimeData->setColorData(color);
    mimeData->setText(color.name());
    drag->setMimeData(mimeData);

    drag->exec(Qt::CopyAction);

    event->accept();
}
コード例 #29
0
ファイル: GridView.cpp プロジェクト: mokerjoke/tomahawk
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 );
}
コード例 #30
0
ファイル: qgscolorbutton.cpp プロジェクト: dmarteau/QGIS
void QgsColorButton::mouseMoveEvent( QMouseEvent *e )
{
  if ( mPickingColor )
  {
    setButtonBackground( sampleColor( e->globalPos() ) );
    e->accept();
    return;
  }

  //handle dragging colors from button
  QColor c = linkedProjectColor();
  if ( !c.isValid() )
    c = mColor;

  if ( !( e->buttons() & Qt::LeftButton ) || !c.isValid() )
  {
    //left button not depressed or no color set, so not a drag
    QToolButton::mouseMoveEvent( e );
    return;
  }

  if ( ( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
  {
    //mouse not moved, so not a drag
    QToolButton::mouseMoveEvent( e );
    return;
  }

  //user is dragging color
  QDrag *drag = new QDrag( this );
  drag->setMimeData( QgsSymbolLayerUtils::colorToMimeData( c ) );
  drag->setPixmap( QgsColorWidget::createDragIcon( c ) );
  drag->exec( Qt::CopyAction );
  setDown( false );
}