当前位置: 首页>>代码示例>>C++>>正文


C++ QDrag::setMimeData方法代码示例

本文整理汇总了C++中QDrag::setMimeData方法的典型用法代码示例。如果您正苦于以下问题:C++ QDrag::setMimeData方法的具体用法?C++ QDrag::setMimeData怎么用?C++ QDrag::setMimeData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDrag的用法示例。


在下文中一共展示了QDrag::setMimeData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: eventFilter

bool CanvasPicker::eventFilter(QObject *object, QEvent *e)
{
	if (object != (QObject *)plot()->canvas())
		return false;

	Graph *g = plot();
	QList<QwtPlotMarker *> lines = g->linesList();
	switch(e->type())
	{
		case QEvent::MouseButtonPress:
			{
                const QMouseEvent *me = (const QMouseEvent *)e;
				if (!(me->modifiers() & Qt::ShiftModifier))
                    g->deselect();

				emit selectPlot();

				bool allAxisDisabled = true;
				for (int i=0; i < QwtPlot::axisCnt; i++){
					if (g->axisEnabled(i)){
						allAxisDisabled = false;
						break;
					}
				}

                int dist, point;
                g->closestCurve(me->pos().x(), me->pos().y(), dist, point);

				if (me->button() == Qt::LeftButton && (g->drawLineActive())){
					startLinePoint = me->pos();
					return true;
				}

				if (!g->zoomOn() && selectMarker(me)){
					if (me->button() == Qt::RightButton)
						emit showMarkerPopupMenu();
					return true;
				}

				if (me->button() == Qt::LeftButton && !g->zoomOn() &&
					!g->hasPanningMagnifierEnabled() && !g->activeTool() && !g->selectedCurveLabels()){
					QDrag *drag = new QDrag(plot());
					QMimeData *mimeData = new QMimeData;
					QPoint p = plot()->canvas()->mapToParent(me->pos());
					mimeData->setText(QString::number(abs(plot()->x() - p.x())) + ";" +
									QString::number(abs(plot()->y() - p.y())));
					drag->setMimeData(mimeData);
					drag->setPixmap(plot()->multiLayer()->windowIcon().pixmap(16));
					drag->exec();
					return true;
				}

				return !(me->modifiers() & Qt::ShiftModifier);
			}
			break;

		case QEvent::MouseButtonDblClick:
			{
				if (d_editing_marker) {
					return d_editing_marker->eventFilter(g->canvas(), e);
				} else if (g->selectedMarker()) {
					if (lines.contains(g->selectedMarker())){
						emit viewLineDialog();
						return true;
					}
				} else if (g->isPiePlot()){
                	emit showPlotDialog(0);
                    return true;
				} else {
					const QMouseEvent *me = (const QMouseEvent *)e;
                    int dist, point;
                    QwtPlotItem *c = g->closestCurve(me->pos().x(), me->pos().y(), dist, point);
                    if (c && dist < 10)
                        emit showPlotDialog(g->curveIndex(c));
                    else
                        emit showPlotDialog(-1);
					return true;
				}
			}
			break;

		case QEvent::MouseMove:
			{
				const QMouseEvent *me = (const QMouseEvent *)e;
				if (me->state() != Qt::LeftButton)
  	            	return true;

				QPoint pos = me->pos();

				QwtPlotItem *c = g->selectedCurveLabels();
				if (c){
					if (c->rtti() == QwtPlotItem::Rtti_PlotSpectrogram)
						((Spectrogram *)c)->moveLabel(pos);
					else
						((DataCurve *)c)->moveLabels(pos);
					return true;
				}

				if (plot()->drawLineActive()) {
					drawLineMarker(pos, g->drawArrow());
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:101,代码来源:CanvasPicker.cpp

示例2: dragResource

void jsBridge::dragResource(QString hash) {

    Resource *res = Resource::fromHash(hash);
    if (res == NULL)
        return;

    QString mime = res->mimeType();
    QString fileName = res->getFileName();
    QByteArray data = res->getData();

    QPixmap pix;
    if (res->isImage()) {
        pix.loadFromData(data);
    } else if (res->isPDF()) {
        pix.load(":/img/application-pdf.png");
    } else {
        pix.load(":/img/application-octet-stream.png");
    }

    delete res;

    if (fileName.isEmpty())
        fileName = hash;

    if (mime == "application/pdf") {
        if (!fileName.endsWith(".pdf", Qt::CaseInsensitive))
            fileName += ".pdf";
    } else if (mime == "image/jpeg") {
        if (!fileName.endsWith(".jpg", Qt::CaseInsensitive) && !fileName.endsWith(".jpeg", Qt::CaseInsensitive))
            fileName += ".jpg";
    } else if (mime == "image/png") {
        if (!fileName.endsWith(".png", Qt::CaseInsensitive))
            fileName += ".png";
    } else if (mime == "image/gif") {
        if (!fileName.endsWith(".gif", Qt::CaseInsensitive))
            fileName += ".gif";
    }

    QString tmpl = QDir::tempPath() + QDir::separator() + fileName;

    QFile* f = new QFile(tmpl);

    if (!f->open(QIODevice::WriteOnly))
        return;

    f->write(data);
    f->close();
    files.enqueue(f);

    QTimer::singleShot(60000, this, SLOT(removeTmpFile()));

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

    QFileInfo fileInfo(tmpl);
    QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
    mimeData->setUrls(QList<QUrl>() << url);

    drag->setMimeData(mimeData);

    if (!pix.isNull())
        drag->setPixmap(pix.scaled(128,128, Qt::KeepAspectRatio, Qt::SmoothTransformation));

    drag->exec(Qt::CopyAction | Qt::MoveAction);
}
开发者ID:MidoriYakumo,项目名称:hippo,代码行数:65,代码来源:jsbridge.cpp

示例3: mousePressEvent

 //mouse has been clicked (creates a mouse event with position event->pos()
void MainWindow::mousePressEvent(QMouseEvent *event)
{
    LEDLabel *child = static_cast<LEDLabel*>(childAt(event->pos()));
    // What type of object have you pressed?
    QString PressedClassName = child->metaObject()->className();
    qDebug() << "type: " << PressedClassName;
    QString QLabelType = "LEDLabel";

    if (!child){
        qDebug() << "Got to !Child";
        return;}

    //Exit if you didn't click a LEDLabel Type. If you press the background
    //instead of LED Label, will clear the selected LEDs
    else if (PressedClassName != QLabelType)
    {
        if (ui->actionSelect_Mode->isChecked())
        {
        clearSelectedLEDs();
        }
        return;
    }

    for (int m = 0; m < LEDs.size(); m++)
    {
        if(LEDs.at(m) == child)
        {
           setActiveLED(m);   // Which #ID LED we pressed
        }
    }
    ui->displayText->setText(QString("Selected LED %1").arg(getActiveLED()));

    QPixmap pixmap = *child->pixmap();

    //In select mode, any label which we click on will be selected or deselected
    if (ui->actionSelect_Mode->isChecked())
    {
        selectLED(child);
    }

    // In this mode, will re-order selectedLEDs in accordance to distance.
    else if (ui->actionAssign_IDs->isChecked())

    {
        //User selects 1st LED, and the algorithm
        //finds next ones until end of selected group.
        qDebug() << "Got Here";
        if (selectedLEDs.empty() == false){
            for (int i = 0; i < selectedLEDs.size(); i++)
            {
                if (child == selectedLEDs.at(i))
                {
                    getOrderedLED(child);
                }
            }
        }
    }

    //In this mode, a drag is started. Code primarily borrowed from "Draggable
    //Icons" Qt Example:
    //http://doc.qt.io/qt-5/qtwidgets-draganddrop-draggableicons-example.html
    else if (ui->actionMove_and_Add_Mode->isChecked())

    {
        QByteArray itemData;
        QDataStream dataStream(&itemData, QIODevice::WriteOnly);
        dataStream << pixmap << QPoint(event->pos() - child->pos());

        QMimeData *mimeData = new QMimeData;
        mimeData->setData("application/x-dnditemdata", itemData);

        QDrag *drag = new QDrag(this);
        drag->setMimeData(mimeData);
        drag->setPixmap(pixmap);
        drag->setHotSpot(event->pos() - child->pos());

        child->setShade(true);


        if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) !=
                Qt::MoveAction) {
            child->show();
            child->setPixmap(pixmap);
            qDebug() << "didn't work??";

        }
    }
}
开发者ID:sonderswag,项目名称:Modular-LED-HRI-,代码行数:89,代码来源:mainwindow.cpp


注:本文中的QDrag::setMimeData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。