Beispiel #1
0
void GraphBase::UpdateViewPort()
{
    QGraphicsView view = this->views()[0];
    QRect viewPort = view.viewport()->rect();
    QPoint r1, r2;
    r1 = viewPort.topLeft();
    r2 = viewPort.bottomRight();

    update(QRectF(view.mapToScene(r1), view.mapToScene(r2)));
}
QRectF ArrangementGraphicsItemBase::getViewportRect( ) const
{
  QRectF clipRect;
  if ( this->scene == NULL || this->scene->views( ).size( ) == 0 )
  {
    return clipRect;
  }

  QGraphicsView* view = this->scene->views( ).first( );
  QPointF p1 = view->mapToScene( 0, 0 );
  QPointF p2 = view->mapToScene( view->width( ), view->height( ) );
  clipRect = QRectF( p1, p2 );

  return clipRect;
}
void UBWidgetUniboardAPI::onDownloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData)
{
    //if widget recieves is waiting for this id then process
    if (!takeIDWidget(desc.id))
        return;

    if (!pSuccess) {
        qDebug() << "can't download the whole data. An error occured";
        return;
    }

    QString contentType = desc.contentTypeHeader;
    QString extention = UBFileSystemUtils::fileExtensionFromMimeType(contentType);

    if (!supportedTypeHeader(contentType)) {
        qDebug() << "actions for mime type" << contentType << "are not supported";
        return;
    }

    QString objDir = getObjDir();
    if (!QDir().exists(objDir)) {
        if (!QDir().mkpath(objDir)) {
            qDebug() << "can't create objects directory path. Check the permissions";
            return;
        }
    }

    QString destFileName = objDir + QUuid::createUuid() + "." + extention;
    QFile destFile(destFileName);

    if (!destFile.open(QIODevice::WriteOnly)) {
        qDebug() << "can't open" << destFileName << "for wrighting";
        return;
    }

    if (destFile.write(pData) == -1) {
        qDebug() << "can't implement data writing";
        return;
    }

    QGraphicsView *tmpView = mGraphicsWidget->scene()->views().at(0);
    QPoint dropPoint(mGraphicsWidget->mapFromScene(tmpView->mapToScene(desc.dropPoint)).toPoint());

    QMimeData dropMimeData;
    QString mimeText = createMimeText(true, contentType, destFileName);
    dropMimeData.setData(tMimeText, mimeText.toAscii());

    destFile.close();

    //To make js interpreter accept drop event we need to generate move event first.
    QDragMoveEvent pseudoMove(dropPoint, desc.dropActions, &dropMimeData, desc.dropMouseButtons, desc.dropModifiers);
    QApplication::sendEvent(mGraphicsWidget,&pseudoMove);

    QDropEvent readyEvent(dropPoint, desc.dropActions, &dropMimeData, desc.dropMouseButtons, desc.dropModifiers);
    //sending event to destination either it had been downloaded or not
    QApplication::sendEvent(mGraphicsWidget,&readyEvent);
    readyEvent.acceptProposedAction();
}
Beispiel #4
0
void RulerItem2::recalculate()
{
	char buffer[500];
	QPointF tmp;
	QFont font;
	QFontMetrics fm(font);

	if (timeAxis == NULL || depthAxis == NULL || pInfo.nr == 0)
		return;

	prepareGeometryChange();
	startPoint = mapFromItem(source, 0, 0);
	endPoint = mapFromItem(dest, 0, 0);

	if (startPoint.x() > endPoint.x()) {
		tmp = endPoint;
		endPoint = startPoint;
		startPoint = tmp;
	}
	QLineF line(startPoint, endPoint);
	setLine(line);
	compare_samples(source->entry, dest->entry, buffer, 500, 1);
	text = QString(buffer);

	// draw text
	QGraphicsView *view = scene()->views().first();
	QPoint begin = view->mapFromScene(mapToScene(startPoint));
	textItem->setText(text);
	qreal tgtX = startPoint.x();
	const qreal diff = begin.x() + textItem->boundingRect().width();
	// clamp so that the text doesn't go out of the screen to the right
	if (diff > view->width()) {
		begin.setX(begin.x() - (diff - view->width()));
		tgtX = mapFromScene(view->mapToScene(begin)).x();
	}
	// always show the text bellow the lowest of the start and end points
	qreal tgtY = (startPoint.y() >= endPoint.y()) ? startPoint.y() : endPoint.y();
	textItem->setPos(tgtX - 1, tgtY + 4);

	// setup the text background
	textItemBack->setVisible(startPoint.x() != endPoint.x());
	QPointF wh = mapFromScene(view->mapToScene(QPoint(textItem->boundingRect().width(),
		textItem->boundingRect().height())));
	textItemBack->setRect(tgtX - 2, tgtY + 3, wh.x() + 2, wh.y() + 3);
}
Beispiel #5
0
/*!
    Returns the scene-local coordinates if the \a gesturePoint is inside a
    graphics view.

    This functional might be useful when the gesture event is delivered to a
    QGraphicsObject to translate a point in screen coordinates to scene-local
    coordinates.

    \sa QPointF::isNull()
*/
QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const
{
    QWidget *w = widget();
    if (w) // we get the viewport as widget, not the graphics view
        w = w->parentWidget();
    QGraphicsView *view = qobject_cast<QGraphicsView*>(w);
    if (view) {
        return view->mapToScene(view->mapFromGlobal(gesturePoint.toPoint()));
    }
    return QPointF();
}
void VerticalRayGraphicsItem::drawArrowhead( QPainter* painter,
                                             double targetY, bool isShootingUp )
{
  if ( this->scene( ) == 0 || this->scene( )->views( ).size( ) == 0 )
  {
    return;
  }
  QGraphicsView* view = this->scene( )->views( ).first( );
  QPointF arrowTip( this->m_source.x( ), targetY );
  QPoint pt = view->mapFromScene( arrowTip );
  if ( ! isShootingUp && this->m_isInfinite )
  {
    if (view->horizontalScrollBar( ) &&
        view->horizontalScrollBar( )->isVisible( ) )
    {
      // std::cout << view->horizontalScrollBar( )->height( ) << std::endl;
      pt.setY( pt.y( ) - view->horizontalScrollBar( )->height( ) - 5 );
      arrowTip = view->mapToScene( pt );
    }
    else
    {
      // std::cout << "no scroll bar " << std::endl;
      pt.setY( pt.y( ) - 5 );
      arrowTip = view->mapToScene( pt );
    }
  }

  int dy = -1;
  if ( isShootingUp )
  {
    dy = 1;
  }
  QPoint leftPt( pt.x( ) - 3, pt.y( ) + 3*dy );
  QPoint rightPt( pt.x( ) + 3, pt.y( ) + 3*dy );
  QPointF left = view->mapToScene( leftPt );
  QPointF right = view->mapToScene( rightPt );
  QLineF leftEdge( left, arrowTip );
  QLineF rightEdge( arrowTip, right );
  painter->drawLine( leftEdge );
  painter->drawLine( rightEdge );
}
QRectF GraphicsViewSegmentInputBase::viewportRect( ) const
{
  QRectF res;
  if ( this->scene == NULL )
  {
    return res;
  }

  QList< QGraphicsView* > views = this->scene->views( );
  if ( views.size( ) == 0 )
  {
    return res;
  }
  // assumes the first view is the right one
  QGraphicsView* viewport = views.first( );
  QPointF p1 = viewport->mapToScene( 0, 0 );
  QPointF p2 = viewport->mapToScene( viewport->width( ), viewport->height( ) );
  res = QRectF( p1, p2 );

  return res;
}
Beispiel #8
0
//Maps screen coordinates to scrollArea coordinates though current m_eventViewport widget 
QPointF ScrollerPrivate::mapToScrollArea(const QPoint &point)
{
    if (!m_scrollArea || !m_eventViewport)
        return point;

    QObject *vparent = m_eventViewport->parent();
    if (!vparent)
        return point;

    QGraphicsView *view = qobject_cast<QGraphicsView*>(vparent);
    if (!view)
        return point;

    QPoint pt = view->mapFromGlobal(point);
    return m_scrollArea->mapFromScene(view->mapToScene(pt));
}
Beispiel #9
0
QPoint Utils::getPopupPoint(QGraphicsScene *scene, QWidget *hostedWidget, QToolButton *button, QWidget *widget)
{
    qreal                   x, y;
    QRectF                  sc, r0;
    QRect                   menuRect, buttonRect;
    QPoint                  p;
    CDiagram                *diagram = NULL;
    QGraphicsView           *v = NULL;
    QWidget                 *parent = NULL;
    CDiagramHostedWidget    *hosted = NULL;
    QGraphicsItem           *item = NULL;

    diagram = dynamic_cast<CDiagram*>(scene);
    hosted = dynamic_cast<CDiagramHostedWidget*>( hostedWidget );
    parent = button->parentWidget();
    if (!diagram || !widget || !parent || !hosted)
        return QPoint();

    v = diagram->getMainView();
    if (!v)
        return QPoint();

    item = hosted->diagramWidget();
    menuRect = widget->geometry();
    buttonRect = button->geometry();
    p = parent->mapTo(hostedWidget, button->pos());
    sc = v->mapToScene(v->viewport()->geometry()).boundingRect();
    r0 = item->mapToScene( item->boundingRect() ).boundingRect();
    r0 = QRectF(r0.topLeft() + QPointF(p.x(), p.y()), QSizeF(buttonRect.width(), buttonRect.height()));

    // determine x
    if (sc.right() - menuRect.width() > r0.left())
        x = r0.left();
    else
        x = sc.right() - menuRect.width();

    // determine y
    if (sc.bottom() - menuRect.height() > r0.bottom() )
        y = r0.bottom();
    else
        y = sc.bottom() - menuRect.height();

    return v->mapToGlobal( v->mapFromScene( QPointF(x, y) ) );
}
Beispiel #10
0
void SCgInsertMode::activate()
{
    if (mInsertedObjectGroup)
    {
        delete mInsertedObjectGroup;
        mInsertedObjectGroup = 0;
    }

    const QMimeData* data = QApplication::clipboard()->mimeData();
    if (data->hasFormat(SCgWindow::SupportedPasteMimeType))
    {
        QDomDocument document;

        if (!document.setContent(data->data(SCgWindow::SupportedPasteMimeType)))
            return;

        // Read document
        GwfObjectInfoReader reader;
        if (!reader.read(document))
            return;

        //Place objects to scene
        TemplateSCgObjectsBuilder objectBuilder(mScene);
        objectBuilder.buildObjects(reader.objectsInfo());

        QList<SCgObject*> list = objectBuilder.objects();
        QList<QGraphicsItem*> withoutChilds;
        foreach(SCgObject* obj, list)
        {
            if (!obj->parentItem())
                withoutChilds.append(obj);
        }

        if(!withoutChilds.empty())
        {
            mInsertedObjectGroup = mScene->createItemGroup(withoutChilds);

            QGraphicsView* v = mScene->views().at(0);
            QPointF p = v->mapToScene(v->mapFromGlobal(QCursor::pos()));
            mInsertedObjectGroup->setPos(p);
            mInsertedObjectGroup->setOpacity(0.5);
        }
    }
void UBWidgetUniboardAPI::ProcessDropEvent(QGraphicsSceneDragDropEvent *event)
{
    const QMimeData *pMimeData = event->mimeData();

    QString destFileName;
    QString contentType;
    bool downloaded = false;

    QGraphicsView *tmpView = mGraphicsWidget->scene()->views().at(0);
    QPoint dropPoint(mGraphicsWidget->mapFromScene(tmpView->mapToScene(event->pos().toPoint())).toPoint());
    Qt::DropActions dropActions = event->possibleActions();
    Qt::MouseButtons dropMouseButtons = event->buttons();
    Qt::KeyboardModifiers dropModifiers = event->modifiers();
    QMimeData *dropMimeData = new QMimeData;
    qDebug() << event->possibleActions();


    if (pMimeData->hasHtml()) { //Dropping element from web browser
        QString qsHtml = pMimeData->html();
        QString url = UBApplication::urlFromHtml(qsHtml);

        if(!url.isEmpty()) {
            QString str = "test string";

            QMimeData mimeData;
            mimeData.setData(tMimeText, str.toAscii());

            sDownloadFileDesc desc;
            desc.dest = sDownloadFileDesc::graphicsWidget;
            desc.modal = true;
            desc.srcUrl = url;
            desc.currentSize = 0;
            desc.name = QFileInfo(url).fileName();
            desc.totalSize = 0; // The total size will be retrieved during the download

            desc.dropPoint = event->pos().toPoint(); //Passing pure event point. No modifications
            desc.dropActions = dropActions;
            desc.dropMouseButtons = dropMouseButtons;
            desc.dropModifiers = dropModifiers;

            registerIDWidget(UBDownloadManager::downloadManager()->addFileToDownload(desc));

        }

    } else  if (pMimeData->hasUrls()) { //Local file processing
        QUrl curUrl = pMimeData->urls().first();
        QString sUrl = curUrl.toString();

        if (sUrl.startsWith("file://") || sUrl.startsWith("/")) {
            QString fileName = curUrl.toLocalFile();
            QString extention = UBFileSystemUtils::extension(fileName);
            contentType = UBFileSystemUtils::mimeTypeFromFileName(fileName);

            if (supportedTypeHeader(contentType)) {
                destFileName = getObjDir() + QUuid::createUuid().toString() + "." + extention;

                if (!UBFileSystemUtils::copyFile(fileName, destFileName)) {
                    qDebug() << "can't copy from" << fileName << "to" << destFileName;
                    return;
                }
                downloaded = true;

            }
        }
    }

    QString mimeText = createMimeText(downloaded, contentType, destFileName);

    // Ev-5.1 - CFA - 20140109 : correction drop RTE
    UBFeaturesController* c = UBApplication::boardController->paletteManager()->featuresWidget()->getFeaturesController();
    if (c->getFeatureByFullPath(mGraphicsWidget->sourceUrl().toLocalFile()).getType() != FEATURE_RTE)
        dropMimeData->setData(tMimeText, mimeText.toAscii());

    if (mGraphicsWidget->page() && mGraphicsWidget->page()->mainFrame()) {
        mGraphicsWidget
            ->page()
            ->mainFrame()
            ->evaluateJavaScript("if(widget && widget.ondrop) { widget.ondrop('" + destFileName + "', '" + contentType + "');}");
    }

    event->setMimeData(dropMimeData);
}
Beispiel #12
0
void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event)
{
    const QMimeData *pMimeData = event->mimeData();

    QString destFileName;
    QString contentType;
    bool downloaded = false;

    QGraphicsView *tmpView = mGraphicsWidget->scene()->views().at(0);
    QPoint dropPoint(mGraphicsWidget->mapFromScene(tmpView->mapToScene(event->pos())).toPoint());
    Qt::DropActions dropActions = event->dropAction();
    Qt::MouseButtons dropMouseButtons = event->mouseButtons();
    Qt::KeyboardModifiers dropModifiers = event->keyboardModifiers();
    QMimeData dropMimeData;


    if (pMimeData->hasHtml()) { //Dropping element from web browser
        QString qsHtml = pMimeData->html();
        QString url = UBApplication::urlFromHtml(qsHtml);

        if(!url.isEmpty()) {
            QString str = "test string";

            QMimeData mimeData;
            mimeData.setData(tMimeText, str.toAscii());

            sDownloadFileDesc desc;
            desc.dest = sDownloadFileDesc::graphicsWidget;
            desc.modal = true;
            desc.url = url;
            desc.currentSize = 0;
            desc.name = QFileInfo(url).fileName();
            desc.totalSize = 0; // The total size will be retrieved during the download

            desc.dropPoint = event->pos(); //Passing pure event point. No modifications
            desc.dropActions = dropActions;
            desc.dropMouseButtons = dropMouseButtons;
            desc.dropModifiers = dropModifiers;

            registerIDWidget(UBDownloadManager::downloadManager()->addFileToDownload(desc));

        }

    } else  if (pMimeData->hasUrls()) { //Local file processing
        QUrl curUrl = pMimeData->urls().first();
        QString sUrl = curUrl.toString();

        if (sUrl.startsWith("file://") || sUrl.startsWith("/")) {
            QString fileName = curUrl.toLocalFile();
            QString extention = UBFileSystemUtils::extension(fileName);
            contentType = UBFileSystemUtils::mimeTypeFromFileName(fileName);

            if (supportedTypeHeader(contentType)) {
                destFileName = getObjDir() + QUuid::createUuid().toString() + "." + extention;

                if (!UBFileSystemUtils::copyFile(fileName, destFileName)) {
                    qDebug() << "can't copy from" << fileName << "to" << destFileName;
                    return;
                }
                downloaded = true;

            }
        }
    }
    qDebug() << destFileName;
    QString mimeText = createMimeText(downloaded, contentType, destFileName);
    dropMimeData.setData(tMimeText, mimeText.toAscii());

    QDropEvent readyEvent(dropPoint, dropActions, &dropMimeData, dropMouseButtons, dropModifiers);
    //sending event to destination either it had been downloaded or not
    QApplication::sendEvent(mGraphicsWidget->widgetWebView(),&readyEvent);
    readyEvent.acceptProposedAction();
}
Beispiel #13
0
void Guideline::rangeOfAttachedObjects(double& min, double& max) const
{
    min = DBL_MAX;
    max = -DBL_MAX;

    for (RelsList::const_iterator curr = relationships.begin(); curr != relationships.end(); ++curr)
    {
        QRectF itemRect;
        if ((*curr)->shape)
        {
            itemRect = (*curr)->shape->boundingRect();
            itemRect.moveCenter((*curr)->shape->pos());
        }
        else if ((*curr)->distro)
        {
            itemRect = (*curr)->distro->boundingRect();
            itemRect.moveCenter((*curr)->distro->pos());
        }
        else if ((*curr)->separation)
        {
            itemRect = (*curr)->separation->boundingRect();
            itemRect.moveCenter((*curr)->separation->pos());
        }

        if (itemRect.isValid())
        {
            if (get_dir() == GUIDE_TYPE_HORI)
            {
                min = qMin(min, itemRect.left());
                max = qMax(max, itemRect.right());
            }
            else
            {
                min = qMin(min, itemRect.top());
                max = qMax(max, itemRect.bottom());
            }
        }
    }

    // Cope with the case where there are no attached objects.
    if ((min == DBL_MAX) && (max = -DBL_MAX) && canvas())
    {
        QList<QGraphicsView *> views = canvas()->views();
        QRectF sceneBounds;

        // Determine bounds by taking the union of all view bounds.
        for (int v = 0; v < views.size(); ++v)
        {
            QGraphicsView *view = views.at(v);

            sceneBounds = sceneBounds.united(QRectF(view->mapToScene(0,0),
                    view->mapToScene(view->width(), view->height())));
        }

        if (get_dir() == GUIDE_TYPE_HORI)
        {
            min = sceneBounds.left();
            max = sceneBounds.right();
        }
        else
        {
            min = sceneBounds.top();
            max = sceneBounds.bottom();
        }
    }
}