void ClsDiagConnectionHandleStart::refresh(){ qrectParentBR.setSize(parentItem()->boundingRect().size()); qrectParentBR.setX(0); qrectParentBR.setY(0); setPos(qrectParentBR.center()); if(dynamic_cast<ClsDiagItemAP*>(parentItem())){ iOrientation = dynamic_cast<ClsDiagItemAP*>(parentItem())->getOrientation(); setOrientation(iOrientation); } QPointF qpHere = parentItem()->scenePos() + qrectParentBR.center(); QGraphicsLineItem *qlinePost = parentConnection->getFirstSegment(); if(qlinePost!=NULL){ if(iOrientation == ClsDiagConnection::WEST_EAST){ qlinePost->setLine(qpHere.x() - qrectMyBR.height(), qpHere.y() - 1, qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */ } else if(iOrientation == ClsDiagConnection::EAST_WEST){ qlinePost->setLine(qpHere.x() + qrectMyBR.height(), qpHere.y(), qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */ } else if(iOrientation == ClsDiagConnection::NORTH_SOUTH){ qlinePost->setLine(qpHere.x(), qpHere.y() - qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y()); } else if(iOrientation == ClsDiagConnection::SOUTH_NORTH){ qlinePost->setLine(qpHere.x() - 1, qpHere.y() + qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y()); } } qlinePost->setZValue(0); setZValue(10); }
void QTableManager::Update(QgraphicsItemTable *table, qreal Vx,qreal Vy) { QGraphicsLineItem* line ; for (int i = 0 ;i<ProjectData->NodeCount();i++){ line = ProjectData->getNode(i)->link; if (ProjectData->getNode(i)->start==table) line->setLine(line->line().x1()+Vx,line->line().y1()+Vy,line->line().x2(),line->line().y2()); if (ProjectData->getNode(i)->end==table){ line->setLine(line->line().x1(),line->line().y1(),line->line().x2()+Vx,line->line().y2()+Vy); } } }
void GraphicalRobotElement::updateTraceRect() { QGraphicsEllipseItem *Position; QGraphicsLineItem *UnLine; int RobotPositionsSize; QRectF rect0; QRectF rect1; QPen penForTraceLine (Qt::black); penForTraceLine.setWidth (1); if (currentWIM.has_myposition() ) { Position = this->parentScene->addEllipse (QRect(), QPen (Qt::black), QBrush (Qt::magenta) ); Position->setRect (this->parentScene->rectFromFC ( currentWIM.myposition().x() * 1000, currentWIM.myposition().y() * 1000, 40, 40) ); RobotPositions.push_back (Position); RobotPositionsSize = RobotPositions.size(); if (RobotPositionsSize > 1) { rect0 = RobotPositions[RobotPositionsSize-1]->rect(); rect1 = RobotPositions[RobotPositionsSize-2]->rect(); UnLine = this->parentScene->addLine (QLineF(), penForTraceLine); UnLine->setLine (QLineF (rect0.x(), rect0.y(), rect1.x(), rect1.y() ) ); UnionistLines.push_back (UnLine); } } }
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 GraphiItemCtrl::OnLineChanged( int iKey, QLineF oLine ) { QGraphicsLineItem* pItem = map_LineItems.value(iKey); if(!pItem) return; pItem->setLine(oLine); }
void ClsDiagConnectionHandleStart::moveChildren (){ // cout << "ClsDiagConnectionHandleStart::moveChildrenBy ( double dx, double dy)" << endl; QPointF qpHere = parentItem()->scenePos() + qrectParentBR.center(); QGraphicsLineItem *qlinePost = parentConnection->getFirstSegment(); if(qlinePost!=NULL){ if(iOrientation == ClsDiagConnection::WEST_EAST){ qlinePost->setLine(qpHere.x() - qrectMyBR.height(), qpHere.y() -1 , qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */ } else if(iOrientation == ClsDiagConnection::EAST_WEST){ qlinePost->setLine(qpHere.x() + qrectMyBR.height(), qpHere.y(), qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */ } else if(iOrientation == ClsDiagConnection::NORTH_SOUTH){ qlinePost->setLine(qpHere.x(), qpHere.y() - qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y()); } else if(iOrientation == ClsDiagConnection::SOUTH_NORTH){ qlinePost->setLine(qpHere.x() - 1, qpHere.y() + qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y()); } } }
void advance() { QPointF unit = (end - start)/sqrt(QPointF::dotProduct(end - start, end - start)); currentPos += 4.*unit; QLineF l = line->line(); l.setP1(currentPos + QPoint(GameScene::tile_width/2, GameScene::tile_height/2)); line->setLine(l); if ((currentPos - end).manhattanLength() < 4.) { finished = true; } }
ParticipantInfoDialog::ParticipantInfoDialog(Participant* participant, QWidget* parent, bool showRemove) : PopupDialog( parent ), m_participant(participant) { setMinimumWidth(400); setMinimumHeight(160); this->setSizeGripEnabled(false); QGraphicsPixmapItem* image = new QGraphicsPixmapItem( participant->pixmap().scaled(80, 80, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), widget() ); image->setPos( 8, 8 ); QGraphicsLineItem* line = new QGraphicsLineItem( widget() ); line->setPen( QPen( QColor( 100, 100, 100 ) ) ); line->setLine( 8, 110, width() - 2 * 8, 110 ); int buttonRight = width() - 10; QPushButton* button = new QPushButton(); button->setText(tr("New Wave")); QGraphicsProxyWidget* item = scene()->addWidget(button); item->setParentItem( widget() ); item->setPos( buttonRight - item->preferredWidth(), height() - 10 - item->preferredHeight() ); buttonRight -= item->preferredWidth() + 10; //Adds remove button if parent is a waveview if (showRemove) { QPushButton* removeFromWaveButton = new QPushButton(); removeFromWaveButton->setText(tr("Remove")); QGraphicsProxyWidget* removeItem = scene()->addWidget(removeFromWaveButton); removeItem->setParentItem( widget() ); removeItem->setPos( buttonRight - removeItem->preferredWidth(), height() - 10 - removeItem->preferredHeight() ); buttonRight -= removeItem->preferredWidth() + 10; connect( removeFromWaveButton, SIGNAL(clicked()),SLOT(removeParticipant())); } QPushButton* button2 = new QPushButton(); button2->setText(tr("Close")); QGraphicsProxyWidget* item2 = scene()->addWidget(button2); item2->setParentItem( widget() ); item2->setPos( buttonRight - item2->preferredWidth(), height() - 10 - item2->preferredHeight() ); QGraphicsTextItem* text = new QGraphicsTextItem( participant->name(), widget() ); text->setPos( 110, 10 ); text->setFont( QFont( "Arial", 18, QFont::Bold ) ); text = new QGraphicsTextItem( tr("Address") + ": " + participant->address(), widget() ); text->setPos( 110, 50 ); text->setFont( QFont( "Arial", 11 ) ); connect( button, SIGNAL(clicked()), SLOT(newWave())); connect( button2, SIGNAL(clicked()), SLOT(close())); }
void MeshDrawer::setMesh(const cv::Mat &mesh) { current_mesh = mesh; int number_of_points = (int)point_items.size(); int number_of_lines = (int)line_items.size(); bool hide_mesh = ((mesh.rows == 0) || (mesh.cols == 0)); // update lines for (int line_index = 0; line_index < number_of_lines; line_index++) { QGraphicsLineItem *line = line_items[line_index]; if (hide_mesh) { line->setVisible(false); } else { QPointF from_point(mesh.at<double>(current_connections.at<int>(0,line_index),0), mesh.at<double>(current_connections.at<int>(0,line_index)+number_of_points,0)); QPointF to_point(mesh.at<double>(current_connections.at<int>(1,line_index),0), mesh.at<double>(current_connections.at<int>(1,line_index)+number_of_points,0)); QLineF line_position(from_point,to_point); line->setLine(line_position); line->setVisible(true); } } // update points for (int point_index = 0; point_index < number_of_points; point_index++) { QGraphicsEllipseItem *point = point_items[point_index]; if (hide_mesh) { point->setVisible(false); } else { QPointF position(mesh.at<double>(point_index,0), mesh.at<double>(point_index+number_of_points,0)); QRectF ellipse_rect(position.x() - point_radius, position.y() - point_radius, 2*point_radius, 2*point_radius); point->setRect(ellipse_rect); point->setVisible(true); } } }
QGraphicsItem* CGraphicsLineItem::createItem() { QGraphicsLineItem* pItem = new QGraphicsLineItem(m_Parent); drawPen(pItem); QPointF start; start.setX(GET_VALUE(x1).toFloat()); start.setY(GET_VALUE(y1).toFloat()); QPointF end; end.setX(GET_VALUE(x2).toFloat()); end.setY(GET_VALUE(y2).toFloat()); QLineF line(start,end); pItem->setLine(line); return pItem; }
void MelodyNoteGlyphItem::layoutLedgerLineItems() { if (!m_ledgerLines.count()) return; qreal halfStaffSpace = musicFont()->halfStaffSpace(); qreal noteHeadWidth = m_notehead->boundingRect().width(); qreal ledgerLineWidth = noteHeadWidth + 2 * ledgerLineExtensionWidth(); for (int i = 0; i < m_ledgerLines.count(); ++i) { qreal yPos = i * halfStaffSpace; if (m_ledgerPosition == LedgerLinePosition::Above) { yPos *= -1; } QGraphicsLineItem *ledgerLineItem = m_ledgerLines.at(i); ledgerLineItem->setLine(0, yPos, ledgerLineWidth, yPos); ledgerLineItem->setVisible(true); } }
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(); } }
void Gui::createLaserScannerObjects() { // the start position for the pos. calculation laserXPos = 0; laserYPos = 0; //laserFrontYPos = INITIALLASERYPOSFRONT; //laserRearYPos = INITIALLASERYPOSREAR; // set some nice colors for some widgets colorLaserObstacle = QColor(255, 50, 50); // light red colorLaserFreeWay = Qt::darkRed; colorLaserPreferredDrivingDirection = QColor(7, 68, 30); // green colorLaserCenterDrivingDirection = Qt::green; colorGraphicsSceneBackground = Qt::black; // the graphicsScene for the laser scanner scene = new LaserScene(); // set some colors scene->setBackgroundBrush(colorGraphicsSceneBackground); // turn off moving of scene, when objects extend the scene -> DISABLED to enable dragging the robot in the laserView!! // (set scene rect to size of GUI element) -> DISABLED to enable dragging the robot in the laserView!! //scene->setSceneRect(0, 0, ui.graphicsViewLaser->width(), ui.graphicsViewLaser->height()); -> DISABLED to enable dragging the robot in the laserView!! // set scene to the GUI ui.graphicsViewLaser->setScene(scene); // enable OpenGL rendering with antialiasing (and direct hardware rendering (if supportet from the hardware)) ui.graphicsViewLaser->setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::DirectRendering))); //======================================================= // add robot picture1 //======================================================= // add items to the scene pixmapBot1 = new QGraphicsPixmapItem(QPixmap(":/images/images/bot_from_above.png")); // init the scale for the laser line / distances drawing stuff lastZoom = ui.sliderZoom->value(); //-------------------------------------------------------------- // set the start scale //-------------------------------------------------------------- startScale = 10; // change scale of the robot pic to 1/10 to fit in the window and to fit on the size of the laser lines pixmapBot1->scale( (1.0 / startScale), (1.0 / startScale)); // horizontal center pixmapBot1->setPos(laserXPos, laserYPos); // add the pixmap scene->addItem(pixmapBot1); // put one layer up (layer 2). All others share the same (unset) layer under the pixmap. pixmapBot1->setZValue(1); //===================================================== // create the laser line lists //===================================================== laserLineListFront = new QList <QGraphicsLineItem*>(); laserLineListRear = new QList <QGraphicsLineItem*>(); //------------------------------------- // create the FRONT laser line list //------------------------------------- // TODO: check if always 180 lines! // create 180 laser lines (0 to 179) for (int i=-90; i<90; i++) { QGraphicsLineItem *line = new QGraphicsLineItem(); // the length (and position) of the laser line in pixel line->setLine(0,0,0,0); // FIXME doest not work: line->setPen(QPen(colorLaserFreeWay, 3)); line->setPen(QPen(colorLaserFreeWay)); // set position of each line line->rotate(i); // put one layer up (layer 2). All others share the same (unset) layer under the pixmap. line->setZValue(2); // add line to QList laserLineListFront->append(line); // add line to scene scene->addItem(line); } //------------------------------------- // create the REAR laser line list //------------------------------------- // TODO: check if always 180 lines! // create 180 laser lines (0 to 179) for (int i=90; i>-90; i--) { QGraphicsLineItem *line = new QGraphicsLineItem(); // FIXME doest not work: line->setPen(QPen(colorLaserFreeWay, 3)); line->setPen(QPen(colorLaserFreeWay)); // the length (and position) of the laser line in pixel line->setLine(0,0,0,0); // set position of each line line->rotate(i); // put one layer up (layer 2). All others share the same (unset) layer under the pixmap. line->setZValue(2); // add line to QList laserLineListRear->append(line); // add line to scene scene->addItem(line); } //======================================================= // add robot picture2 //======================================================= // add items to the scene pixmapBot2 = new QGraphicsPixmapItem(QPixmap(":/images/images/bot_from_above_TOP2.png")); // change scale of the robot pic to 1/10 to fit in the window and to fit on the size of the laser lines pixmapBot2->scale( (1.0 / startScale), (1.0 / startScale)); // horizontal center pixmapBot2->setPos(laserXPos, laserYPos); // add the pixmap scene->addItem(pixmapBot2); // put one layer up (layer 2). All others share the same (unset) layer under the pixmap. pixmapBot2->setZValue(3); }
void KMapScene::updatePath() { QGraphicsLineItem *path; QVector<QPoint> curve1 (0); QPoint toP (0, 0), fromP (0, 0); int r, s; pathLineListRectReset(); for (int ways = 0; ways < PathLength; ways++) { if (pathR[ways] == -1 && pathS[ways] == -1) { break; } r = pathR[ways]; s = pathS[ways]; if (r == InnerRing + 1) { fromP.setX ( toGrid (toCartesianY (RtoD (r) + 0.75 * RingDistance, StoT (s) + 0.5 * SectorAngleRad) ) ); fromP.setY ( toGrid (toCartesianX (RtoD (r) + 0.75 * RingDistance, StoT (s) + 0.5 * SectorAngleRad) ) ); } else { fromP.setX ( toGrid (cellCenterY[r][s]) ); fromP.setY ( toGrid (cellCenterX[r][s]) ); } QPoint x0 (gridImgH[r][s], gridImgV[r][s]); QPoint x1 (gridImgH[ (r+1) ][s], gridImgV[ (r+1) ][s]); QPoint x2 (gridImgH[ (r+1) ][wrapTo (s+1, N) ], gridImgV[ (r+1) ][wrapTo (s+1, N) ]); QPoint x3 (gridImgH[r][wrapTo (s+1, N) ], gridImgV[r][wrapTo (s+1, N) ]); curve1.clear(); curve1.append (x0); curve1.append (x1); curve1.append (x2); curve1.append (x3); if (pathO[ways] == 0) { toP.setX ( (curve1[1].x() + curve1[2].x() ) / 2); toP.setY ( (curve1[1].y() + curve1[2].y() ) / 2); } else if (pathO[ways] == 1) { toP.setX ( curve1[2].x() ); toP.setY ( curve1[2].y() ); } else if (pathO[ways] == 2) { toP.setX ( (curve1[2].x() + curve1[3].x() ) / 2); toP.setY ( (curve1[2].y() + curve1[3].y() ) / 2); } else if (pathO[ways] == 3) { toP.setX (curve1[3].x() ); toP.setY (curve1[3].y() ); } else if (pathO[ways] == 4) { toP.setX ( (curve1[0].x() + curve1[3].x() ) / 2); toP.setY ( (curve1[0].y() + curve1[3].y() ) / 2); } else if (pathO[ways] == 5) { toP.setX ( curve1[0].x() ); toP.setY (curve1[0].y() ); } else if (pathO[ways] == 6) { toP.setX ( (curve1[1].x() + curve1[0].x() ) / 2); toP.setY ( (curve1[1].y() + curve1[0].y() ) / 2); } else if (pathO[ways] == 7) { toP.setX (curve1[1].x() ); toP.setY (curve1[1].y() ); } path = pathLineList.at (ways); path->setLine (fromP.x(), fromP.y(), toP.x(), toP.y() ); pathR[ways] = -1; pathS[ways] = -1; pathO[ways] = -1; } }
void PSV_AxisDownItem::updateItem() { // m_markFont.setPointSizeF(m_rect.width() * m_rect.height() * 0.0005); updateLabels(); QPen linePen(QBrush(m_lineColor), m_lineWidth); QPen barPen(QBrush(m_markColor), m_markWidth); { QGraphicsLineItem* lineItem = new QGraphicsLineItem(this); lineItem->setPen(linePen); lineItem->setLine(m_rect.right() + 2 * m_arrowsLength, m_rect.top() , m_rect.left(), m_rect.top()); lineItem->setZValue(1); QGraphicsLineItem* arrowsItem_up = new QGraphicsLineItem(this); arrowsItem_up->setPen(linePen); arrowsItem_up->setLine(m_rect.right() + 2 * m_arrowsLength, m_rect.y() , m_rect.right() + m_arrowsLength, m_rect.y()- 0.5 * m_arrowsLength); arrowsItem_up->setZValue(1); QGraphicsLineItem* arrowsItem_right = new QGraphicsLineItem(this); arrowsItem_right->setPen(linePen); arrowsItem_right->setLine(m_rect.right() + 2 * m_arrowsLength, m_rect.y() , m_rect.right() + m_arrowsLength, m_rect.y() + 0.5 * m_arrowsLength); arrowsItem_right->setZValue(1); } int count = m_labelList.count(); if(count <= 1) { return; } double dx = 0.0; double dy = 0.0; if(m_isCenter && m_isList) { dx = 0.5 * m_rect.width() / count; } else { count--; } double oneSpace = m_rect.width() / count; m_markPointList.clear(); bool isRotate = false; qreal maxHeight = 0.0;; qreal maxWidth = 0.0;; if(m_isCenter && m_isList) { count = m_labelList.count() + 1; } else { count = m_labelList.count(); } for(int index = 0; index < m_labelList.count(); ++index) { QPair<QVariant, QString> labelPair = m_labelList.at(index); QGraphicsTextItem* textItem = new QGraphicsTextItem(labelPair.second, this); textItem->setDefaultTextColor(m_defaultColor); textItem->setFont(m_markFont); qreal height = textItem->boundingRect().height(); qreal width = textItem->boundingRect().width(); if(index == 0) { if(width > oneSpace && height < 2*oneSpace)//ФЭК±ґ¦Ан { isRotate = true; maxHeight = width; maxWidth = height; } else { maxHeight = height; maxWidth = width; } } qreal x = m_rect.left() + (index * (m_rect.width())) / (count - 1); qreal y = m_rect.top() + m_markLength; if(isRotate) { #if QT_VERSION > QT_VERSION_CHECK(4, 6, 0) textItem->setRotation(90); #else textItem->rotate(90); #endif textItem->setPos(x + 0.5 * height, y); if(maxHeight < width) { maxHeight = width; } if(maxWidth < height) { maxWidth = height; } } else { textItem->setPos(x - 0.5 * width, y); if(maxHeight < height) { maxHeight = height; } if(maxWidth < width) { maxWidth = width; } } textItem->moveBy(dx,dy); QGraphicsLineItem *lineItem = new QGraphicsLineItem(this); lineItem->setPen(barPen); if(index != 0 && index != count -1) { lineItem->setLine(x - 0.5 * barPen.width(), m_rect.top(), x - 0.5 * barPen.width(), m_rect.top() + m_markLength); } else { lineItem->setLine(x, m_rect.top(), x, m_rect.top() + m_markLength); } m_markPointList.append(QPointF(x - 0.5 * barPen.width(), m_rect.top())); } //================= m_validRect = QRectF(m_rect.x() - 0.5 * maxWidth ,m_rect.y() ,m_rect.width() + maxWidth ,m_markLength + maxHeight); // QGraphicsRectItem *item = new QGraphicsRectItem(m_validRect,this); }
void BaseDrawingWidget::handleDrawingState(DrawingState state, QPointF lastPoint) { // handle drawing start/update/end events for the current drawing mode QPainter::CompositionMode prevCompMode; if(state == DRAWINGSTATE_START) { // start a new series of paint operations on the picture picturePainter.begin(&picture); // set the drawing style for the painter picturePainter.setPen(drawingPen); picturePainter.setBrush(drawingBrush); } switch(drawingMode) { case DRAWINGMODE_FREEHAND: if(state == DRAWINGSTATE_START) { QGraphicsLineItem * newLine = new QGraphicsLineItem(QLineF(lastPoint, lastPoint), 0, getDrawingData()); currentItem = newLine; newLine->setPen(drawingPen); } else if(state == DRAWINGSTATE_UPDATE) { QGraphicsLineItem * newLine = new QGraphicsLineItem(currentItem, getDrawingData()); newLine->setLine(QLineF(mousePrevPoint, lastPoint)); newLine->setPen(drawingPen); picturePainter.drawLine(mousePrevPoint, lastPoint); } else { QGraphicsLineItem * newLine = new QGraphicsLineItem(currentItem, getDrawingData()); newLine->setLine(QLineF(mousePrevPoint, lastPoint)); newLine->setPen(drawingPen); // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); picturePainter.drawLine(mousePrevPoint, lastPoint); } break; case DRAWINGMODE_RECTANGLE: if(state == DRAWINGSTATE_START) { // create a temporary QGraphicsItem // will be committed to the drawing when the mouse is released QGraphicsRectItem * newRect = new QGraphicsRectItem(lastPoint.x(), lastPoint.y(),0,0); currentItem = (QGraphicsItem *) newRect; newRect->setPen(drawingPen); newRect->setBrush(drawingBrush); drawingData->addItem(currentItem); } else if(state == DRAWINGSTATE_UPDATE) // update the temporary QGraphicsItem ((QGraphicsRectItem*)currentItem)->setRect(QRectF(mouseDownPoint,lastPoint).normalized()); else { // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); // commit the drawing to the stage pixmap picturePainter.drawRect(QRectF(mouseDownPoint,lastPoint).normalized()); } break; case DRAWINGMODE_STRAIGHTLINE: if(state == DRAWINGSTATE_START) { // create a temporary QGraphicsItem // will be committed to the drawing when the mouse is released QGraphicsLineItem * newLine = new QGraphicsLineItem(QLineF(lastPoint, lastPoint)); currentItem = (QGraphicsItem*) newLine; newLine->setPen(drawingPen); getDrawingData()->addItem(newLine); } else if(state == DRAWINGSTATE_UPDATE) { // update the temporary QGraphicsItem ((QGraphicsLineItem*)currentItem)->setLine(QLineF(mouseDownPoint, lastPoint)); } else { // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); // commit the drawing to the stage pixmap picturePainter.drawLine(QLineF(mouseDownPoint, lastPoint)); } break; case DRAWINGMODE_ELLIPSE: if(state == DRAWINGSTATE_START) { // create a temporary QGraphicsItem // will be committed to the drawing when the mouse is released QGraphicsEllipseItem * newRect = new QGraphicsEllipseItem(lastPoint.x(), lastPoint.y(),0,0); currentItem = (QGraphicsItem *) newRect; newRect->setPen(drawingPen); newRect->setBrush(drawingBrush); drawingData->addItem(currentItem); } else if(state == DRAWINGSTATE_UPDATE) // update the temporary QGraphicsItem ((QGraphicsRectItem*)currentItem)->setRect(QRectF(mouseDownPoint,lastPoint).normalized()); else { // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); // commit the drawing to the stage pixmap picturePainter.drawEllipse(QRectF(mouseDownPoint,lastPoint).normalized()); } break; case DRAWINGMODE_ERASER: if(state == DRAWINGSTATE_START) { QGraphicsRectItem * newEraseRect = new QGraphicsRectItem(QRectF(lastPoint, QSizeF(drawingPen.width()+5, drawingPen.width()+5)), 0, getDrawingData()); currentItem = newEraseRect; newEraseRect->setPen(QPen(Qt::transparent)); newEraseRect->setBrush(QBrush(Qt::white)); } else if(state == DRAWINGSTATE_UPDATE) { QGraphicsRectItem * newEraseRect = new QGraphicsRectItem(currentItem, getDrawingData()); newEraseRect->setRect(QRectF(lastPoint, QSizeF(drawingPen.width()+5, drawingPen.width()+5))); newEraseRect->setPen(QPen(Qt::transparent)); newEraseRect->setBrush(QBrush(Qt::white)); } else { QGraphicsRectItem * newEraseRect = new QGraphicsRectItem(currentItem, getDrawingData()); newEraseRect->setRect(QRectF(lastPoint, QSizeF(drawingPen.width()+5, drawingPen.width()+5))); newEraseRect->setPen(QPen(Qt::transparent)); newEraseRect->setBrush(QBrush(Qt::white)); // remove the temporary QGraphicsItem getDrawingData()->removeItem(currentItem); } // common in all cases for the eraser: // we have to set a specific composition mode for the eraser // back up the current value prevCompMode = picturePainter.compositionMode(); picturePainter.setCompositionMode(QPainter::CompositionMode_SourceIn); // fill the region to be erased with transparent color picturePainter.fillRect(QRectF(lastPoint, QSizeF(drawingPen.width()+5, drawingPen.width()+5)),Qt::transparent); // restore the old composition mode picturePainter.setCompositionMode(prevCompMode); break; case DRAWINGMODE_ARROW: // TODO not yet implemented - implement this as well break; } if(state == DRAWINGSTATE_END) { // finalize the painting on the QPicture picturePainter.end(); commitDrawing(picture); } }
void KMapScene::updatePath() { if(pathLength == 0){ return; } QGraphicsLineItem *path; QGraphicsEllipseItem *ellipse; QGraphicsLineItem *smallLine; QPoint toP (0, 0), fromP (0, 0); int r, s, o; pathLineListRectReset(); //setup up in the background the path line and then in the foreground the robot positions for (int ways = 0; ways < pathLength; ways++) { if (pathR[ways] == -1 && pathS[ways] == -1) break; r = pathR[ways]; s = pathS[ways]; if(r == 255 || s == 255){ toP.setX (toGrid(0)); toP.setY (toGrid(0)); }else{ toP.setX (cellCenterX[r][s]); toP.setY (cellCenterY[r][s]); } if(ways == 0 || ways == 1){ fromP.setX (toGrid(0)); fromP.setY (toGrid(0)); }else{ fromP.setX (cellCenterX[pathR[ways-1]][pathS[ways-1]]); fromP.setY (cellCenterY[pathR[ways-1]][pathS[ways-1]]); } path = pathLineList.at (ways); path->setLine (fromP.x(), fromP.y(), toP.x(), toP.y() ); if(ways < pathLength){ ellipse = pathEllipseList.at (ways); QPoint ellipseCenter;// ( cellCenterX[pathR[ways]][pathS[ways]] , cellCenterY[pathR[ways]][pathS[ways]] ); if(r == 255 || s == 255){ ellipseCenter.setX(toGrid(0)); ellipseCenter.setY(toGrid(0)); }else{ ellipseCenter.setX(cellCenterX[r][s]); ellipseCenter.setY(cellCenterY[r][s]); } ellipse->setRect (ellipseCenter.x() - 5, ellipseCenter.y() - 5, 10, 10); float color = 100.0f + 155.0f*((float)(ways+1)/(float)pathLength); ellipse->setBrush (QColor ((int) color, 0, 0) ); int pix = 7; smallLine = pathSmallLineList.at (ways); int orientation = pathO[ways]; //orientation = orientation*2*M_PI/8; //cout << "Mpika " << toGrid (targetRing*moveStepInMeters)/2 << " " << toGrid (targetCell*moveStepInMeters)/2 << endl; float angle = orientation*2*M_PI/8.0f; int newX = -KMath::toCartesianY ( 10, angle); int newY = -KMath::toCartesianX ( 10, angle); toP.setX ( ellipseCenter.x() + newX); toP.setY (ellipseCenter.y() + newY ); smallLine->setLine (ellipseCenter.x(), ellipseCenter.y(), toP.x(), toP.y() ); //cout << ways << " " << orientation << endl; } } }