void ProfileScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (!isProfileSelected) { return; } if (isVertexMoving) { QPoint mousePos = event->lastScenePos().toPoint(); float x = mousePos.x(); float y = mousePos.y(); QGraphicsEllipseItem* ellipse = currentlyMovingVertex->getEllipse(); ellipse->setRect(x - vertexRadius, y - vertexRadius, vertexRadius * 2.0f, vertexRadius * 2.0f); Vertex* neighbor1 = currentlyMovingVertex->getNeighbor1(); if (neighbor1 != 0){ QGraphicsLineItem* edge1 = currentlyMovingVertex->getEdge1(); edge1->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(), neighbor1->getEllipse()->rect().center().rx(), neighbor1->getEllipse()->rect().center().ry()); } Vertex* neighbor2 = currentlyMovingVertex->getNeighbor2(); if (neighbor2 != 0) { QGraphicsLineItem* edge2 = currentlyMovingVertex->getEdge2(); edge2->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(), neighbor2->getEllipse()->rect().center().rx(), neighbor2->getEllipse()->rect().center().ry()); } QRectF thisSize = this->sceneRect(); Utils::adjustCoordinatesSceneTo3D(x, y, thisSize.width(), thisSize.height()); currentlyMovingVertex->setX(x); currentlyMovingVertex->setY(y); } }
void LVL_ModeCircle::mouseMove(QGraphicsSceneMouseEvent *mouseEvent) { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); if(!LvlPlacingItems::layer.isEmpty() && LvlPlacingItems::layer!="Default") s->setLabelBoxItem(true, mouseEvent->scenePos(), LvlPlacingItems::layer + ", " + QString::number( mouseEvent->scenePos().toPoint().x() ) + "x" + QString::number( mouseEvent->scenePos().toPoint().y() ) ); else s->setLabelBoxItem(false); if(s->m_cursorItemImg && s->m_cursorItemImg->isVisible()) { QGraphicsEllipseItem * cur = dynamic_cast<QGraphicsEllipseItem *>(s->m_cursorItemImg); QPoint hw = s->applyGrid( mouseEvent->scenePos().toPoint(), LvlPlacingItems::gridSz, LvlPlacingItems::gridOffset); QSize hs = QSize( (long)fabs(drawStartPos.x() - hw.x()), (long)fabs( drawStartPos.y() - hw.y() ) ); cur->setRect(0,0, hs.width(), hs.height()); cur->setPos(((hw.x() < drawStartPos.x() )? hw.x() : drawStartPos.x()), ((hw.y() < drawStartPos.y() )? hw.y() : drawStartPos.y())); } }
QGraphicsItemGroup* SDefaultBrush::renderPath(QPainterPath path){ QGraphicsItemGroup* pGroup = new QGraphicsItemGroup(); QPen pen; QColor c1 = mColor; QColor c2 = mColor; int alpha1 = 3*mColor.alpha()/4; c1.setAlpha(alpha1); int alpha2 = alpha1*mHardness/100; c2.setAlpha(alpha2); pen.setColor(QColor(Qt::transparent)); QRadialGradient gradient(500, 500, 500, 500, 500); gradient.setColorAt(0, c1); gradient.setColorAt(1, c2); QBrush brush(gradient); for(int i=0; i<path.length(); i+=(mWidth/2)*mSpacing){ QGraphicsEllipseItem* pEllipse = new QGraphicsEllipseItem(); pEllipse->setPen(pen); pEllipse->setBrush(brush); QPointF pt = path.pointAtPercent(path.percentAtLength(i)); pEllipse->setRect(pt.x()-mWidth/2, pt.y()-mWidth/2, mWidth, mWidth); pGroup->addToGroup(pEllipse); } return pGroup; }
/// @brief constructor /// /// @param parent parent widget ScrollScene::ScrollScene (QWidget * parent, ResultsTab *resultsTab) : QGraphicsScene (parent) , resultsTab (resultsTab) , testing (false) , text1 (new QGraphicsTextItem ("Scroll until the red circle is centered. Press SPACE to begin.")) , text2 (new QGraphicsTextItem ("Scroll until the red circle is centered. Press SPACE to begin.")) { // set the text font text1->setFont (QFont ("Arial", 18, QFont::Bold)); text2->setFont (QFont ("Arial", 18, QFont::Bold)); QRectF r = text1->boundingRect (); const size_t NCIRCLES = 100; text1->setPos (-r.width () / 2, -4 * RADIUS); text2->setPos (-r.width () / 2, NCIRCLES * RADIUS * 2); // add it addItem (text1); addItem (text2); // set background of client area setBackgroundBrush (Qt::white); circles.resize (NCIRCLES); for (size_t i = 0; i < circles.size (); ++i) { QGraphicsEllipseItem *c = new QGraphicsEllipseItem (0); c->setRect (-RADIUS, -RADIUS, RADIUS, RADIUS); int y = i * RADIUS * 2; c->setPos (0, y); addItem (c); circles[i] = c; } }
void PSV_CircularIndicatorItem::drawColorPie(int zValue) { double colorCircleRadius = m_colorCircleRadiusRatio * m_outerRadius; QPointF topLeftPot(m_rect.center().x()-colorCircleRadius, m_rect.center().y()-colorCircleRadius); QPointF bottomRightPot(m_rect.center().x()+colorCircleRadius, m_rect.center().y()+colorCircleRadius); QRectF colorCircleRect=QRectF(topLeftPot, bottomRightPot); QMapIterator<double,QColor> iter(m_levelInfos); int startAngle = 225 * 16; double dValue = m_max -m_min; if(qAbs(dValue) < PSV_ZEOR) { dValue = 100; m_max = 100; m_min = 0; } int spanAngle = 0; int topAngle = 0; while(iter.hasNext()) { iter.next(); spanAngle = (int)(16 * 270 * iter.key()) - topAngle; topAngle += spanAngle; QGraphicsEllipseItem* item = new QGraphicsEllipseItem(this); item->setRect(colorCircleRect); item->setStartAngle(startAngle - spanAngle); item->setSpanAngle(spanAngle); item->setPen(QPen(Qt::NoPen)); item->setBrush(QBrush(iter.value())); item->setZValue(zValue); startAngle = startAngle - spanAngle; } }
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); } } }
QGraphicsEllipseItem * GalaGV::makeMarkerItem(const QString &cords,const QString& sysid, ItemTyps itemtyp,QColor color, Typs typ) { QStringList cord = cords.split('/'); qreal x1 = cord.at(0).toFloat(); //qreal y1 = cord.at(1).toFloat(); qreal z1 = -1*cord.at(2).toFloat(); QGraphicsEllipseItem *item = new QGraphicsEllipseItem(); int size; switch(typ){ case GalaGV::Plani: item->setBrush(QBrush(Qt::white)); size = 2; break; case GalaGV::Mark: size = 6; break; case GalaGV::BigMarker: size = 10; break; } item->setRect(x1-(size/2),z1-(size/2),size,size); item->setPen(QPen(color)); item->setData(ID,sysid); item->setData(Cords,cords); item->setData(ItemTyp,itemtyp); return item; }
void FloorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (isVertexMoving) { QPoint mousePos = event->lastScenePos().toPoint(); float x = mousePos.x(); float y = mousePos.y(); //update the ellipse coordinate of the currently moving vertex QGraphicsEllipseItem* ellipse = currentlyMovingVertex->getEllipse(); ellipse->setRect(x - vertexRadius, y - vertexRadius, vertexRadius * 2.0f, vertexRadius * 2.0f); //update the coordinate of the two edges of the currently moving vertex FloorVertex* neighbor1 = (FloorVertex*)currentlyMovingVertex->getNeighbor1(); QGraphicsLineItem* edge1 = currentlyMovingVertex->getEdge1(); edge1->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(), neighbor1->getEllipse()->rect().center().rx(), neighbor1->getEllipse()->rect().center().ry()); FloorVertex* neighbor2 = (FloorVertex*)currentlyMovingVertex->getNeighbor2(); QGraphicsLineItem* edge2 = currentlyMovingVertex->getEdge2(); edge2->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(), neighbor2->getEllipse()->rect().center().rx(), neighbor2->getEllipse()->rect().center().ry()); //update the coordinate of the currently moving vertex QRectF thisSize = this->sceneRect(); Utils::adjustCoordinatesSceneTo3D(x, y, thisSize.width(), thisSize.height()); currentlyMovingVertex->setX(x); currentlyMovingVertex->setY(y); //update the normals currentlyMovingVertex->computeNormal(); neighbor1->computeNormal(); neighbor2->computeNormal(); } }
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value){ if(change == ItemPositionHasChanged){ QGraphicsEllipseItem *item = qgraphicsitem_cast<QGraphicsEllipseItem *>(parentItem()); qreal diff = qSqrt(x()*x() + y()*y()); item->setRect(MakeCircleRect(diff - kCropItemControlPointRadius)); } return QGraphicsEllipseItem::itemChange(change, value); }
QGraphicsItem* CGraphicsEllipseItem::createItem() { QGraphicsEllipseItem* pItem = new QGraphicsEllipseItem(m_Parent); drawPen(pItem); drawBrush(pItem); pItem->setRect(GET_VALUE(cx).toInt(), GET_VALUE(cy).toInt(), GET_VALUE(rx).toInt(), GET_VALUE(ry).toInt()); return pItem; }
void IdentityItem::updateItem( const Polka::Identity &identity ) { m_identity = identity; foreach( QGraphicsItem *child, childItems() ) { delete child; } if ( identity.type() == "group" ) { int circleSize = m_itemSize + 14; QGraphicsEllipseItem *groupCircle = new QGraphicsEllipseItem( this ); groupCircle->setRect( -circleSize/2, -circleSize/2, circleSize, circleSize ); QPen pen; pen.setBrush( Qt::white ); pen.setWidth( 4 ); groupCircle->setPen( pen ); } QPixmap pixmap = m_model->pixmap( identity ); QGraphicsItem *item = new QGraphicsPixmapItem( pixmap, this ); item->setPos( -pixmap.width() / 2, -pixmap.height() / 2 ); QGraphicsTextItem *textItem = new QGraphicsTextItem( identity.name().value() ); int textWidth = textItem->boundingRect().width(); int textHeight = textItem->boundingRect().height(); m_nameItem = new RoundedRectItem( this ); m_nameItem->setRect( 0, 0, textWidth, textHeight ); m_nameItem->setBrush( QColor( 255,255,230 ) ); m_nameItem->setZValue( 10 ); textItem->setParentItem( m_nameItem ); m_nameItem->setPos( - textWidth / 2, 30 ); m_fanMenu = new FanMenu( this ); m_fanMenu->setZValue( 50 ); FanMenuItem *menuItem = m_fanMenu->addItem( i18n("Remove") ); connect( menuItem, SIGNAL( clicked() ), SLOT( emitRemoveIdentity() ) ); m_checkMenuItem = m_fanMenu->addItem( i18n("Check") ); connect( m_checkMenuItem, SIGNAL( clicked() ), SLOT( checkItem() ) ); if ( identity.type() == "group" ) { menuItem = m_fanMenu->addItem( i18n("Go to") ); } else { menuItem = m_fanMenu->addItem( i18n("Show") ); } connect( menuItem, SIGNAL( clicked() ), SLOT( emitShowIdentity() ) ); m_fanMenu->setupItems(); hidePopups(); }
PacMan::PacMan(int radius, QColor color, int layer , double startX, double startY, double endX, double endY, int startSec, int endSec) : radius(radius) , color(color) , layer(layer) , startX(startX) , startY(startY) , endX(endX) , endY(endY) , startSec(startSec) , endSec(endSec) { moveScale = 1; QGraphicsEllipseItem * ellipse = new QGraphicsEllipseItem(this); ellipse->setRect ( -radius , -radius , radius*2 , radius*2 ); ellipse->setBrush (QBrush(color)); liveSec = endSec - startSec; setZValue(layer); }
void ProfileScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if (!isProfileSelected) { return; } if (isVertexMoving) { QPoint mousePos = event->lastScenePos().toPoint(); float x = mousePos.x(); float y = mousePos.y(); // enforce the monotonicity constraints Vertex* neighbor1 = currentlyMovingVertex->getNeighbor1(); if (neighbor1 != 0){ if (neighbor1->getEllipse()->rect().center().ry() - 1 <= y) { return; } } // enforce the monotonicity constraints Vertex* neighbor2 = currentlyMovingVertex->getNeighbor2(); if (neighbor2 != 0){ if (neighbor2->getEllipse()->rect().center().ry() + 1 >= y) { return; } } //update the ellipse coordinate of the currently moving vertex QGraphicsEllipseItem* ellipse = currentlyMovingVertex->getEllipse(); ellipse->setRect(x - vertexRadius, y - vertexRadius, vertexRadius * 2.0f, vertexRadius * 2.0f); //update the coordinate of the two edges of the currently moving vertex if (neighbor1 != 0){ Edge* edge1 = currentlyMovingVertex->getEdge1(); edge1->getLineItem()->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(), neighbor1->getEllipse()->rect().center().rx(), neighbor1->getEllipse()->rect().center().ry()); } if (neighbor2 != 0) { Edge* edge2 = currentlyMovingVertex->getEdge2(); edge2->getLineItem()->setLine(ellipse->rect().center().rx(), ellipse->rect().center().ry(), neighbor2->getEllipse()->rect().center().rx(), neighbor2->getEllipse()->rect().center().ry()); } //update the coordinate of the currently moving vertex QRectF thisSize = this->sceneRect(); Utils::adjustCoordinatesSceneTo3D(x, y, thisSize.width(), thisSize.height()); currentlyMovingVertex->setX(x); currentlyMovingVertex->setY(y); } }
void HostItem::updateHalos() { int count = 1; QMap<Job,QGraphicsEllipseItem*>::Iterator it; for(it = m_jobHalos.begin(); it != m_jobHalos.end(); ++it) { QGraphicsEllipseItem *halo = it.value(); halo->setRect(halo->x() - 5 - count * 3, halo->y() - 5 - count * 3, m_baseWidth + count * 6, m_baseHeight + count * 6); halo->setBrush(m_hostInfoManager->hostColor(it.key().client())); halo->setPen(Qt::NoPen); ++count; } }
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); } } }
void TodoHandleItem::updateItem( const Bliss::Todo &todo ) { m_todo = todo; foreach( QGraphicsItem *child, childItems() ) { delete child; } if ( todo.type() == "group" ) { int circleSize = m_itemSize + 14; QGraphicsEllipseItem *groupCircle = new QGraphicsEllipseItem( this ); groupCircle->setRect( -circleSize/2, -circleSize/2, circleSize, circleSize ); QPen pen; pen.setBrush( Qt::white ); pen.setWidth( 4 ); groupCircle->setPen( pen ); } }
/* � * Calculates the gatter intersections and hoshis position � */ void Gatter::resize(int offsetX, int offsetY, int square_size) { int i,j; QGraphicsEllipseItem *e; QMapIterator<int,QGraphicsEllipseItem*> it( hoshisList ); int size = square_size / 5; // Round size top be odd (hoshis) if (size % 2 == 0) size--; if ((size < 7) && (size>2)) size = 7; else if (size <= 2) size = 3; for (i=0; i<board_size; i++) for (j=0; j<board_size; j++) { HGatter[i][j]->setLine(int(offsetX + square_size * ( i - 0.5*(i!=0))), offsetY + square_size * j, int(offsetX + square_size * ( i + 0.5 * (i+1 != board_size))), offsetY + square_size * j ); VGatter[i][j]->setLine(offsetX + square_size * i, int(offsetY + square_size * ( j - 0.5*(j!=0))), offsetX + square_size * i, int(offsetY + square_size * ( j + 0.5 * (j+1 != board_size)))); if (hoshisList.contains(board_size*(i+1)+j+1)) { e = hoshisList.value(board_size*(i+1)+j+1); e->setRect(offsetX + square_size * i - size/2, offsetY + square_size * j- size/2, size , size ); } } }
void PSV_CircularIndicatorItem::drawOuterCircle(int zValue) { QRadialGradient outerGradient(m_rect.center(), m_outerRadius, m_rect.center()); outerGradient.setColorAt(0.0, QColor(200, 200, 200)); outerGradient.setColorAt(0.9, QColor(80, 80, 80)); outerGradient.setColorAt(0.95, QColor(180, 180, 180)); outerGradient.setColorAt(1.0, QColor(80, 80, 80)); //========================== QPen pen(Qt::NoPen); QGraphicsEllipseItem* item = new QGraphicsEllipseItem(this); item->setRect(m_rect.center().x() - m_outerRadius, m_rect.center().y() - m_outerRadius, m_outerRadius*2, m_outerRadius*2); item->setPen(pen); item->setBrush(outerGradient); item->setZValue(zValue); {//TEST QGraphicsRectItem *item = new QGraphicsRectItem(m_rect, this); item->setPen(QPen(Qt::blue)); // item->setPen(); } }
void SymbolDataEditor::moveItem(const QPoint pos) { if (itemToChange == Item::NoItem || scene->items().isEmpty()) return; if (itemToChange == Item::InPoint || itemToChange == Item::OutPoint) { QPointF itemPos = mapToScene(pos); QGraphicsEllipseItem* item = static_cast<QGraphicsEllipseItem *>(scene->items(Qt::AscendingOrder).at(itemToChange)); item->setRect(itemPos.x() - pointWidth / 2, itemPos.y() - pointWidth / 2, pointWidth, pointWidth); } if (itemToChange == Item::LimitsRect) { QGraphicsRectItem* item = static_cast<QGraphicsRectItem *>(scene->items(Qt::AscendingOrder).at(itemToChange)); QPointF scenePos = mapToScene(pos); QRectF newRect = item->rect(); if (sideToChange & Side::Top) newRect.setTop(scenePos.y()); if (sideToChange & Side::Bottom) newRect.setBottom(scenePos.y()); if (sideToChange & Side::Left) newRect.setLeft(scenePos.x()); if (sideToChange & Side::Right) newRect.setRight(scenePos.x()); if (sideToChange == Side::AllSides) { newRect.moveCenter(scenePos + dLimitsCenter); } item->setRect(newRect); } }
bool ZipplXmlReader::read( QIODevice *dev ) { setDevice( dev ); bool res = true; bool metaMode = false; mCurrParent = 0; mCurrSpot = 0; QGraphicsScene *scene = mGraphWidget->scene(); int spotID = 0; while (!atEnd()) { readNext(); if( isStartElement() ) { qDebug() << "XML name: " << name(); if( name() == "presentation") { // presentation mode: debug & presentation QString mode = attributes().value("mode").toString(); if( !mode.isEmpty() ) mMode = mode; mPath = attributes().value("path").toString(); if( !mPath.endsWith('/') ) mPath += "/"; qreal dx = qrealAttrib("width") / -2.0; qreal dy = qrealAttrib("height") / -2.0; QRectF rect( dx, dy, -2.0*dx, -2.0*dy ); scene->setSceneRect( rect ); } else if( name() == "meta" ) { metaMode = true; } else if( name() == "title" && metaMode ) { mPresentationTitle = readElementText(); } else if( name() == "description" && metaMode ) { mPresentationDescr = readElementText(); } else if( name() == "date" && metaMode ) { mPresentationDate = readElementText(); } else if( name() == "name" && metaMode ) { mAuthorName = readElementText(); } else if( name() == "email" && metaMode ) { mAuthorEmail = readElementText(); } else if( name() == "tocentry" ) { if( mCurrSpot ) { mCurrSpot->setData( TOCENTRY, readElementText() ); } } else if( name() == "spot" ) { if( mCurrParent != 0 ) { qDebug() << "Strange: Current Parent should be zero here!"; } QGraphicsRectItem *rectItem = new QGraphicsRectItem( ); rectItem->setPen( pen( rectItem->pen(), QColor("#aeaeae") )); mCurrParent = rectItem; mCurrSpot = rectItem; mCurrParent->setData( ID, QVariant( spotID++ )); mCurrParent->setPos( position() ); rectItem->setBrush( brush( rectItem->brush() ) ); scene->addItem( mCurrParent ); mSpots.append( mCurrParent ); // Prepare the hidden items list GraphicsItemList list; mHiddenItems.insert( mCurrParent, list ); } else if( name() == "hidden" ) { QGraphicsRectItem *rectItem = new QGraphicsRectItem( mCurrParent, scene ); rectItem->setPen( QPen( QColor( 240, 240, 240 ))); // append this hidden item to the list of hiddens of the parent spot. GraphicsItemList list = mHiddenItems[mCurrSpot]; list.append( rectItem ); mHiddenItems[mCurrSpot] = list; mCurrParent = rectItem; mCurrParent->setData( ID, QVariant( spotID++ )); } else if( name() == "rect" ) { if( mCurrParent ) { // within a spot qDebug() << "Creating a rectangle!"; QGraphicsRectItem *rectItem = new QGraphicsRectItem( mCurrParent, scene ); qreal width = qrealAttrib( "width" ); qreal height = qrealAttrib( "height" ); QPointF pos = position(); if( width > 0 && height > 0 ) { rectItem->setRect( pos.x(), pos.y(), width, height ); } else { rectItem->setPos( pos ); } rectItem->setPen( pen( rectItem->pen() ) ); mCurrParent = rectItem; } } else if( name() == "circle" ) { QPointF pos = position(); QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem( mCurrParent, scene ); // ellipse->setBrush( getBrush() ); qreal r = 2.0 * qrealAttrib( "r" ); QRectF rect( pos, QSizeF( r, r ) ); ellipse->setPen( pen( ellipse->pen() ) ); ellipse->setRect( rect ); } else if( name() == "text" ) { QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem( mCurrParent, scene ); QString font = attributes().value("font").toString(); QString size = attributes().value("size").toString(); QFont currFont = textItem->font(); if( !font.isEmpty() ) { currFont.setFamily( font ); textItem->setFont( currFont ); } if( !size.isEmpty() ) { currFont.setPointSize( size.toInt() ); textItem->setFont( currFont ); } textItem->setPos( position() ); // set the brush QBrush b( textItem->brush() ); b.setColor( color() ); textItem->setBrush( b ); QString text = readElementText(); textItem->setText( text ); } else if( name() == "image" ) { if( handleImg( scene ) ) { } } } else if( isEndElement() ) { qDebug( ) << "XML CLOSE: " << name().toString(); if( name() == "spot" || name() == "toc" ) { QRectF rect = mCurrParent->childrenBoundingRect(); rect.setX(0); rect.setY(0); qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent)->setRect( rect); mCurrParent = 0; } else if( name() == "rect" ) { QGraphicsRectItem *item = qgraphicsitem_cast<QGraphicsRectItem*>(mCurrParent); if( item->rect().isEmpty() ) item->setRect( mCurrParent->childrenBoundingRect() ); mCurrParent = mCurrParent->parentItem(); } else if( name() == "hidden") { mCurrParent->setOpacity( 0.0 ); mCurrParent = mCurrParent->parentItem(); } else if( name() == "meta" ) { metaMode = false; } } } createToc( scene ); return res; }
void CellScene::drawPoints() { points.clear(); for (unsigned i = 0; i < y_count; i++) for (unsigned j = 0; j < x_count; j++) { QPointF temp; temp.setY(i * a * sin(M_PI / 3)); if (i % 2 != 0) { if (j == 0) temp.setX(a * cos(M_PI / 3)); if (j > 0) { temp.setX(0); for (unsigned k = 1; k <= j; k++) temp.setX(temp.x() + ((k - 1) % 2 + 1) * a); temp.setX(temp.x() + a * cos(M_PI / 3)); } } if (i % 2 == 0) { if (j == 0) temp.setX(0); if (j > 0) { temp.setX(0); for (unsigned k = 1; k <= j; k++) temp.setX(temp.x() + ((k) % 2 + 1) * a); } } points.push_back(temp); } QGraphicsEllipseItem * pEllipseItem; QGraphicsLineItem * pLineItem; for (unsigned i = 0; i < points.size(); i++) { pEllipseItem = new QGraphicsEllipseItem(0, this); pEllipseItem->setPen(QPen(Qt::blue, 2)); pEllipseItem->setRect(QRect(points[i].x(), points[i].y(), 4, 4)); pEllipseItem->setData(0, "cellpoint"); pEllipseItem->setData(1, ""); pEllipseItem->setData(3,points[i]/a); } //for (unsigned j=1;j<=y_count/2;j++) // { // for (unsigned i=0;i<x_count/2;i++) // { // pLineItem = new QGraphicsLineItem(0, this); // pLineItem->setLine(points[2*i].x(),points[2*i].y(),points[2*i+j*x_count].x(),points[2*i+j*x_count].y()); // pLineItem->setPen(QPen(Qt::blue, 1)); // pLineItem->setData(0, "line"); // pLineItem = new QGraphicsLineItem(0, this); // pLineItem->setLine(points[2*i+j*x_count].x(),points[2*i+j*x_count].y(),points[2*i+j*x_count+1].x(),points[2*i+j*x_count+1].y()); // pLineItem->setPen(QPen(Qt::blue, 1)); // pLineItem->setData(0, "line"); // pLineItem = new QGraphicsLineItem(0, this); // pLineItem->setLine(points[2*i+1].x(),points[2*i+1].y(),points[2*i+j*x_count+1].x(),points[2*i+j*x_count+1].y()); // pLineItem->setPen(QPen(Qt::blue, 1)); // pLineItem->setData(0, "line"); // //pLineItem = new QGraphicsLineItem(points[2*i].x(),points[2*i].y(),points[2*i+j*x_count].x(),points[2*i+j*x_count].y(),this); // } //} }
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; } } }