Exemplo n.º 1
0
 QPainterPath shape() const override
 {
     QPainterPath path;
     path.setFillRule(Qt::WindingFill);
     if (m_arrowItem)
         path.addRect(mapRectFromItem(m_arrowItem, m_arrowItem->boundingRect()));
     if (m_diamondItem)
         path.addRect(mapRectFromItem(m_diamondItem, m_diamondItem->boundingRect()));
     return path;
 }
Exemplo n.º 2
0
void QgsLayoutItemGroup::updateBoundingRect( QgsLayoutItem *item )
{
  //update extent
  if ( mBoundingRectangle.isEmpty() ) //we add the first item
  {
    mBoundingRectangle = QRectF( 0, 0, item->rect().width(), item->rect().height() );
    setSceneRect( QRectF( item->pos().x(), item->pos().y(), item->rect().width(), item->rect().height() ) );

    if ( !qgsDoubleNear( item->rotation(), 0.0 ) )
    {
      setItemRotation( item->rotation() );
    }
  }
  else
  {
    if ( !qgsDoubleNear( item->rotation(), rotation() ) )
    {
      //items have mixed rotation, so reset rotation of group
      mBoundingRectangle = mapRectToScene( mBoundingRectangle );
      setItemRotation( 0 );
      mBoundingRectangle = mBoundingRectangle.united( item->mapRectToScene( item->rect() ) );
      setSceneRect( mBoundingRectangle );
    }
    else
    {
      //items have same rotation, so keep rotation of group
      mBoundingRectangle = mBoundingRectangle.united( mapRectFromItem( item, item->rect() ) );
      QPointF newPos = mapToScene( mBoundingRectangle.topLeft().x(), mBoundingRectangle.topLeft().y() );
      mBoundingRectangle = QRectF( 0, 0, mBoundingRectangle.width(), mBoundingRectangle.height() );
      setSceneRect( QRectF( newPos.x(), newPos.y(), mBoundingRectangle.width(), mBoundingRectangle.height() ) );
    }
  }
}
Exemplo n.º 3
0
bool EmulatedCardWindow::sceneEvent(QEvent* event)
{
	if (isMaximized()) {
		if (event->type() == QEvent::GestureOverride) {
				event->accept();
		}
		else if (event->type() == QEvent::Gesture) {

			QGestureEvent* ge = static_cast<QGestureEvent*>(event);
			QGesture* g = ge->gesture(Qt::TapGesture);
			if (g && g->state() == Qt::GestureFinished) {
				QTapGesture* gt = static_cast<QTapGesture*>(g);
				QPoint touchPoint = mapFromScene(gt->position()).toPoint();
				QRectF hitTarget = mapRectFromItem(m_keyboardButton, m_keyboardButton->boundingRect());
				if (hitTarget.contains(touchPoint)) {
					//The tap coordinates landed on the keyboard button, so let them through
					//without adjusting them
					m_keyboardButton->simulateClick();
					return true;
				}
			}
		}
	}
	return CardWindow::sceneEvent(event);
}
Exemplo n.º 4
0
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
    {
        Q_UNUSED(painter);
        Q_UNUSED(option);
        Q_UNUSED(widget);

#ifdef DEBUG_PAINT_SHAPE
        painter->setPen(QPen(Qt::blue));
        painter->drawRect(boundingRect());
        painter->setPen(QPen(Qt::red));
        painter->drawPath(shape());
        painter->setPen(QPen(Qt::green));
        if (m_arrowItem)
            painter->drawRect(mapRectFromItem(m_arrowItem, m_arrowItem->boundingRect()));
        if (m_diamondItem)
            painter->drawRect(mapRectFromItem(m_diamondItem, m_diamondItem->boundingRect()));
#endif
    }
Exemplo n.º 5
0
void EmulatedCardWindow::mapCoordinates(qreal& x, qreal& y) {

	//Before we even get started, the keyboard activation button
	//is always in the CardWindow's coordinate space and isn't
	//relative to the emulated app, so its touch target is
	//"in a DMZ" of this algorithm.

	QRectF hitTarget = mapRectFromItem(m_keyboardButton, m_keyboardButton->boundingRect());
	if (hitTarget.contains(x,y)) {
		//The tap coordinates landed on the keyboard button, so let them through
		//without adjusting them
		return;
	}


	qreal adjustmentAngle = rotationAdjustmentAngle();

	qreal temp;

	if (adjustmentAngle == 90) {
		temp = -x;
		x = y;
		y = temp;
	}
	else if (adjustmentAngle == -90) {
		temp = x;
		x = -y;
		y = temp;
	} else if (adjustmentAngle == 0) {
		//Do nothing
	}
	else if (adjustmentAngle == 180) {
		x = -x;
		y = -y;
	}

	int emuWidth = emulationBoundingRect().toRect().width();
	int emuHeight = emulationBoundingRect().toRect().height();
	QRectF br = boundingRect();
	x = x - br.x() - (br.width()/2) + (emuWidth/2);
	y = y - br.y() - (br.height()/2) + (emuHeight/2);

	if (adjustmentAngle == 90) {
		x = x + m_positiveSpaceAdjustment;
	}
	else if (adjustmentAngle == -90) {
		x = x - m_positiveSpaceAdjustment;
	} else if (adjustmentAngle == 0) {
		y = y + m_positiveSpaceAdjustment;
	}
	else if (adjustmentAngle == 180) {
		y = y - m_positiveSpaceAdjustment;
	}

}
Exemplo n.º 6
0
QPainterPath ArrowItem::shape() const
{
    QPainterPath path;
    path.setFillRule(Qt::WindingFill);
    if (m_shaftItem &&m_shaftItem->path() != QPainterPath()) {
        QPainterPathStroker ps;
        QPen pen = m_shaftItem->pen();
        ps.setCapStyle(pen.capStyle());
        ps.setJoinStyle(pen.joinStyle());
        ps.setMiterLimit(pen.miterLimit());
        // overwrite pen width to make selection more lazy
        ps.setWidth(16.0);
        QPainterPath p = ps.createStroke(m_shaftItem->path());
        path.addPath(p);
    }
    if (m_startHeadItem)
        path.addRect(mapRectFromItem(m_startHeadItem, m_startHeadItem->boundingRect()));
    if (m_endHeadItem)
        path.addRect(mapRectFromItem(m_endHeadItem, m_endHeadItem->boundingRect()));
    return path;
}
Exemplo n.º 7
0
void QgsLayoutItemGroup::attemptResize( const QgsLayoutSize &size, bool includesFrame )
{
  if ( !mLayout )
    return;

  if ( !shouldBlockUndoCommands() )
    mLayout->undoStack()->beginMacro( tr( "Resize Group" ) );

  QRectF oldRect = rect();
  QSizeF newSizeLayoutUnits = mLayout->convertToLayoutUnits( size );
  QRectF newRect;
  newRect.setSize( newSizeLayoutUnits );

  //also resize all items within the group
  for ( QgsLayoutItem *item : qgis::as_const( mItems ) )
  {
    if ( !item )
      continue;

    std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
    if ( !shouldBlockUndoCommands() )
    {
      command.reset( createCommand( QString(), 0 ) );
      command->saveBeforeState();
    }

    QRectF itemRect = mapRectFromItem( item, item->rect() );
    QgsLayoutUtils::relativeResizeRect( itemRect, oldRect, newRect );

    itemRect = itemRect.normalized();
    QPointF newPos = mapToScene( itemRect.topLeft() );

    QgsLayoutSize itemSize = mLayout->convertFromLayoutUnits( itemRect.size(), item->sizeWithUnits().units() );
    item->attemptResize( itemSize, includesFrame );

    // translate new position to current item units
    QgsLayoutPoint itemPos = mLayout->convertFromLayoutUnits( newPos, item->positionWithUnits().units() );
    item->attemptMove( itemPos, false );

    if ( command )
    {
      command->saveAfterState();
      mLayout->undoStack()->push( command.release() );
    }
  }
  QgsLayoutItem::attemptResize( size );
  if ( !shouldBlockUndoCommands() )
    mLayout->undoStack()->endMacro();

  resetBoundingRect();
}
Exemplo n.º 8
0
//-----------------------------------------------------------------------------
// Function: itemTotalRect()
//-----------------------------------------------------------------------------
QRectF VisualizerItem::itemTotalRect() const
{
	// the rectangle that contains this item
	QRectF totalRect(rect());

	// if there are children
	QList<QGraphicsItem*> children = childItems();
	foreach (QGraphicsItem* child, children)
    {
		// the rectangle must contain this item and also the child item
		VisualizerItem* childItem = dynamic_cast<VisualizerItem*>(child);
		if (childItem && childItem->isVisible())
        {
			totalRect = totalRect.united(mapRectFromItem(child, childItem->itemTotalRect()));
		}
	}
Exemplo n.º 9
0
void QgsComposerMouseHandles::drawSelectedItemBounds( QPainter* painter )
{
  //draw dotted border around selected items to give visual feedback which items are selected
  QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
  if ( selectedItems.size() == 0 )
  {
    return;
  }

  //use difference mode so that they are visible regardless of item colors
  painter->save();
  painter->setCompositionMode( QPainter::CompositionMode_Difference );

  // use a grey dashed pen - in difference mode this should always be visible
  QPen selectedItemPen = QPen( QColor( 144, 144, 144, 255 ) );
  selectedItemPen.setStyle( Qt::DashLine );
  selectedItemPen.setWidth( 0 );
  painter->setPen( selectedItemPen );
  painter->setBrush( Qt::NoBrush );

  QList<QgsComposerItem*>::iterator itemIter = selectedItems.begin();
  for ( ; itemIter != selectedItems.end(); ++itemIter )
  {
    //get bounds of selected item
    QPolygonF itemBounds;
    if ( mIsDragging && !( *itemIter )->positionLock() )
    {
      //if currently dragging, draw selected item bounds relative to current mouse position
      //first, get bounds of current item in scene coordinates
      QPolygonF itemSceneBounds = ( *itemIter )->mapToScene(( *itemIter )->rectWithFrame() );
      //now, translate it by the current movement amount
      //IMPORTANT - this is done in scene coordinates, since we don't want any rotation/non-translation transforms to affect the movement
      itemSceneBounds.translate( transform().dx(), transform().dy() );
      //finally, remap it to the mouse handle item's coordinate system so it's ready for drawing
      itemBounds = mapFromScene( itemSceneBounds );
    }
    else if ( mIsResizing && !( *itemIter )->positionLock() )
    {
      //if currently resizing, calculate relative resize of this item
      if ( selectedItems.size() > 1 )
      {
        //get item bounds in mouse handle item's coordinate system
        QRectF itemRect = mapRectFromItem(( *itemIter ), ( *itemIter )->rectWithFrame() );
        //now, resize it relative to the current resized dimensions of the mouse handles
        QgsComposition::relativeResizeRect( itemRect, QRectF( -mResizeMoveX, -mResizeMoveY, mBeginHandleWidth, mBeginHandleHeight ), mResizeRect );
        itemBounds = QPolygonF( itemRect );
      }
      else
      {
        //single item selected
        itemBounds = rect();
      }
    }
    else
    {
      //not resizing or moving, so just map from scene bounds
      itemBounds = mapRectFromItem(( *itemIter ), ( *itemIter )->rectWithFrame() );
    }
    painter->drawPolygon( itemBounds );
  }
  painter->restore();
}