void ProfileScene::addVertex(QPoint mousePos) { //if clicked on an edge, add point on this edge QGraphicsLineItem* currentEdge = 0; bool foundEdge(false); Profile* profile = currentProfile; Vertex* currentVertex = profile->getProfileVertex(); while(currentVertex->getNeighbor2() != 0) { currentEdge = currentVertex->getEdge2(); if (currentEdge->isUnderMouse()) { foundEdge = true; break; } currentVertex = currentVertex->getNeighbor2(); } float w = mousePos.x(); float z = mousePos.y(); if (foundEdge) { QGraphicsEllipseItem* ellipse = new QGraphicsEllipseItem(w - vertexRadius, z - vertexRadius, vertexRadius * 2.0f, vertexRadius * 2.0f); QRectF thisSize = this->sceneRect(); Utils::adjustCoordinatesSceneTo3D(w, z, thisSize.width(), thisSize.height()); //build the new vertex and add the edges between the new neighbour Vertex* newVertex = new Vertex(w, z); newVertex->setEllipse(ellipse); Vertex* nextVertex = currentVertex->getNeighbor2(); Vertex* previousVertex = currentVertex; QGraphicsLineItem* edge1 = previousVertex->replaceNeighbour(nextVertex, newVertex); QGraphicsLineItem* edge2 = nextVertex->replaceNeighbour(previousVertex, newVertex); //set all neighbour/edges of the new vertex newVertex->setNeighbor1(previousVertex);//addNeighbor newVertex->setEdge1(edge1); newVertex->setNeighbor2(nextVertex);//addNeighbor newVertex->setEdge2(edge2); //finally show the ellipse and delete the old edge this->addItem(ellipse); this->addItem(edge1); this->addItem(edge2); this->removeItem(currentEdge); delete currentEdge; // tell the mesh to generate new point/triangle mesh->setUpdateOnMesh(); } else { // we don't have clicked on an edge, we will put the point at the current position Vertex * newVertex = new Vertex(0,0); newVertex->setEllipse(new QGraphicsEllipseItem(w - vertexRadius, z - vertexRadius, vertexRadius * 2.0f, vertexRadius*2.0f)); QRectF thisSize = this->sceneRect(); Utils::adjustCoordinatesSceneTo3D(w, z, thisSize.width(), thisSize.height()); newVertex->setX(w); newVertex->setY(z); this->currentProfile->addVertexEnd(newVertex); this->addItem(newVertex->getEllipse()); this->addItem(newVertex->getEdge1()); // tell the mesh to generate new point/triangle mesh->setUpdateOnMesh(); } }
void NetworkGraphics::updateNetwork(){ qDebug() << "NetworkGraphics::updateNetwork()"; scene->clear(); linkMap.clear(); rebuildNetwork(); QPointF position = QPointF(0.0, 0.0); QList<raw_address> rootAddrs = network->getTopLevelAddresses(); for(int i=0; i<rootAddrs.size(); i++){ if(positionBranch(rootAddrs[i], position)){ QSizeF size = computeSize(rootAddrs[i]); QRectF rect = QRectF(position, size); //scene->addRect(rect);*/ position.setX( position.x() + size.width() + (3.0*CLOUD_X_MARGIN) ); //scene->update(rect); } } //Draw links QList<NetLink*> links = network->getLinks(); QPen blackPen = QPen(); blackPen.setColor(Qt::gray); blackPen.setWidth(2); for(int i=0; i<links.size(); i++){ NetLink* link = links[i]; GraphicNetCloud* firstCloud = cloudMap[nodeMap[link->getFirst()]]; GraphicNetCloud* secondCloud = cloudMap[nodeMap[link->getSecond()]]; if(firstCloud != secondCloud){ QPointF startPoint = firstCloud->boundingRect().center(); QPointF endPoint = secondCloud->boundingRect().center(); startPoint.setX(firstCloud->pos().x() + startPoint.x()); startPoint.setY(firstCloud->pos().y() + startPoint.y()); endPoint.setX(secondCloud->pos().x() + endPoint.x()); endPoint.setY(secondCloud->pos().y() + endPoint.y()); QLineF line(startPoint, endPoint); QGraphicsLineItem* lineItem = new QGraphicsLineItem(line); lineItem->setPen(blackPen); lineItem->setZValue(1); lineItem->setOpacity(.8); scene->addItem(lineItem); //qDebug() << "Line: " << line ; linkMap.insert(link, lineItem); } } }
treeVisualiserFrame::treeVisualiserFrame(const observationTree& tree, float pointSize) :pointSize(pointSize), highlightItem(NULL) { graphicsScene = new QGraphicsScene(); graphicsScene->installEventFilter(this); graphicsScene->setItemIndexMethod(QGraphicsScene::NoIndex); graphicsView = new ZoomGraphicsView(graphicsScene); graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); graphicsView->installEventFilter(this); const observationTree::treeGraphType treeGraph = tree.getTreeGraph(); observationTree::treeGraphType::vertex_iterator currentVertex, endVertex; boost::tie(currentVertex, endVertex) = boost::vertices(treeGraph); QPen blackPen(QColor("black")); blackPen.setStyle(Qt::NoPen); QBrush blueBrush(QColor("blue")); QBrush redBrush(QColor("red")); for(; currentVertex != endVertex; currentVertex++) { float x = treeGraph[*currentVertex].x; float y = treeGraph[*currentVertex].y; treeVisualiserVertex* vertexItem = new treeVisualiserVertex(x - pointSize/2, y - pointSize/2, pointSize, pointSize); vertexItem->setVertexID((int)*currentVertex); if(treeGraph[*currentVertex].potentiallyDisconnected) { vertexItem->setPen(blackPen); vertexItem->setBrush(blueBrush); } else { vertexItem->setPen(blackPen); vertexItem->setBrush(redBrush); } vertexItem->setFlag(QGraphicsItem::ItemIsSelectable, true); graphicsScene->addItem(vertexItem); } blackPen.setStyle(Qt::SolidLine); blackPen.setWidthF(pointSize/8); observationTree::treeGraphType::edge_iterator currentEdge, endEdge; boost::tie(currentEdge, endEdge) = boost::edges(treeGraph); for(; currentEdge != endEdge; currentEdge++) { int sourceVertex = (int)boost::source(*currentEdge, treeGraph); int targetVertex = (int)boost::target(*currentEdge, treeGraph); float sourceX = treeGraph[sourceVertex].x; float sourceY = treeGraph[sourceVertex].y; float targetX = treeGraph[targetVertex].x; float targetY = treeGraph[targetVertex].y; QGraphicsLineItem* lineItem = graphicsScene->addLine(sourceX, sourceY, targetX, targetY, blackPen); lineItem->setFlag(QGraphicsItem::ItemIsSelectable, false); } layout = new QHBoxLayout; layout->addWidget(graphicsView, 1); layout->setContentsMargins(0,0,0,0); setLayout(layout); graphicsView->fitInView(graphicsView->sceneRect(), Qt::KeepAspectRatioByExpanding); }
void ToolStudyArea::mousePress( QMouseEvent *mouseEvent ) { if (Qt::RightButton == mouseEvent->button()){ //# right button click, finished a loop area // draw last line segment QPointF pt = mBoundaryPts.first(); // draw temporal point // QGraphicsEllipseItem *pointItem = new QGraphicsEllipseItem( pt.x(), pt.y(), 1, 1); pointItem->setPen( QPen(Qt::red) ); mPointItems.append( pointItem ); mView->scene()->addItem( pointItem ); //# show line // draw temporal line // if ( mPrePoint.x()>=0 && mPrePoint.y()>=0 ){ QGraphicsLineItem *line = new QGraphicsLineItem( mPrePoint.x(), mPrePoint.y(), pt.x(), pt.y() ); line->setPen( QPen(Qt::green) ); mLineItems.append( line ); mView->scene()->addItem( line ); //# show line } // record new previouse point // mPrePoint.setX( -1 ); mPrePoint.setY( -1 ); // set the study area of main window and project file object // QVector<QPoint> points; for(int i=0; i<mBoundaryPts.size(); ++i){ points.append( QPoint(mBoundaryPts[i].x(), mBoundaryPts[i].y()) ); } mView->mMainWind->mInterestingArea = QPolygon( points ); mView->mMainWind->mPrjFileObj.setStudyArea( points ); // save study area to project file object mView->mMainWind->updateMask( mView->mCurrentFrame ); //update mask matrix according to polygon of study area // release, set to pan tool mView->mMainWind->releaseTool(); } else if (Qt::LeftButton == mouseEvent->button()) // left mouse button, add point and line { // add one point // save point to list QPointF pt = mView->mapToScene( QPoint(mouseEvent->x(), mouseEvent->y()) ); mBoundaryPts.append( pt ); // draw temporal point // QGraphicsEllipseItem *pointItem = new QGraphicsEllipseItem( pt.x(), pt.y(), 1, 1); pointItem->setPen( QPen(Qt::red) ); mPointItems.append( pointItem ); mView->scene()->addItem( pointItem ); //# show line // draw temporal line // if ( mPrePoint.x()>=0 && mPrePoint.y()>=0 ){ QGraphicsLineItem *line = new QGraphicsLineItem( mPrePoint.x(), mPrePoint.y(), pt.x(), pt.y() ); line->setPen( QPen(Qt::green) ); mLineItems.append( line ); mView->scene()->addItem( line ); //# show line } // record new previouse point mPrePoint.setX(pt.x()); mPrePoint.setY(pt.y()); } }
void ProfileGraphicsView::plot_cylinder_pressure(struct divecomputer *dc) { int i; int last = -1, last_index = -1; int lift_pen = FALSE; int first_plot = TRUE; int sac = 0; struct plot_data *last_entry = NULL; if (!get_cylinder_pressure_range(&gc)) return; QPointF from, to; for (i = 0; i < gc.pi.nr; i++) { int mbar; struct plot_data *entry = gc.pi.entry + i; mbar = GET_PRESSURE(entry); if (entry->cylinderindex != last_index) { lift_pen = TRUE; last_entry = NULL; } if (!mbar) { lift_pen = TRUE; continue; } if (!last_entry) { last = i; last_entry = entry; sac = get_local_sac(entry, gc.pi.entry + i + 1, dive); } else { int j; sac = 0; for (j = last; j < i; j++) sac += get_local_sac(gc.pi.entry + j, gc.pi.entry + j + 1, dive); sac /= (i - last); if (entry->sec - last_entry->sec >= SAC_WINDOW) { last++; last_entry = gc.pi.entry + last; } } QColor c = get_sac_color(sac, dive->sac); if (lift_pen) { if (!first_plot && entry->cylinderindex == last_index) { /* if we have a previous event from the same tank, * draw at least a short line */ int prev_pr; prev_pr = GET_PRESSURE(entry - 1); QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC((entry-1)->sec, prev_pr), SCALEGC(entry->sec, mbar)); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); } else { first_plot = FALSE; from = QPointF(SCALEGC(entry->sec, mbar)); } lift_pen = FALSE; } else { to = QPointF(SCALEGC(entry->sec, mbar)); QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); } from = QPointF(SCALEGC(entry->sec, mbar)); last_index = entry->cylinderindex; } }
void ProfileGraphicsView::plot_pp_gas_profile() { int i; struct plot_data *entry; struct plot_info *pi = &gc.pi; setup_pp_limits(&gc); QColor c; QPointF from, to; if (prefs.pp_graphs.pn2) { c = profile_color[PN2].first(); entry = pi->entry; from = QPointF(SCALEGC(entry->sec, entry->pn2)); for (i = 1; i < pi->nr; i++) { entry++; if (entry->pn2 < prefs.pp_graphs.pn2_threshold) { to = QPointF(SCALEGC(entry->sec, entry->pn2)); QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); from = to; } else { from = QPointF(SCALEGC(entry->sec, entry->pn2)); } } c = profile_color[PN2_ALERT].first(); entry = pi->entry; from = QPointF(SCALEGC(entry->sec, entry->pn2)); for (i = 1; i < pi->nr; i++) { entry++; if (entry->pn2 >= prefs.pp_graphs.pn2_threshold) { to = QPointF(SCALEGC(entry->sec, entry->pn2)); QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); from = to; } else { from = QPointF(SCALEGC(entry->sec, entry->pn2)); } } } if (prefs.pp_graphs.phe) { c = profile_color[PHE].first(); entry = pi->entry; from = QPointF(SCALEGC(entry->sec, entry->phe)); for (i = 1; i < pi->nr; i++) { entry++; if (entry->phe < prefs.pp_graphs.phe_threshold) { to = QPointF(SCALEGC(entry->sec, entry->phe)); QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); from = to; } else { from = QPointF(SCALEGC(entry->sec, entry->phe)); } } c = profile_color[PHE_ALERT].first(); entry = pi->entry; from = QPointF(SCALEGC(entry->sec, entry->phe)); for (i = 1; i < pi->nr; i++) { entry++; if (entry->phe >= prefs.pp_graphs.phe_threshold) { to = QPointF(SCALEGC(entry->sec, entry->phe)); QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); from = to; } else { from = QPointF(SCALEGC(entry->sec, entry->phe)); } } } if (prefs.pp_graphs.po2) { c = profile_color[PO2].first(); entry = pi->entry; from = QPointF(SCALEGC(entry->sec, entry->po2)); for (i = 1; i < pi->nr; i++) { entry++; if (entry->po2 < prefs.pp_graphs.po2_threshold) { to = QPointF(SCALEGC(entry->sec, entry->po2)); QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); from = to; } else { from = QPointF(SCALEGC(entry->sec, entry->po2)); } } c = profile_color[PO2_ALERT].first(); entry = pi->entry; from = QPointF(SCALEGC(entry->sec, entry->po2)); for (i = 1; i < pi->nr; i++) { entry++; if (entry->po2 >= prefs.pp_graphs.po2_threshold) { to = QPointF(SCALEGC(entry->sec, entry->po2)); QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y()); item->setPen(QPen(c)); scene()->addItem(item); from = to; } else { from = QPointF(SCALEGC(entry->sec, entry->po2)); } } } }
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 PacketsScene::addPacket (qreal tx, qreal rx, uint32_t fromNodeId, uint32_t toNodeId, QString metaInfo, bool drawPacket) { QString shortMeta = ""; if (m_filter != AnimPacket::ALL) { bool result; shortMeta = AnimPacket::getMeta (metaInfo, m_filter, result, false); if (!result) return; } else { shortMeta = AnimPacket::getMeta (metaInfo, false); } QRegExp rex (m_filterRegex); if (rex.indexIn (metaInfo) == -1) { return; } qreal txY = 0; qreal rxY = 0; if (drawPacket && m_showGraph) { qreal fromNodeX = m_interNodeSpacing * m_lineIndex[fromNodeId]; qreal toNodeX = m_interNodeSpacing * m_lineIndex[toNodeId]; txY = timeToY (tx); rxY = timeToY (rx); GraphPacket * graphPacket = new GraphPacket (QPointF (fromNodeX, txY), QPointF (toNodeX, rxY)); //addItem (graphPacket); m_packetPath.moveTo (graphPacket->line ().p1 ()); m_packetPath.lineTo (graphPacket->line ().p2 ()); qreal angle = 45; qreal mag = 9; QPointF endPoint (graphPacket->line ().p2 ()); if (1) { if (graphPacket->line ().angle () > 270) { m_packetPath.moveTo (endPoint); angle += graphPacket->line ().angle (); //NS_LOG_DEBUG ("Angle:" << graphPacket->line ().angle () << " Final Angle:" << angle); m_packetPath.lineTo (endPoint.x () - mag * cos (angle * PI/180), endPoint.y () - mag * sin (angle * PI/180)); m_packetPath.moveTo (endPoint); m_packetPath.lineTo (endPoint.x () - mag * cos (angle * PI/180), endPoint.y () + mag * sin (angle * PI/180)); } else if (graphPacket->line ().angle () > 180) { m_packetPath.moveTo (endPoint); angle += 180 - graphPacket->line ().angle (); //NS_LOG_DEBUG ("Angle:" << graphPacket->line ().angle () << " Final Angle:" << angle); m_packetPath.lineTo (endPoint.x () + mag * cos (angle * PI/180), endPoint.y () - mag * sin (angle * PI/180)); m_packetPath.moveTo (endPoint); m_packetPath.lineTo (endPoint.x () + mag * cos (angle * PI/180), endPoint.y () + mag * sin (angle * PI/180)); } } m_packetPathItem->setPath (m_packetPath); m_packetLines.push_back (graphPacket); QGraphicsSimpleTextItem * info = new QGraphicsSimpleTextItem (shortMeta); addItem (info); m_packetInfoTexts.push_back (info); info->setFlag (QGraphicsItem::ItemIgnoresTransformations); info->setPos (QPointF (fromNodeX, txY)); qreal textAngle = graphPacket->line().angle (); if(textAngle < 90) { textAngle = 360-textAngle; } else if (textAngle > 270) { textAngle = 360-textAngle; } else { textAngle = 180-textAngle; info->setPos (QPointF (toNodeX, rxY)); } info->setTransform (QTransform ().rotate (textAngle)); } Table * table = PacketsMode::getInstance ()->getTable (); QStringList sl; sl << QString::number (fromNodeId) << QString::number (toNodeId) << QString::number (tx) << shortMeta; table->addRow (sl); if (m_showGrid && drawPacket && m_showGraph) { QGraphicsSimpleTextItem * txText = new QGraphicsSimpleTextItem (QString::number (tx)); txText->setFlag (QGraphicsItem::ItemIgnoresTransformations); addItem (txText); txText->setPos (RULER_X, txY); QPen pen (QColor (200, 100, 155, 100)); QGraphicsLineItem * horizontalTxLine = new QGraphicsLineItem (RULER_X, txY, m_interNodeSpacing * m_lineIndex.size (), txY); QGraphicsLineItem * horizontalRxLine = new QGraphicsLineItem (RULER_X, rxY, m_interNodeSpacing * m_lineIndex.size (), rxY); horizontalTxLine->setPen (pen); horizontalRxLine->setPen (pen); addItem (horizontalTxLine); addItem (horizontalRxLine); QGraphicsSimpleTextItem * rxText = new QGraphicsSimpleTextItem (QString::number (rx)); addItem (rxText); rxText->setFlag (QGraphicsItem::ItemIgnoresTransformations); rxText->setPos (RULER_X, rxY); //graphPacket->setPos (QPointF (fromNodeX, txY)); m_rulerTexts.push_back (txText); m_rulerTexts.push_back (rxText); m_horizontalRulerLines.push_back (horizontalTxLine); m_horizontalRulerLines.push_back (horizontalRxLine); } }
void PSV_TreeItem::paintLine(const QLineF &parentVLine, PSV_TreeItemData *itemData) { if(itemData == NULL) { return; } QPointF point2 = parentVLine.p2(); QList<PSV_TreeItemData*> children = itemData->children(); int leafCount = itemData->leafCount(); int count = children.count(); QPen pen; pen.setColor(QColor(Qt::red)); QPen pen_vLine; pen_vLine.setColor(QColor(Qt::blue)); QPen pen_hLine; QString tempText = itemData->text().trimmed(); QString text; for(int i = 0; i < tempText.length(); ++i) { text.append(tempText.at(i)); if(i != tempText.length() - 1) { text.append("\n"); } } QGraphicsItem* nodeItem = new QGraphicsEllipseItem(QRectF(0,0,1,1),this); nodeItem->setToolTip(tempText); QSizeF size = nodeItem->boundingRect().size(); nodeItem->setPos(point2.x() - size.width() * 0.5,point2.y() - size.height() * 0.5); QRectF rect = QRectF(nodeItem->pos().x(),nodeItem->pos().y(),size.width(),size.height()); // QGraphicsRectItem* rectItem = new QGraphicsRectItem(rect,this); // rectItem->setPen(pen); if(parentVLine.length() > PSV_ZEOR) { QLineF line = parentVLine; line.setP2(QPointF(line.x2(),rect.top())); QGraphicsLineItem* item = new QGraphicsLineItem(line,this); PSV_NOUSED(item); } if(count > 0) { QLineF leftHLine(point2.x() - leafCount * 0.5 * m_dw ,point2.y() ,rect.left() ,point2.y()); QLineF rightHLine(rect.right() ,point2.y() ,point2.x() + leafCount * 0.5 * m_dw ,point2.y()); double curX1 = leftHLine.x1(); for(int i = 0; i < count; ++i) { PSV_TreeItemData* tempItemData = children.at(i); int tempLeafCount = tempItemData->leafCount(); curX1 += tempLeafCount * 0.5 * m_dw; if(i == 0) { leftHLine.setP1(QPointF(curX1,leftHLine.y1())); } if(i == count - 1) { rightHLine.setP2(QPointF(curX1,leftHLine.y2())); } double y1 = point2.y(); double y2 = point2.y() + tempItemData->distance() * m_dhRatio; if(curX1 > rect.left() && curX1 < rect.right()) { y1 = rect.bottom(); } QLineF lineV(curX1,y1,curX1,y2); curX1 += tempLeafCount * 0.5 * m_dw; paintLine(lineV,tempItemData); } if(count > 1) { QGraphicsLineItem* leftHLineItem = new QGraphicsLineItem(leftHLine,this); leftHLineItem->setPen(pen_hLine); QGraphicsLineItem* rightHLineItem = new QGraphicsLineItem(rightHLine,this); rightHLineItem->setPen(pen_hLine); } } }
Game::Game(): QGraphicsView(){ move_timer = new QTimer(this); move_timer->start(20); //create a scene scene = new QGraphicsScene(this); scene->setSceneRect(0,0,920,720); //set the scene setScene(scene); //set cursor cursor = nullptr; building = nullptr; setMouseTracking(true); //alter window setFixedSize(920,720); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //split screen into playfield and menu field_menu << QPointF(720,0) << QPointF(720,720); for(size_t i=0, n = field_menu.size()-1; i < n; i++){ //create a line QLineF line(field_menu[i],field_menu[i+1]); QGraphicsLineItem * lineItem = new QGraphicsLineItem(line); QPen pen; pen.setWidth(5); pen.setColor(Qt::black); lineItem->setPen(pen); scene->addItem(lineItem); } //create gridpoints for(gPoint_x=0; gPoint_x<20; gPoint_x++){ for(gPoint_y=0; gPoint_y<20; gPoint_y++){ Gridpoint *gPoint = new Gridpoint; gPoint->setPos(x()+12+(36*gPoint_x),y()+12+(36*gPoint_y)); scene->addItem(gPoint); } } //creat enemy spawnTimer = new QTimer(this); enemiesSpawned = 0; maxNumberOfEnemies = 0; pointsToFollow << QPointF(18,18) << QPointF(18,414) << QPointF(198,414)<< QPointF(594,414) << QPointF(594,54) << QPointF(800,54)<< QPointF(594,54); for(int i=0;i<=(pointsToFollow.length()-2);i++){ QPointF temp; double test; temp=((pointsToFollow[i+1])-(pointsToFollow[i])); temp=temp; direction[i][0]=temp.x()/(sqrt(pow(temp.x(),2)+pow(temp.y(),2))); direction[i][1]=temp.y()/(sqrt(pow(temp.x(),2)+pow(temp.y(),2))); } createEnemies(20); //create Road createRoad(); //create Tower-Icon BuildRedTowerIcon * rt = new BuildRedTowerIcon(); BuildGreenTowerIcon * gt = new BuildGreenTowerIcon(); BuildBlueTowerIcon * bt = new BuildBlueTowerIcon(); BuildBlackTowerIcon * bkt = new BuildBlackTowerIcon(); BuildWhiteTowerIcon * wt = new BuildWhiteTowerIcon(); BuildYellowTowerIcon * yt = new BuildYellowTowerIcon(); //move tower icons rt->setPos(x()+850,y()); gt->setPos(x()+850,y()+50); bt->setPos(x()+850,y()+100); bkt->setPos(x()+850,y()+150); yt->setPos(x()+850,y()+200); wt->setPos(x()+850,y()+250); scene->addItem(rt); scene->addItem(gt); scene->addItem(bt); scene->addItem(bkt); scene->addItem(yt); scene->addItem(wt); }
RaceViewer::RaceViewer(const QList<GeoCoordinate> &racePoints, QWidget *parent) : QDialog(parent), mPoints(racePoints) { const int ratio = 300 * 1000; scene = new QGraphicsScene(this); view = new ResizableView(this); view->setScene(scene); view->scale(ratio, -ratio); QPointF prev = racePoints.at(0).projection(); QPointF cur; int j = 1; while (j < mPoints.size()) { cur = mPoints.at(j).projection(); if (prev != cur) { QGraphicsLineItem* segment; segment = scene->addLine(prev.x(), prev.y(), cur.x(), cur.y()); segment->setData(0, j - 1); prev = cur; j++; } else { mPoints.removeAt(j); } } qDebug() << j; QPointF first = racePoints.at(0).projection(); marker = new ExtensibleEllipseItem; marker->setRect(first.x(), first.y(), 4 / 10000.0, 4 / 10000.0); marker->moveBy(-2 / 10000.0, -2 / 10000.0); marker->setFlag(QGraphicsItem::ItemIsMovable, true); marker->setBrush(QColor(255, 0, 0, 127)); marker->setZValue(100); scene->addItem(marker); QPushButton* okButton = new QPushButton(tr("Ok")); connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); QPushButton* cancelButton = new QPushButton(tr("Annuler")); connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); QHBoxLayout* viewerLayout = new QHBoxLayout; viewerLayout->addWidget(view); QHBoxLayout* buttonLayout = new QHBoxLayout; buttonLayout->addWidget(cancelButton); buttonLayout->addWidget(okButton); QVBoxLayout* topLayout = new QVBoxLayout; topLayout->addLayout(viewerLayout); topLayout->addLayout(buttonLayout); setLayout(topLayout); }
void ProfileGraphicsView::plot_depth_profile() { int i, incr; int sec, depth; struct plot_data *entry; int maxtime, maxdepth, marker, maxline; int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 }; /* Get plot scaling limits */ maxtime = get_maxtime(&gc.pi); maxdepth = get_maxdepth(&gc.pi); gc.maxtime = maxtime; /* Time markers: at most every 10 seconds, but no more than 12 markers. * We start out with 10 seconds and increment up to 30 minutes, * depending on the dive time. * This allows for 6h dives - enough (I hope) for even the craziest * divers - but just in case, for those 8h depth-record-breaking dives, * we double the interval if this still doesn't get us to 12 or fewer * time markers */ i = 0; while (maxtime / increments[i] > 12 && i < 7) i++; incr = increments[i]; while (maxtime / incr > 12) incr *= 2; gc.leftx = 0; gc.rightx = maxtime; gc.topy = 0; gc.bottomy = 1.0; last_gc = gc; QColor c = getColor(TIME_GRID); for (i = incr; i < maxtime; i += incr) { QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(i, 0), SCALEGC(i, 1)); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); } timeMarkers = new QGraphicsRectItem(); /* now the text on the time markers */ struct text_render_options tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, LINE_DOWN}; if (maxtime < 600) { /* Be a bit more verbose with shorter dives */ for (i = incr; i < maxtime; i += incr) plot_text(&tro, QPointF(i, 0), QString("%1:%2").arg(i/60).arg(i%60, 2, 10, QChar('0')), timeMarkers); } else { /* Only render the time on every second marker for normal dives */ for (i = incr; i < maxtime; i += 2 * incr) plot_text(&tro, QPointF(i, 0), QString("%1").arg(QString::number(i/60)), timeMarkers); } timeMarkers->setPos(0,0); scene()->addItem(timeMarkers); /* Depth markers: every 30 ft or 10 m*/ gc.leftx = 0; gc.rightx = 1.0; gc.topy = 0; gc.bottomy = maxdepth; switch (prefs.units.length) { case units::METERS: marker = 10000; break; case units::FEET: marker = 9144; break; /* 30 ft */ } maxline = qMax(gc.pi.maxdepth + marker, maxdepth * 2 / 3); c = getColor(DEPTH_GRID); for (i = marker; i < maxline; i += marker) { QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, i), SCALEGC(1, i)); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); } gc.leftx = 0; gc.rightx = maxtime; c = getColor(MEAN_DEPTH); /* Show mean depth */ if (! gc.printer) { QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, gc.pi.meandepth), SCALEGC(gc.pi.entry[gc.pi.nr - 1].sec, gc.pi.meandepth)); QPen pen(defaultPen); pen.setColor(c); item->setPen(pen); scene()->addItem(item); } #if 0 /* * These are good for debugging text placement etc, * but not for actual display.. */ if (0) { plot_smoothed_profile(gc, pi); plot_minmax_profile(gc, pi); } #endif /* Do the depth profile for the neat fill */ gc.topy = 0; gc.bottomy = maxdepth; entry = gc.pi.entry; QPolygonF p; QLinearGradient pat(0.0,0.0,0.0,scene()->height()); QGraphicsPolygonItem *neatFill = NULL; p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) p.append(QPointF(SCALEGC(entry->sec, entry->depth))); /* Show any ceiling we may have encountered */ if (prefs.profile_dc_ceiling) { for (i = gc.pi.nr - 1; i >= 0; i--, entry--) { if (!entry->in_deco) { /* not in deco implies this is a safety stop, no ceiling */ p.append(QPointF(SCALEGC(entry->sec, 0))); } else if (entry->stopdepth < entry->depth) { p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth))); } else { p.append(QPointF(SCALEGC(entry->sec, entry->depth))); } } } pat.setColorAt(1, getColor(DEPTH_BOTTOM)); pat.setColorAt(0, getColor(DEPTH_TOP)); neatFill = new QGraphicsPolygonItem(); neatFill->setPolygon(p); neatFill->setBrush(QBrush(pat)); neatFill->setPen(QPen(QBrush(Qt::transparent),0)); scene()->addItem(neatFill); /* if the user wants the deco ceiling more visible, do that here (this * basically draws over the background that we had allowed to shine * through so far) */ if (prefs.profile_dc_ceiling && prefs.profile_red_ceiling) { p.clear(); pat.setColorAt(0, getColor(CEILING_SHALLOW)); pat.setColorAt(1, getColor(CEILING_DEEP)); entry = gc.pi.entry; p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) { if (entry->in_deco && entry->stopdepth) { if (entry->stopdepth < entry->depth) { p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth))); } else { p.append(QPointF(SCALEGC(entry->sec, entry->depth))); } } else { p.append(QPointF(SCALEGC(entry->sec, 0))); } } neatFill = new QGraphicsPolygonItem(); neatFill->setBrush(QBrush(pat)); neatFill->setPolygon(p); neatFill->setPen(QPen(QBrush(Qt::NoBrush),0)); scene()->addItem(neatFill); } /* finally, plot the calculated ceiling over all this */ if (prefs.profile_calc_ceiling) { pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW)); pat.setColorAt(1, getColor(CALC_CEILING_DEEP)); entry = gc.pi.entry; p.clear(); p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) { if (entry->ceiling) p.append(QPointF(SCALEGC(entry->sec, entry->ceiling))); else p.append(QPointF(SCALEGC(entry->sec, 0))); } p.append(QPointF(SCALEGC((entry-1)->sec, 0))); neatFill = new QGraphicsPolygonItem(); neatFill->setPolygon(p); neatFill->setPen(QPen(QBrush(Qt::NoBrush),0)); neatFill->setBrush(pat); scene()->addItem(neatFill); } /* plot the calculated ceiling for all tissues */ if (prefs.profile_calc_ceiling && prefs.calc_all_tissues) { int k; for (k=0; k<16; k++) { pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW)); pat.setColorAt(1, QColor(100, 100, 100, 50)); entry = gc.pi.entry; p.clear(); p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) { if ((entry->ceilings)[k]) p.append(QPointF(SCALEGC(entry->sec, (entry->ceilings)[k]))); else p.append(QPointF(SCALEGC(entry->sec, 0))); } p.append(QPointF(SCALEGC((entry-1)->sec, 0))); neatFill = new QGraphicsPolygonItem(); neatFill->setPolygon(p); neatFill->setBrush(pat); scene()->addItem(neatFill); } } /* next show where we have been bad and crossed the dc's ceiling */ if (prefs.profile_dc_ceiling) { pat.setColorAt(0, getColor(CEILING_SHALLOW)); pat.setColorAt(1, getColor(CEILING_DEEP)); entry = gc.pi.entry; p.clear(); p.append(QPointF(SCALEGC(0, 0))); for (i = 0; i < gc.pi.nr; i++, entry++) p.append(QPointF(SCALEGC(entry->sec, entry->depth))); for (i-- , entry--; i >= 0; i--, entry--) { if (entry->in_deco && entry->stopdepth > entry->depth) { p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth))); } else { p.append(QPointF(SCALEGC(entry->sec, entry->depth))); } } } neatFill = new QGraphicsPolygonItem(); neatFill->setPolygon(p); neatFill->setPen(QPen(QBrush(Qt::NoBrush),0)); neatFill->setBrush(QBrush(pat)); scene()->addItem(neatFill); /* Now do it again for the velocity colors */ entry = gc.pi.entry; for (i = 1; i < gc.pi.nr; i++) { entry++; sec = entry->sec; /* we want to draw the segments in different colors * representing the vertical velocity, so we need to * chop this into short segments */ depth = entry->depth; QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(entry[-1].sec, entry[-1].depth), SCALEGC(sec, depth)); QPen pen(defaultPen); pen.setColor(getColor((color_indice_t)(VELOCITY_COLORS_START_IDX + entry->velocity))); item->setPen(pen); scene()->addItem(item); } }
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 DlgSettingsColorFilter::updateHistogram() { LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsColorFilter::updateHistogram"; enableOk (true); const double PEN_WIDTH = 0.0; // Zero value gives one-pixel width at all scales QString curveName = m_cmbCurveName->currentText(); m_sceneProfile->clear(); m_scale->setColorFilterMode (m_modelColorFilterAfter->colorFilterMode(curveName)); // Start with original image QImage image = cmdMediator().document().pixmap().toImage(); double *histogramBins = new double [ColorFilterHistogram::HISTOGRAM_BINS ()]; ColorFilter filter; ColorFilterHistogram filterHistogram; int maxBinCount; filterHistogram.generate (filter, histogramBins, m_modelColorFilterAfter->colorFilterMode (curveName), image, maxBinCount); // Draw histogram, normalizing so highest peak exactly fills the vertical range. Log scale is used // so smaller peaks do not disappear double logMaxBinCount = qLn (maxBinCount); for (int bin = 1; bin < ColorFilterHistogram::HISTOGRAM_BINS (); bin++) { double x0 = PROFILE_SCENE_WIDTH () * (bin - 1.0) / (ColorFilterHistogram::HISTOGRAM_BINS () - 1.0); // Map logPixelCount through 0 to 0 through PROFILE_SCENE_HEIGHT-1, using log scale double count0 = 1.0 + histogramBins [bin - 1]; double y0 = (PROFILE_SCENE_HEIGHT () - 1.0) * (1.0 - qLn (count0) / logMaxBinCount); double x1 = PROFILE_SCENE_WIDTH () * (bin - 0.0) / (ColorFilterHistogram::HISTOGRAM_BINS () - 1.0); // Map logPixelCount through 0 to 0 through PROFILE_SCENE_HEIGHT-1, using log scale double count1 = 1.0 + histogramBins [bin]; double y1 = (PROFILE_SCENE_HEIGHT () - 1.0) * (1.0 - qLn (count1) / logMaxBinCount); QGraphicsLineItem *line = new QGraphicsLineItem (x0, y0, x1, y1); line->setPen (QPen (QBrush (Qt::black), PEN_WIDTH)); m_sceneProfile->addItem (line); } // Create low and high dividers m_dividerLow = new ViewProfileDivider(*m_sceneProfile, *m_viewProfile, PROFILE_SCENE_WIDTH (), PROFILE_SCENE_HEIGHT (), PROFILE_SCENE_HEIGHT () * 2.0 / 3.0, true); m_dividerHigh = new ViewProfileDivider(*m_sceneProfile, *m_viewProfile, PROFILE_SCENE_HEIGHT (), PROFILE_SCENE_WIDTH (), PROFILE_SCENE_HEIGHT () / 3.0, false); // Connect the dividers to each other since the shaded areas depend on both divides when low divider is // moved to the right of the high divider connect (m_dividerLow, SIGNAL (signalMovedLow (double)), m_dividerHigh, SLOT (slotOtherMoved(double))); connect (m_dividerHigh, SIGNAL (signalMovedHigh (double)), m_dividerLow, SLOT (slotOtherMoved(double))); // Update preview when the dividers move connect (m_dividerLow, SIGNAL (signalMovedLow (double)), this, SLOT (slotDividerLow (double))); connect (m_dividerHigh, SIGNAL(signalMovedHigh (double)), this, SLOT (slotDividerHigh (double))); if (m_btnForeground->isChecked()) { // Foreground m_dividerLow->setX (m_modelColorFilterAfter->foregroundLow(curveName), FOREGROUND_MIN, FOREGROUND_MAX); m_dividerHigh->setX (m_modelColorFilterAfter->foregroundHigh(curveName), FOREGROUND_MIN, FOREGROUND_MAX); } else if (m_btnIntensity->isChecked()) { // Intensity m_dividerLow->setX (m_modelColorFilterAfter->intensityLow(curveName), INTENSITY_MIN, INTENSITY_MAX); m_dividerHigh->setX (m_modelColorFilterAfter->intensityHigh(curveName), INTENSITY_MIN, INTENSITY_MAX); } else if (m_btnHue->isChecked()) { // Hue m_dividerLow->setX (m_modelColorFilterAfter->hueLow(curveName), HUE_MIN, HUE_MAX); m_dividerHigh->setX (m_modelColorFilterAfter->hueHigh(curveName), HUE_MIN, HUE_MAX); } else if (m_btnSaturation->isChecked()) { // Saturation m_dividerLow->setX (m_modelColorFilterAfter->saturationLow(curveName), SATURATION_MIN, SATURATION_MAX); m_dividerHigh->setX (m_modelColorFilterAfter->saturationHigh(curveName), SATURATION_MIN, SATURATION_MAX); } else if (m_btnValue->isChecked()) { // Value m_dividerLow->setX (m_modelColorFilterAfter->valueLow(curveName), VALUE_MIN, VALUE_MAX); m_dividerHigh->setX (m_modelColorFilterAfter->valueHigh(curveName), VALUE_MIN, VALUE_MAX); } else { ENGAUGE_ASSERT (false); } free (histogramBins); }
void StitcherView::mouseReleaseEvent( QMouseEvent * event){ ImageView::mouseReleaseEvent(event); if(mode == Line && event->button() & Qt::LeftButton){ setMode(Default); QGraphicsLineItem * line = new QGraphicsLineItem(QLineF(mapToScene(lineOrigin),mapToScene(lineEnd))); line->setData(0,QString("Helper")); line->setZValue(11); QPen pen = line->pen(); pen.setColor(Qt::white); pen.setStyle(Qt::SolidLine); line->setPen(pen); graphicsScene->addItem(line); }else if(mode == Circle && event->button() & Qt::LeftButton){ setMode(Default); QPointF lineOriginF = mapToScene(lineOrigin); QPointF lineEndF = mapToScene(lineEnd); QPointF circleCenter = (lineOriginF+lineEndF)/2; qreal circleRadius = sqrt((lineOriginF-lineEndF).x()* (lineOriginF-lineEndF).x()+ (lineOriginF-lineEndF).y()* (lineOriginF-lineEndF).y())/2; if(QApplication::keyboardModifiers() & Qt::ShiftModifier){ circleCenter = mapFromScene(QPointF(0,0)); circleRadius = sqrt((circleCenter-lineEnd).x()* (circleCenter-lineEnd).x()+ (circleCenter-lineEnd).y()* (circleCenter-lineEnd).y()); circleCenter = QPointF(0,0); } QGraphicsEllipseItem * circle = new QGraphicsEllipseItem(QRect(circleCenter.x()-circleRadius,circleCenter.y()-circleRadius,circleRadius*2,circleRadius*2)); circle->setData(0,QString("Helper")); circle->setZValue(11); QPen pen = circle->pen(); pen.setColor(Qt::white); pen.setStyle(Qt::SolidLine); circle->setPen(pen); graphicsScene->addItem(circle); }else if(mode == AddPoint && event->button() & Qt::LeftButton){ QList<QGraphicsItem *> it = items(event->pos()); for(int i = 0; i < it.size(); i++){ if(ImageItem * item = qgraphicsitem_cast<ImageItem *>(it.at(i))){ item->addControlPoint(item->mapFromScene(mapToScene(event->pos()))); } } }else if(mode == DeletePoint && event->button() & Qt::LeftButton){ QList<QGraphicsItem *> it = items(event->pos()); for(int i = 0; i < it.size(); i++){ if(ImageItem * item = qgraphicsitem_cast<ImageItem *>(it.at(i))){ item->deleteControlPoint(item->mapFromScene(mapToScene(event->pos()))); } } }else if(mode == DeleteGuide && event->button() & Qt::LeftButton){ QList<QGraphicsItem *> it = items(event->pos()); QPointF pos = mapToScene(event->pos()); /* 10 px tolerance radius, delete the closest */ for(int i = 0; i < it.size(); i++){ if(QString("Helper") == it[i]->data(0)){ QGraphicsEllipseItem * elipse = qgraphicsitem_cast<QGraphicsEllipseItem *>(it[i]); if(elipse){ // Check if click position close to the line QPointF origin = elipse->rect().center(); qreal radius = elipse->rect().height()/2; QPointF d = origin-pos; if(abs(sqrt(d.x()*d.x()+d.y()*d.y())-radius) < 10){ delete elipse; } } QGraphicsLineItem * line = qgraphicsitem_cast<QGraphicsLineItem *>(it[i]); if(line){ delete line; } } } } }
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 GridFromFloat::draw() { SLM_TRACE_FUNC(); SLM_ASSERT("m_xSpacing can not equal 0", m_xSpacing != 0); SLM_ASSERT("m_ySpacing can not equal 0", m_ySpacing != 0); // Remove all lines from the scene for (std::vector<QGraphicsItem*>::iterator it = m_lines.begin(); it != m_lines.end(); ++it) { this->getScene2DRender()->getScene()->removeItem(*it); } // Clear the lines vector m_lines.clear(); // Calculate the start, end and step on x for the lines float xStartVal = (int)( m_xMin / m_xSpacing ) * m_xSpacing; float xEndVal = (int)( m_xMax / m_xSpacing ) * m_xSpacing; float xStep = m_xSpacing; // Calculate the start, end and step on y for the lines float yStartVal = (int)( m_yMin / m_ySpacing ) * m_ySpacing; float yEndVal = (int)( m_yMax / m_ySpacing ) * m_ySpacing; float yStep = m_ySpacing; // Draw the horizontal lines for ( float yVal = yStartVal ; yVal <= yEndVal ; yVal += yStep ) { QGraphicsLineItem* line = new QGraphicsLineItem( this->mapAdaptorToScene(std::pair< double , double >( xStartVal, yVal) , m_xAxis, m_yAxis).first, this->mapAdaptorToScene(std::pair< double , double >( xStartVal, yVal) , m_xAxis, m_yAxis).second, this->mapAdaptorToScene(std::pair< double , double >( xEndVal, yVal) , m_xAxis, m_yAxis).first, this->mapAdaptorToScene(std::pair< double , double >( xEndVal, yVal) , m_xAxis, m_yAxis).second ); // Set the line the pen and push it back in to the lines vector line->setPen(m_pen); m_lines.push_back(line); } // Draw the vertical lines for ( float xVal = xStartVal ; xVal <= xEndVal ; xVal += xStep ) { QGraphicsLineItem* line = new QGraphicsLineItem( this->mapAdaptorToScene(std::pair< double , double >( xVal, yStartVal) , m_xAxis, m_yAxis).first, this->mapAdaptorToScene(std::pair< double , double >( xVal, yStartVal) , m_xAxis, m_yAxis).second, this->mapAdaptorToScene(std::pair< double , double >( xVal, yEndVal) , m_xAxis, m_yAxis).first, this->mapAdaptorToScene(std::pair< double , double >( xVal, yEndVal) , m_xAxis, m_yAxis).second ); // Set the line the pen and push it back in to the lines vector line->setPen(m_pen); m_lines.push_back(line); } // Add the lines contained in the lines vector to the layer for ( unsigned int i = 0 ; i < m_lines.size() ; i++) { m_layer->addToGroup(m_lines.at(i)); } // Set the layer position (according to the related axis) and zValue m_layer->setPos(m_xAxis->getOrigin(), m_yAxis->getOrigin()); m_layer->setZValue(m_zValue); // Add the layer to the scene this->getScene2DRender()->getScene()->addItem(m_layer); }
void repere::Teste() { QPolygonF box1; box1 << QPointF(50,50)<< QPointF(80,50)<< QPointF(80,60)<< QPointF(70,60)<< QPointF(70,70)<< QPointF(50,70); QGraphicsPolygonItem *P; P=Scene->addPolygon(box1,QPen(Qt::darkGray),QBrush(Qt::darkGray)); QPolygonF box2; box2 << QPointF(20,20)<< QPointF(51,20)<< QPointF(51,51)<< QPointF(20,51); QGraphicsPolygonItem *P2; P2=Scene->addPolygon(box2,QPen(Qt::red),QBrush(Qt::red)); //P->collidingItems() qDebug()<< P->collidesWithItem(P2); QPainterPath s,s2,s3; s= P->shape(); s2=P2->shape(); //Scene->addPath(s,QPen(Qt::magenta),QBrush(Qt::yellow)); Scene->addText("o")->setPos(85,85); QGraphicsLineItem *l; l=Scene->addLine(90,65,70,65,QPen(Qt::red)); s2=l->shape(); qDebug()<< "intersects: "<<s.intersects(s2); //qDebug()<< "intersected: "<<s.intersected(s2); s3=s.intersected(s2); Scene->addLine(50,65,50,65,QPen(Qt::green)); Scene->addLine(70,65,70,65,QPen(Qt::green)); qDebug()<< "intersected2:"<<P->shape().intersected(l->shape()).elementAt(1)<<s3.elementAt(1); qDebug()<< "intersected a:"<<P->shape().intersected(l->shape()); qDebug()<< "intersected b:"<<l->shape().intersected(P->shape()); vector<QGraphicsPolygonItem*> obstaculos; obstaculos.push_back(P); obstaculos.push_back(P2); /* QImage *image = new QImage(QSize(400,400),QImage::Format_ARGB32); image->fill(QColor(Qt::white).rgb()); QPainter *pngPainter = new QPainter(image); pngPainter->setRenderHint(QPainter::Antialiasing); Scene->render(pngPainter); pngPainter->end(); image->setText(); //image->save(nom+".png","PNG",100); */ }
void AnimatorScene::setShowInterfaceTexts (bool showIp, bool showMac) { resetInterfaceTexts (); m_showIpInterfaceTexts = showIp; m_showMacInterfaceTexts = showMac; if (!m_showIpInterfaceTexts && !m_showMacInterfaceTexts) { return; } if (!m_interfaceATexts.size ()) { for (LinkManager::NodeIdAnimLinkVectorMap_t::const_iterator i = LinkManager::getInstance ()->getLinks ()->begin (); i != LinkManager::getInstance ()->getLinks ()->end (); ++i) { LinkManager::AnimLinkVector_t linkVector = i->second; for (LinkManager::AnimLinkVector_t::const_iterator j = linkVector.begin (); j != linkVector.end (); ++j) { AnimLink * animLink = *j; QString pointADescription = animLink->getInterfaceADescription (); QPointF pointApos = animLink->getInterfacePosA (); AnimInterfaceText * interfaceAText = new AnimInterfaceText (pointADescription); interfaceAText->setPos (pointApos); addItem (interfaceAText); m_interfaceATexts.push_back (interfaceAText); interfaceAText->setMode (m_showIpInterfaceTexts, m_showMacInterfaceTexts); QString pointBDescription = animLink->getInterfaceBDescription (); if (pointBDescription == "") { continue; } QPointF pointBpos = animLink->getInterfacePosB (); AnimInterfaceText * interfaceBText = new AnimInterfaceText (pointBDescription, true); interfaceBText->setMode (m_showIpInterfaceTexts, m_showMacInterfaceTexts); addItem (interfaceBText); interfaceBText->setPos (pointBpos); m_interfaceBTexts.push_back (interfaceBText); } } update (); removeInterfaceTextCollision (); return; } for (AnimInterfaceTextVector_t::const_iterator i = m_interfaceATexts.begin (); i != m_interfaceATexts.end (); ++i) { AnimInterfaceText * interfaceText = *i; interfaceText->setMode (m_showIpInterfaceTexts, m_showMacInterfaceTexts); QGraphicsLineItem * l = interfaceText->getLine (); if (l) { l->setVisible (showIp || showMac); } interfaceText->setVisible (showIp || showMac); } for (AnimInterfaceTextVector_t::const_iterator i = m_interfaceBTexts.begin (); i != m_interfaceBTexts.end (); ++i) { AnimInterfaceText * interfaceText = *i; interfaceText->setMode (m_showIpInterfaceTexts, m_showMacInterfaceTexts); QGraphicsLineItem * l = interfaceText->getLine (); if (l) { l->setVisible (showIp || showMac); } interfaceText->setVisible (showIp || showMac); } removeInterfaceTextCollision (); update (); }
void TerrainProfileGraph::drawHoverCursor(const QPointF& position) { if (_hoverLine) { _scene->removeItem(_hoverLine); delete _hoverLine; _hoverLine = 0L; } if (_graphField.width() < 2 || _graphField.height() < 2) return; double xPos = position.x() < _graphField.x() ? _graphField.x() : (position.x() > _graphField.x() + _graphField.width() ? _graphField.x() + _graphField.width() : position.x()); QLineF vLine(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height()); QPointF* intersect = new QPointF; bool foundIntersect = false; for (int i=0; i < _graphLines.count(); i++) { if (vLine.intersect(_graphLines[i], intersect) == QLineF::BoundedIntersection) { foundIntersect = true; break; } } if (foundIntersect) { // Draw the upper line segment. Also serves as the parent item. _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, intersect->y() - 3); _hoverLine->setPen(_hoverPen); _hoverLine->setZValue(OVERLAY_Z); _scene->addItem(_hoverLine); // Draw the box around the intersect point QGraphicsRectItem* hoverBox = new QGraphicsRectItem(xPos - 3, intersect->y() - 3, 6, 6); hoverBox->setPen(_hoverPen); hoverBox->setBrush(Qt::NoBrush); hoverBox->setZValue(OVERLAY_Z); hoverBox->setParentItem(_hoverLine); // Draw the lower line segment QGraphicsLineItem* lowerLine = new QGraphicsLineItem(xPos, intersect->y() + 3, xPos, _graphField.y() + _graphField.height() + 5); lowerLine->setPen(_hoverPen); lowerLine->setZValue(OVERLAY_Z); lowerLine->setParentItem(_hoverLine); // Draw the text and background double y = (1.0 - ((intersect->y() - _graphField.y()) / _graphField.height())) * (_graphMaxY - _graphMinY) + _graphMinY; int textOffset = 10; QGraphicsSimpleTextItem* hoverText = new QGraphicsSimpleTextItem(QString::number(y) + tr("m")); hoverText->setBrush(QBrush(_axesColor)); hoverText->setFont(_graphFont); hoverText->setZValue(OVERLAY_Z); if (intersect->x() + textOffset + hoverText->boundingRect().width() < _graphField.x() + _graphField.width()) hoverText->setPos(intersect->x() + textOffset, intersect->y() - hoverText->boundingRect().height()); else hoverText->setPos(intersect->x() - textOffset - hoverText->boundingRect().width(), intersect->y() - hoverText->boundingRect().height()); QGraphicsRectItem* hoverTextBackground = new QGraphicsRectItem(hoverText->x() - 3, hoverText->y() - 1, hoverText->boundingRect().width() + 6, hoverText->boundingRect().height() + 1); hoverTextBackground->setPen(_axesPen); hoverTextBackground->setBrush(QBrush(_graphColor)); hoverTextBackground->setZValue(OVERLAY_Z); hoverTextBackground->setParentItem(_hoverLine); hoverText->setParentItem(_hoverLine); // Update callback if (_positionCallback.valid()) { double distanceFactor = ((xPos - _graphField.x()) / (double)_graphField.width()); osg::Vec3d worldStart, worldEnd; _calculator->getStart(ALTMODE_ABSOLUTE).toWorld(worldStart); _calculator->getEnd(ALTMODE_ABSOLUTE).toWorld(worldEnd); double worldX = (worldEnd.x() - worldStart.x()) * distanceFactor + worldStart.x(); double worldY = (worldEnd.y() - worldStart.y()) * distanceFactor + worldStart.y(); double worldZ = (worldEnd.z() - worldStart.z()) * distanceFactor + worldStart.z(); GeoPoint mapPos; mapPos.fromWorld(_calculator->getStart().getSRS(), osg::Vec3d(worldX, worldY, worldZ)); _positionCallback->updatePosition(mapPos.y(), mapPos.x(), hoverText->text().toStdString()); } } else { // No intersect found so just draw the full line at xPos _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height() + 5); _hoverLine->setPen(_hoverPen); _hoverLine->setZValue(OVERLAY_Z); _scene->addItem(_hoverLine); } // Draw distance text double x = ((xPos - _graphField.x()) / _graphField.width()) * _totalDistance; BoxedSimpleTextItem* distanceText = new BoxedSimpleTextItem(QString::number(x / 1000.0, 'f', 2) + tr("km"), _backgroundColor); distanceText->setBrush(QBrush(_axesColor)); distanceText->setFont(_graphFont); distanceText->setZValue(OVERLAY_Z); if(xPos - 2 - distanceText->boundingRect().width() > _graphField.x()) { distanceText->setPos(xPos - 2 - distanceText->boundingRect().width(), _graphField.y() + _graphField.height() + 2); } else { distanceText->setPos(xPos + 2, _graphField.y() + _graphField.height() + 2); } distanceText->setParentItem(_hoverLine); // Draw selection box drawSelectionBox(xPos); delete intersect; }
void WeekScene::addCalendar() { const KCalendarSystem* cal = KGlobal::locale()->calendar(); QGraphicsTextItem* tmp = addText("Dinges"); QFontMetricsF fm(tmp->font()); removeItem(tmp); delete tmp; // first add 7 rectangles for each day of the week xoff = fm.width("00:00") + 10; yoff = 2 * fm.height() + 10; day_width = LongestDayWidth(fm) * 1.5; hour_height = fm.height() * 1.5; status = addText(i18n("Current schedule:")); status->setPos(QPointF(0, 0)); status->setZValue(2); QPen pen(SchedulerPluginSettings::scheduleLineColor()); QBrush brush(SchedulerPluginSettings::scheduleBackgroundColor()); for (int i = 0; i < 7; i++) { QGraphicsRectItem* item = addRect(xoff + day_width * i, yoff, day_width, 24 * hour_height, pen, brush); item->setZValue(1); QString day = cal->weekDayName(i + 1); // make sure day is centered in the middle of the column qreal dlen = fm.width(day); qreal mid = xoff + day_width * (i + 0.5); qreal start = mid - dlen * 0.5; QGraphicsTextItem* t = addText(day); t->setPos(QPointF(start, fm.height() + 5)); t->setZValue(2); rects.append(item); } // draw hour lines for (int i = 0; i <= 24; i++) { QGraphicsLineItem* item = addLine(0, yoff + i * hour_height, xoff + 7 * day_width, yoff + i * hour_height, pen); item->setZValue(2); if (i < 24) { QGraphicsTextItem* t = addText(QString("%1:00").arg(i)); t->setPos(QPointF(0, yoff + i * hour_height)); t->setZValue(2); } lines.append(item); } ; gline[0] = new GuidanceLine(xoff, yoff, xoff + 7 * day_width + 10); gline[0]->setVisible(false); gline[1] = new GuidanceLine(xoff, yoff, xoff + 7 * day_width + 10); gline[1]->setVisible(false); addItem(gline[0]); addItem(gline[1]); QRectF r = sceneRect(); r.setHeight(r.height() + 10); setSceneRect(r); }
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; } } }