void Wall::ShowStructure(QGraphicsScene *c) { Vector offset = Cell::Offset(); double factor = Cell::Factor(); Vector startpoint ( ((offset.x+n1->x)*factor),((offset.y+n1->y)*factor)), endpoint (((offset.x+n2->x)*factor),((offset.y+n2->y)*factor)); Vector linevec = endpoint - startpoint; Vector midline = startpoint + linevec/2.; Vector perpvec = linevec.Normalised().Perp2D(); Vector textpos1 = midline + 100 * perpvec; Vector textpos2 = midline - 100 * perpvec; QGraphicsLineItem *line = new QGraphicsLineItem(0,c); line->setPen( QPen(QColor(par.arrowcolor),2) ); line->setLine(startpoint.x, startpoint.y, endpoint.x, endpoint.y ); line->setZValue(10); line->show(); QGraphicsSimpleTextItem *text1 = new QGraphicsSimpleTextItem( QString("%1").arg(c2->Index()),0,c); QGraphicsSimpleTextItem *text2 = new QGraphicsSimpleTextItem( QString("%1").arg(c1->Index()),0,c); text1 -> setPos( textpos1.x, textpos1.y ); text2 -> setPos( textpos2.x, textpos2.y ); text1->setZValue(20); text2->setZValue(20); text1->setFont( QFont( "Helvetica", par.nodenumsize, QFont::Bold) ); text2->setFont( QFont( "Helvetica", par.nodenumsize, QFont::Bold) ); text1->setPen ( QColor(par.textcolor) ); text2->setPen ( text1->pen() ); text1->show(); text2->show(); }
void QgsComposerItem::changeItemRectangle( const QPointF& currentPosition, const QPointF& mouseMoveStartPos, const QGraphicsRectItem* originalItem, double dx, double dy, QGraphicsRectItem* changeItem ) { Q_UNUSED( dx ); Q_UNUSED( dy ); if ( !changeItem || !originalItem || !mComposition ) { return; } //test if change item is a composer item. If so, prefer call to setSceneRect() instead of setTransform() and setRect() QgsComposerItem* changeComposerItem = dynamic_cast<QgsComposerItem *>( changeItem ); double mx = 0.0, my = 0.0, rx = 0.0, ry = 0.0; QPointF snappedPosition = mComposition->snapPointToGrid( currentPosition ); //snap to grid and align to other items if ( mComposition->alignmentSnap() && mCurrentMouseMoveAction != QgsComposerItem::MoveItem ) { double alignX = 0; double alignY = 0; snappedPosition = mComposition->alignPos( snappedPosition, dynamic_cast<const QgsComposerItem*>( originalItem ), alignX, alignY ); if ( alignX != -1 ) { QGraphicsLineItem* item = hAlignSnapItem(); item->setLine( QLineF( alignX, 0, alignX, mComposition->paperHeight() ) ); item->show(); } else { deleteHAlignSnapItem(); } if ( alignY != -1 ) { QGraphicsLineItem* item = vAlignSnapItem(); item->setLine( QLineF( 0, alignY, mComposition->paperWidth(), alignY ) ); item->show(); } else { deleteVAlignSnapItem(); } } double diffX = 0; double diffY = 0; switch ( mCurrentMouseMoveAction ) { //vertical resize case QgsComposerItem::ResizeUp: diffY = snappedPosition.y() - originalItem->transform().dy(); mx = 0; my = diffY; rx = 0; ry = -diffY; break; case QgsComposerItem::ResizeDown: diffY = snappedPosition.y() - ( originalItem->transform().dy() + originalItem->rect().height() ); mx = 0; my = 0; rx = 0; ry = diffY; break; //horizontal resize case QgsComposerItem::ResizeLeft: diffX = snappedPosition.x() - originalItem->transform().dx(); mx = diffX, my = 0; rx = -diffX; ry = 0; break; case QgsComposerItem::ResizeRight: diffX = snappedPosition.x() - ( originalItem->transform().dx() + originalItem->rect().width() ); mx = 0; my = 0; rx = diffX, ry = 0; break; //diagonal resize case QgsComposerItem::ResizeLeftUp: diffX = snappedPosition.x() - originalItem->transform().dx(); diffY = snappedPosition.y() - originalItem->transform().dy(); mx = diffX, my = diffY; rx = -diffX; ry = -diffY; break; case QgsComposerItem::ResizeRightDown: diffX = snappedPosition.x() - ( originalItem->transform().dx() + originalItem->rect().width() ); diffY = snappedPosition.y() - ( originalItem->transform().dy() + originalItem->rect().height() ); mx = 0; my = 0; rx = diffX, ry = diffY; break; case QgsComposerItem::ResizeRightUp: diffX = snappedPosition.x() - ( originalItem->transform().dx() + originalItem->rect().width() ); diffY = snappedPosition.y() - originalItem->transform().dy(); mx = 0; my = diffY, rx = diffX, ry = -diffY; break; case QgsComposerItem::ResizeLeftDown: diffX = snappedPosition.x() - originalItem->transform().dx(); diffY = snappedPosition.y() - ( originalItem->transform().dy() + originalItem->rect().height() ); mx = diffX, my = 0; rx = -diffX; ry = diffY; break; case QgsComposerItem::MoveItem: { //calculate total move difference double moveX = currentPosition.x() - mouseMoveStartPos.x(); double moveY = currentPosition.y() - mouseMoveStartPos.y(); QPointF upperLeftPoint( originalItem->transform().dx() + moveX, originalItem->transform().dy() + moveY ); QPointF snappedLeftPoint = mComposition->snapPointToGrid( upperLeftPoint ); if ( snappedLeftPoint != upperLeftPoint ) //don't do align snap if grid snap has been done { deleteAlignItems(); } else if ( mComposition->alignmentSnap() ) //align item { double alignX = 0; double alignY = 0; snappedLeftPoint = mComposition->alignItem( dynamic_cast<const QgsComposerItem*>( originalItem ), alignX, alignY, moveX, moveY ); if ( alignX != -1 ) { QGraphicsLineItem* item = hAlignSnapItem(); int numPages = mComposition->numPages(); double yLineCoord = 300; //default in case there is no single page if ( numPages > 0 ) { yLineCoord = mComposition->paperHeight() * numPages + mComposition->spaceBetweenPages() * ( numPages - 1 ); } item->setLine( QLineF( alignX, 0, alignX, yLineCoord ) ); item->show(); } else { deleteHAlignSnapItem(); } if ( alignY != -1 ) { QGraphicsLineItem* item = vAlignSnapItem(); item->setLine( QLineF( 0, alignY, mComposition->paperWidth(), alignY ) ); item->show(); } else { deleteVAlignSnapItem(); } } double moveRectX = snappedLeftPoint.x() - originalItem->transform().dx(); double moveRectY = snappedLeftPoint.y() - originalItem->transform().dy(); if ( !changeComposerItem ) { QTransform moveTransform; moveTransform.translate( originalItem->transform().dx() + moveRectX, originalItem->transform().dy() + moveRectY ); changeItem->setTransform( moveTransform ); } else //for composer items, we prefer setSceneRect as subclasses can implement custom behaviour (e.g. item group) { changeComposerItem->setSceneRect( QRectF( originalItem->transform().dx() + moveRectX, originalItem->transform().dy() + moveRectY, originalItem->rect().width(), originalItem->rect().height() ) ); changeComposerItem->updateItem(); } } return; case QgsComposerItem::NoAction: break; } if ( !changeComposerItem ) { QTransform itemTransform; itemTransform.translate( originalItem->transform().dx() + mx, originalItem->transform().dy() + my ); changeItem->setTransform( itemTransform ); QRectF itemRect( 0, 0, originalItem->rect().width() + rx, originalItem->rect().height() + ry ); changeItem->setRect( itemRect ); } else //for composer items, we prefer setSceneRect as subclasses can implement custom behaviour (e.g. item group) { changeComposerItem->setSceneRect( QRectF( originalItem->transform().dx() + mx, originalItem->transform().dy() + my, originalItem->rect().width() + rx, originalItem->rect().height() + ry ) ); changeComposerItem->updateItem(); } }