void AvatarEditScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    QGraphicsScene::mouseMoveEvent(event);

    QGraphicsView *view = qobject_cast<QGraphicsView*>(event->widget()->parent());
    Q_ASSERT(view);
    QPoint p(view->mapFromScene(event->scenePos()));

    if (isDragged)
    {
        crop.moveLeft(qMax(0, crop.x() + (p.x() - origin.x())));
        crop.moveTop(qMax(0, crop.y() + (p.y() - origin.y())));
        crop.moveLeft(qMin(photo.width() - crop.width(), crop.x()));
        crop.moveTop(qMin(photo.height() - crop.height(), crop.y()));
        origin = p;

        redraw();
        emit cropChanged(crop);
    }
    else if (isSizing)
    {
        crop.setWidth(qMax(1, p.x() - crop.x()));
        crop.setWidth(
            qMin(qMin(photo.width() - crop.x(), photo.height() - crop.y()), crop.width()));
        crop.setHeight(crop.width());

        redraw();
        emit cropChanged(crop);
    }
}
예제 #2
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);
}
예제 #3
0
파일: kwidget.cpp 프로젝트: kxtry/kxmob
QRectF KWidget::rectToView() const
{
    QGraphicsView *gview = view();
    QRectF rt = rect();

    QPointF pt = mapToScene(rt.topLeft());
    QPoint vpt = gview->mapFromScene(pt);
    rt.moveTo(vpt);
    return rt;
}
QRect PageClientQGraphicsWidget::geometryRelativeToOwnerWidget() const
{
    if (!view->scene())
        return QRect();

    QList<QGraphicsView*> views = view->scene()->views();
    if (views.isEmpty())
        return QRect();

    QGraphicsView* graphicsView = views.at(0);
    return graphicsView->mapFromScene(view->boundingRect()).boundingRect();
}
QRect QGraphicsWebViewPrivate::geometryRelativeToOwnerWidget() const
{
    if (!q->scene())
        return QRect();

    QList<QGraphicsView*> views = q->scene()->views();
    if (views.isEmpty())
        return QRect();

    QGraphicsView* view = views.at(0);
    return view->mapFromScene(q->boundingRect()).boundingRect();
}
예제 #6
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();
	// this isn't exactly optimal, since we want to scale the 1.0, 4.0 distances as well
	textItem->setPos(tgtX - 1.0, tgtY + 4.0);

	// setup the text background
	textItemBack->setVisible(startPoint.x() != endPoint.x());
	textItemBack->setPos(textItem->x(), textItem->y());
	textItemBack->setRect(0, 0, textItem->boundingRect().width(), textItem->boundingRect().height());
}
예제 #7
0
파일: CUtils.cpp 프로젝트: jetcodes/JetMind
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) ) );
}
예제 #8
0
void
CurrentTrack::mousePressEvent( QGraphicsSceneMouseEvent *event )
{
    if( !m_isStopped
        && event->modifiers() == Qt::NoModifier
        && event->button() == Qt::LeftButton )
    {
        QGraphicsView *view = scene()->views().first();
        QGraphicsItem *item = view->itemAt( view->mapFromScene(event->scenePos()) );
        if( item == m_albumCover->graphicsItem() )
        {
            Meta::AlbumPtr album = The::engineController()->currentTrack()->album();
            if( album )
                ( new CoverViewDialog( album, The::mainWindow() ) )->show();
            return;
        }
    }
    Context::Applet::mousePressEvent( event );
}
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 );
}
void AvatarEditScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    if (event->button() != Qt::LeftButton)
        return;

    QGraphicsView *view = qobject_cast<QGraphicsView*>(event->widget()->parent());
    Q_ASSERT(view);
    QPoint p(view->mapFromScene(event->scenePos()));

    if (!isSizing && crop.contains(p))
    {
        isDragged = true;
        view->setCursor(Qt::ClosedHandCursor);
        origin = p;
    }
    else if (!isDragged && cropper.contains(p))
    {
        isSizing = true;
        view->setCursor(Qt::SizeFDiagCursor);
    }

    QGraphicsScene::mousePressEvent(event);
}