Beispiel #1
0
void CaptionGraphicsItem::selectPropertyButtonClicked() {
  if (_view->graph() == nullptr)
    return;

  QMenu menu;
  for (const string &piName : _view->graph()->getProperties()) {
    if (_view->graph()->getProperty(piName)->getTypename() != "double")
      continue;

    QAction *action = menu.addAction(piName.c_str(), this, SLOT(propertySelectedSlot()));

    if (_confPropertySelectionWidget->text() == QString(piName.c_str()))
      menu.setActiveAction(action);
  }
  // set a combo like stylesheet
  QPalette palette = QComboBox().palette();
  menu.setStyleSheet(QString("QMenu::item {color: %1; background-color: %2;} QMenu::item:selected "
                             "{color: %3; background-color: %4}")
                         .arg(palette.color(QPalette::Active, QPalette::Text).name())
                         .arg(palette.color(QPalette::Active, QPalette::Base).name())
                         .arg(palette.color(QPalette::Active, QPalette::HighlightedText).name())
                         .arg(palette.color(QPalette::Active, QPalette::Highlight).name()));

  // compute a combo like position
  // to popup the menu
  QWidget *pViewport = QApplication::widgetAt(QCursor::pos());
  QWidget *pView = pViewport->parentWidget();
  QGraphicsView *pGraphicsView = qobject_cast<QGraphicsView *>(pView);
  QPoint popupPos =
      pGraphicsView->mapToGlobal(pGraphicsView->mapFromScene(_confPropertySelectionItem->mapToScene(
          _confPropertySelectionItem->subWidgetRect(_confPropertySelectionWidget).bottomLeft())));

  menu.exec(popupPos);
}
Beispiel #2
0
QRectF KWidget::rectToScreen() const
{
    QRectF rt = rect();
    QGraphicsView *gview = view();

    QPointF pt = mapToScene(rt.topLeft());
    QPoint vpt = gview->mapFromScene(pt);
    QPoint gpt = gview->mapToGlobal(vpt);
    rt.moveTo(gpt);
    return rt;
}
Beispiel #3
0
/// \bug Due to not being able to restrict the mouse cursor to the window client are in any cross-platform means,
/// it is possible that if the screen is resized to very small and if the mouse is moved very fast, the cursor
/// escapes the window client area and will not get recentered.
void QtInputService::RecenterMouse()
{
    QGraphicsView *view = framework->GetUIView();
    QPoint centeredCursorPosLocal = QPoint(view->size().width()/2, view->size().height()/2);

    lastMouseX = centeredCursorPosLocal.x();
    lastMouseY = centeredCursorPosLocal.y();
    // This call might trigger an immediate mouse move message to the window, so set the mouse coordinates above.
    QPoint centeredCursorPosGlobal = view->mapToGlobal(centeredCursorPosLocal);
    if (centeredCursorPosGlobal == QCursor::pos())
        return; // If the mouse cursor already is at the center, don't do anything.
    QCursor::setPos(centeredCursorPosGlobal);

    // Double-check that the mouse cursor did end up where we wanted it to go.
    QPoint mousePos = view->mapFromGlobal(QCursor::pos());
    lastMouseX = mousePos.x();
    lastMouseY = mousePos.y();
}
Beispiel #4
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) ) );
}
void MultiTouchListener::handleEvent( TUIO::TuioCursor* tcur,
                                      const QEvent::Type eventType )
{
    QGraphicsView* view = _graphicsViewProxy->getGraphicsView();
    if( !view )
        return;

    const QPoint& viewPos = view->mapToGlobal( view->pos());
    const QRectF& sceneRect = view->sceneRect();
    const int viewWidth = view->geometry().width();
    const int viewHeight = view->geometry().height();

    const qreal w = viewWidth / sceneRect.width();
    const qreal h = viewHeight / sceneRect.height();
    const int x = qreal(viewWidth - w) * .5;
    const int y = qreal(viewHeight - h) * .5;
    const QPoint sceneOffset( x, y );

    const QPointF normPos( tcur->getX(), tcur->getY( ));
    const QPoint pos( w * normPos.x(), h * normPos.y( ));
    const QPoint screenPos( viewPos + sceneOffset + pos );

    const QPoint wallPos( g_configuration->getTotalWidth() * tcur->getX(),
                          g_configuration->getTotalHeight() * tcur->getY( ));

    QTouchEvent::TouchPoint touchPoint( tcur->getCursorID( ));
    touchPoint.setPressure( 1.0 );
    touchPoint.setNormalizedPos( normPos );
    touchPoint.setPos( wallPos ); // need for pan gesture recognition
    touchPoint.setScenePos( normPos );
    touchPoint.setScreenPos( screenPos ); // need for hotspot & itemAt

    Qt::TouchPointStates touchPointStates = 0;
    if( tcur->getCursorID() == 0 )
        touchPointStates |= Qt::TouchPointPrimary;

    switch( eventType )
    {
    case QEvent::TouchBegin:
        touchPointStates = Qt::TouchPointPressed;

        touchPoint.setStartNormalizedPos( normPos );
        touchPoint.setStartPos( touchPoint.pos( ));
        touchPoint.setStartScreenPos( screenPos );
        touchPoint.setStartScenePos( touchPoint.scenePos( ));

        touchPoint.setLastNormalizedPos( normPos );
        touchPoint.setLastPos( touchPoint.pos( ));
        touchPoint.setLastScreenPos( screenPos );
        touchPoint.setLastScenePos( touchPoint.scenePos( ));
        break;

    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        if( eventType == QEvent::TouchUpdate )
            touchPointStates = tcur->isMoving() ? Qt::TouchPointMoved
                                                : Qt::TouchPointStationary;
        else
            touchPointStates = Qt::TouchPointReleased;

        const QTouchEvent::TouchPoint& prevPoint = _touchPointMap.value( tcur->getCursorID( ));
        touchPoint.setStartNormalizedPos( prevPoint.startNormalizedPos( ));
        touchPoint.setStartPos( prevPoint.startPos( ));
        touchPoint.setStartScreenPos( prevPoint.startScreenPos( ));
        touchPoint.setStartScenePos( prevPoint.startScenePos( ));

        touchPoint.setLastNormalizedPos( prevPoint.normalizedPos( ));
        touchPoint.setLastPos( prevPoint.pos( ));
        touchPoint.setLastScreenPos( prevPoint.screenPos( ));
        touchPoint.setLastScenePos( prevPoint.scenePos( ));
        break;
    }

    default:
        put_flog( LOG_ERROR, "Got wrong touch event type %i", eventType );
        return;
    }

    touchPoint.setState( touchPointStates );
    _touchPointMap.insert( tcur->getCursorID(), touchPoint );

    QEvent* touchEvent = new QTouchEvent( eventType, QTouchEvent::TouchScreen,
                                          Qt::NoModifier, touchPointStates,
                                          _touchPointMap.values( ));
    QApplication::postEvent( view->viewport(), touchEvent );

    if( eventType == QEvent::TouchEnd )
        _touchPointMap.remove( tcur->getCursorID( ));
}