void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap) { const IconMetrics& iconMetrics = defaultIconMetrics(); QGraphicsPixmapItem *iconItem = 0; double yValue = title->boundingRect().height() + iconMetrics.spacing; Q_FOREACH (ToolTip t, toolTips) { yValue += t.second->boundingRect().height(); } if (entryToolTip.second) { yValue += entryToolTip.second->boundingRect().height(); } iconItem = new QGraphicsPixmapItem(this); if (!icon.isNull()) { iconItem->setPixmap(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small)); } else if (!pixmap.isNull()) { iconItem->setPixmap(pixmap); } const int sp2 = iconMetrics.spacing * 2; iconItem->setPos(sp2, yValue); QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this); textItem->setPos(sp2 + iconMetrics.sz_small + sp2, yValue); textItem->setBrush(QBrush(Qt::white)); textItem->setFlag(ItemIgnoresTransformations); toolTips.push_back(qMakePair(iconItem, textItem)); }
void DivePlannerGraphics::pointInserted(const QModelIndex& parent, int start , int end) { DiveHandler *item = new DiveHandler (); scene()->addItem(item); handles << item; QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem(); scene()->addItem(gasChooseBtn); gasChooseBtn->setZValue(10); gasChooseBtn->setFlag(QGraphicsItem::ItemIgnoresTransformations); gases << gasChooseBtn; drawProfile(); }
void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon) { QGraphicsPixmapItem *iconItem = 0; double yValue = title->boundingRect().height() + SPACING; Q_FOREACH (ToolTip t, toolTips) { yValue += t.second->boundingRect().height(); } if (!icon.isNull()) { iconItem = new QGraphicsPixmapItem(icon.pixmap(ICON_SMALL, ICON_SMALL), this); iconItem->setPos(SPACING, yValue); } QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this); textItem->setPos(SPACING + ICON_SMALL + SPACING, yValue); textItem->setBrush(QBrush(Qt::white)); textItem->setFlag(ItemIgnoresTransformations); toolTips.push_back(qMakePair(iconItem, textItem)); expand(); }
void AnimatorScene::initGridCoordinates () { for (int i = 0; i < m_gridCoordinates.size (); ++i) { QGraphicsSimpleTextItem * item = m_gridCoordinates[i]; removeItem (item); delete item; } m_gridCoordinates.clear (); for (int i = 0; i < 9; i++) // only 9 coordinates will be marked { QGraphicsSimpleTextItem * item = new QGraphicsSimpleTextItem; item->setFlag (QGraphicsItem::ItemIgnoresTransformations); m_gridCoordinates.push_back (item); addItem (item); } markGridCoordinates (); }
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->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); } }