Ejemplo n.º 1
0
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).toImage());

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

    // Restore Down state
    setDown(false);
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
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();
	//			{}
}
Ejemplo n.º 4
0
QDrag *DndFactory::createDrag( const Incidence::Ptr &incidence, QWidget *owner )
{
  QDrag *drag = new QDrag( owner );
  drag->setMimeData( createMimeData( incidence ) );
  drag->setPixmap( BarIcon( incidence->iconName() ) );

  return drag;
}
Ejemplo n.º 5
0
static inline void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & supportedActions )
{
    QDrag *drag = new QDrag( view );
    drag->setPixmap( QPixmap( ":/noart64" ) );
    drag->setMimeData( view->model()->mimeData(
        view->selectionModel()->selectedIndexes() ) );
    drag->exec( supportedActions );
}
Ejemplo n.º 6
0
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();
}
Ejemplo n.º 7
0
void KSnapshot::slotDragSnapshot()
{
    QDrag *drag = new QDrag(this);

    drag->setMimeData(new QMimeData);
    drag->mimeData()->setImageData(snapshot);
    drag->mimeData()->setData("application/x-kde-suggestedfilename", QFileInfo(file_path_).fileName().toUtf8());
    drag->setPixmap(preview());
    drag->start();
}
Ejemplo n.º 8
0
void GenomeVectorListView::startDrag(Qt::DropActions supportedActions)
{
	QDrag* drag = new QDrag(this);
	QMimeData* mimeData = new QMimeData;
	mimeData->setData("application/x-qabstractitemmodeldatalist", QByteArray::number(dragStartIndex.row()));
	drag->setMimeData(mimeData);
	drag->setPixmap(model()->data(dragStartIndex, Qt::DecorationRole).value<QPixmap>());
	drag->exec(supportedActions);
	selectionModel()->select(qobject_cast<GenomeVector*>(model())->selectedIndex(), QItemSelectionModel::ClearAndSelect);
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
 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);

     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));
     } 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));
     }

     drag->exec();
     setCursor(Qt::OpenHandCursor);
 }
Ejemplo n.º 11
0
void MainWindow::onBtnCameraDragAndDropPressed() {
    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData;

    drag->setMimeData(mimeData);
    drag->setPixmap(QPixmap(":/assets/images/camera.png", 0, Qt::AutoColor));

    drag->setHotSpot(QPoint(5, 15));
    drag->exec(Qt::CopyAction);
}
//! [2]
void MyWidget::mousePressEvent(QMouseEvent *event)
{
//! [2]
    QString text = dataLabel->text();
    QPixmap iconPixmap(32, 32);
    iconPixmap.fill(qRgba(255, 0, 0, 127));
    QImage image(100, 100, QImage::Format_RGB32);
    image.fill(qRgb(0, 0, 255));

//! [3]
    if (event->button() == Qt::LeftButton) {

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

        mimeData->setText(text);
        mimeData->setImageData(image);
        drag->setMimeData(mimeData);
        drag->setPixmap(iconPixmap);

        Qt::DropAction dropAction = drag->exec();
//! [3]
        // ...
//! [4]
        event->accept();
    }
//! [4]
    else if (event->button() == Qt::MidButton) {

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

        mimeData->setImageData(image);
        drag->setMimeData(mimeData);
        drag->setPixmap(iconPixmap);

        Qt::DropAction dropAction = drag->exec();
        // ...
        event->accept();
    }
//! [5]
}
Ejemplo n.º 13
0
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();
        
    }
}
Ejemplo n.º 14
0
void StackFolder::activatedDragAndDrop(const KFileItem &item)
{

    QMimeData *mime = new QMimeData;
    QList<QUrl> urls;
    urls.append(item.url());
    mime->setUrls(urls);
    QDrag *drag = new QDrag(view());
    drag->setMimeData(mime);
    QString local_path = item.localPath();
    PreviewGenerator *gen = PreviewGenerator::createInstance();
    Q_ASSERT(gen != 0);

    if (gen->hasPreviewPixmap(local_path)) {
        drag->setPixmap(gen->getPreviewPixmap(item.localPath()).scaled(KIconLoader::SizeMedium, KIconLoader::SizeMedium, Qt::KeepAspectRatio));
    }
    else
        drag->setPixmap(item.pixmap(0));
    drag->exec(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction, Qt::CopyAction);
}
Ejemplo n.º 15
0
 void InlineView::startDrag(Qt::DropActions supportedActions)
 {
	QMimeData *mimeData = new QMimeData;
	QByteArray data = currentItem()->text().toLocal8Bit();
	mimeData->setData("text/inline", data);
	QDrag *drag = new QDrag(this);
	drag->setMimeData(mimeData);
	drag->setPixmap(currentItem()->icon().pixmap(48, 48));
	drag->exec(Qt::CopyAction);
	clearSelection();
}
Ejemplo n.º 16
0
/**
 * QT 4.7.1 拖拽的函数默认调用过程:
 *
 * Model.supportedDropActions()
 *
 * View.startDrag()
 *     Model.mimeData() // 获取拖拽数据
 *     Model.supportedDragActions()
 *         Model.supportedDropActions()
 *     QDrag.exec() // 阻塞,直到拖拽结束
 *
 *         // 在拖拽过程中,如果拖拽进入某个节点
 *         View.dragEnterEvent() // 默认实现会拒绝拖拽,需要重写并调用 QDragEnterEvent.acceptProposedAction()
 *             Model.mimeTypes()
 *         View.dragMoveEvent()
 *             Model.mimeTypes()
 *         View.dragLeaveEvent()
 *
 *         // 拖拽结束后
 *         View.dropEvent()
 *             Model.dropMimeData() // QT用来接收数据
 *
 *     // exec()执行完后,如果是 MoveAction,则调用
 *     Model.removeSelectedRows() // QT用来删除数据
 *
 * 上述默认过程对跨 View 拖放支持不好, 下面的startDrag()函数摘自默认实现,并
 * 将部分代码替换掉以免调用removeSelectedRows()函数
 */
void DirectoryTree::startDrag(Qt::DropActions)
{
    const QModelIndexList indexes = selectedIndexes();
    if (indexes.count() == 0)
        return;

    // setup pixmap
    QRect rect = visualRect(indexes.at(0));
    QList<QRect> rects;
    for (size_t i = 0, s = indexes.count(); i < s; ++i)
    {
        rects.append(visualRect(indexes.at(i)));
        rect |= rects.at(i);
    }
    rect = rect.intersected(viewport()->rect());
    QPixmap pixmap(rect.size());
    pixmap.fill(palette().base().color());
    QPainter painter(&pixmap);
    QStyleOptionViewItem option = viewOptions();
    option.state |= QStyle::State_Selected;
    for (size_t j = 0, s = indexes.count(); j < s; ++j)
    {
        option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(),
        rects.at(j).size());
        itemDelegate()->paint(&painter, option, indexes.at(j));
    }
    painter.end();

    // create drag object
    QDrag *drag = new QDrag(this);
    drag->setPixmap(pixmap);
    drag->setMimeData(model()->mimeData(indexes));
    drag->setHotSpot(viewport()->mapFromGlobal(QCursor::pos()) - rect.topLeft());

    /**
     * 在拖动之前,先把 parent 和  row 保存下来,
     * 在 Model.dropMimeData() 中统一进行底层数据和视图层数据的修改,
     * 避免索引混乱
     */
    DirectoryTreeModel *m = (DirectoryTreeModel*) model();
    QModelIndex parent = indexes.at(0).parent();
    int row = indexes.at(0).row();
    m->prepare_draging_drop(parent, row);

    /*
     * 这里的原来的实现 removeSelectedRows() 是我们不需要的, 且 QDrag->start() 总是允许 Qt::CopyAction
     * 而我们需要的是,内部用 Qt::MoveAction,外部用 Qt::CopyAction且内部不支持 Qt::CopyAction且内部不支持
     * Qt::CopyAction,否则导致错误
     *
    if (drag->start(supportedActions) == Qt::MoveAction)
        removeSelectedRows();
    */
    drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction);
}
Ejemplo n.º 17
0
void CSVWorld::DragRecordTable::startDragFromTable (const CSVWorld::DragRecordTable& table)
{
    CSMWorld::TableMimeData* mime = new CSMWorld::TableMimeData (table.getDraggedRecords(), mDocument);

    if (mime)
    {
        QDrag* drag = new QDrag (this);
        drag->setMimeData (mime);
        drag->setPixmap (QString::fromUtf8 (mime->getIcon().c_str()));
        drag->exec (Qt::CopyAction);
    }
}
Ejemplo n.º 18
0
void CCardLabel::mouseMoveEvent(QMouseEvent *ev)
{
    if (mLockButton)
    {
        mLockButton->setVisible(mLockButton->isChecked()
            || (mCard.isValid() && mLockButton->geometry().contains(ev->pos())));
    }
    if (mLastLeftClickPos && mCard.isValid())
    {
        QLineF moveLine(ev->globalPos(), *mLastLeftClickPos);
        if (moveLine.length() >= QApplication::startDragDistance())
        {
            QDrag *drag = new QDrag(this);
            QMimeData *dragData = createCardLabelDropData(*this);
            drag->setMimeData(dragData);
            drag->setHotSpot(ev->pos());

            const QPixmap *unitImg = pixmap();
            if (unitImg)
            {
                int w = unitImg->width() / 2;
                int h = unitImg->height() / 2;
                QPixmap dragImg(w, h);
                dragImg.fill(Qt::transparent);
                QPainter painter(&dragImg);
                painter.setOpacity(0.75);
                painter.drawPixmap(0, 0, w, h, unitImg->scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation));
                painter.end();
                drag->setPixmap(dragImg);
            }

            if (QApplication::keyboardModifiers() == Qt::ControlModifier || !acceptDrops())
            {     
                drag->exec(Qt::CopyAction);
            }
            else
            {
                CCard cardBuf = mCard;
                bool lockBuf = isLocked();
                setCard(CCard::INVALID_CARD);
                setLocked(false);
                if (!drag->exec(Qt::MoveAction))
                {
                    setCard(cardBuf);
                    setLocked(lockBuf);
                }
            }
            delete mLastLeftClickPos;
            mLastLeftClickPos = 0;
            emit unitDragged();
        }
    }
}
Ejemplo n.º 19
0
void TeamPokeButton::startDrag()
{
    QMimeData * data = new QMimeData();
    data->setText(this->text());
    data->setImageData(*pokeIcon->pixmap());
    QDrag * drag = new QDrag(this);
    drag->setMimeData(data);
    drag->setPixmap(*pokeIcon->pixmap());
    drag->exec(Qt::MoveAction);

    emit clicked();
}
Ejemplo n.º 20
0
void paramBtn::createInputLeaveDrag(QMouseEvent *event ){
	qDebug( "  paramBtn::createInputLeaveDrag()\n");
	emit tellviewdeleteline(this->moduleid,this->paramId,connectedoutputmoduleid,connectedoutputparamid);
	QDrag *drag = new QDrag(this);
	//drag->setDragCursor(QPixmap("image/ports/01.png"),Qt::MoveAction);
	drag->setHotSpot(QPoint(event->pos() - rect().topLeft()));  
   switch (connectedoutputshape)//端口的类型10种情况
		{
		case 5:
			drag->setPixmap(QPixmap(":/image/ports/01.png"));
			break;
		case 6:
			drag->setPixmap(QPixmap(":/image/ports/02.png"));
			break;
		case 7:
			drag->setPixmap(QPixmap(":/image/ports/03.png"));
			break;
		case 8:
			drag->setPixmap(QPixmap(":/image/ports/04.png"));
			break;
		case 10:
			drag->setPixmap(QPixmap(":/image/ports/09.png"));
			break;
	
		}

	QMimeData *mime = new QMimeData;
	QString send_Msg = QString::number(connectedoutputmoduleid);
	send_Msg += "|4|";//添加标志位,用于表示此时需要画线操作
	QString pid = QString::number(connectedoutputparamid);
	send_Msg += pid;
	send_Msg +="|";
	send_Msg +=QString::number(connectedoutputshape);
	qDebug()<<send_Msg;
	mime->setText(send_Msg);
	drag->setMimeData(mime);

	drag->start(Qt::MoveAction);

}
Ejemplo n.º 21
0
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();
    delete drag;
}
Ejemplo n.º 22
0
void AppListView::startDrag(const QModelIndex &index)
{
    if (!index.isValid())
        return;

    AppsListModel *listModel = qobject_cast<AppsListModel *>(model());
    if (!listModel)
        return;

    const QModelIndex &dragIndex = index;
    const QString appKey = index.data(AppsListModel::AppKeyRole).toString();
    const QPixmap pixmap = index.data(AppsListModel::AppIconRole).value<QPixmap>();

    QDrag *drag = new QDrag(this);
    drag->setMimeData(model()->mimeData(QModelIndexList() << dragIndex));
    drag->setPixmap(pixmap.scaled(DLauncher::APP_DRAG_ICON_SIZE, DLauncher::APP_DRAG_ICON_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
    drag->setHotSpot(QPoint(DLauncher::APP_DRAG_ICON_SIZE, DLauncher::APP_DRAG_ICON_SIZE) / 2);

    // request remove current item.
    if (listModel->category() == AppsListModel::All)
    {
        m_dropToPos = index.row();
        listModel->setDragingIndex(index);
    }

    drag->exec(Qt::MoveAction);

    // disable animation when finally dropped
    m_dropThresholdTimer->stop();

    // disable auto scroll
    emit requestScrollStop();

    if (listModel->category() != AppsListModel::All)
        return;

    if (!m_lastFakeAni)
    {
        if (m_enableDropInside)
            listModel->dropSwap(m_dropToPos);
        else
            listModel->dropSwap(indexAt(m_dragStartPos).row());

        listModel->clearDragingIndex();
    }
    else
    {
        connect(m_lastFakeAni, &QPropertyAnimation::finished, listModel, &AppsListModel::clearDragingIndex);
    }

    m_enableDropInside = false;
}
Ejemplo n.º 23
0
// ************************************************************
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();

}
Ejemplo n.º 24
0
//![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);
}
Ejemplo n.º 25
0
	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
	}
Ejemplo n.º 26
0
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);
}
Ejemplo n.º 27
0
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);
}
Ejemplo n.º 28
0
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 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;
    }
}
Ejemplo n.º 30
0
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);
}