QPainterPath GGPageItem::shape() const { QPainterPath p; switch (m_page->page()->type()) { case GGStartPage::Type: case GGEndPage::Type: return roundShape(innerBoundingRect()); case GGConditionPage::Type: return diamondShape(innerBoundingRect()); case GGActionPage::Type: case GGDecisionPage::Type: return roundedRectShape(boundingRect()); } return p; }
void GGPageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->setPen(QPen(editScene()->pageColor(m_page), editScene()->pageBorderWidth())); bool withCaption = true; painter->save(); switch (m_page->page()->type()) { case GGStartPage::Type: paintStart(painter, innerBoundingRect(), editScene()->pageColor(m_page), editScene()->pageFillColor()); withCaption = false; break; case GGEndPage::Type: paintEnd(painter, innerBoundingRect(), editScene()->pageColor(m_page), editScene()->pageFillColor()); withCaption = false; break; case GGConditionPage::Type: paintCondition(painter, innerBoundingRect(), editScene()->pageColor(m_page), editScene()->pageFillColor()); break; case GGActionPage::Type: paintAction(painter, boundingRect(), editScene()->pageColor(m_page), editScene()->pageFillColor()); break; case GGDecisionPage::Type: paintDecision(painter, boundingRect(), editScene()->pageColor(m_page), editScene()->pageFillColor()); break; } painter->restore(); if (withCaption) { QString name = m_page->page()->name(); painter->drawText(innerBoundingRect(), Qt::AlignCenter, name); } /* // TEST CENTER painter->setPen(Qt::red); painter->drawEllipse(0,0,2,2); // TEST BOUNDS painter->drawRect(boundingRect()); */ if (isSelected()) { painter->setPen(editScene()->pageHighlightColor()); painter->drawRect(boundingRect()); } }
QRectF GGPageItem::boundingRect() const { const qreal penWidth = editScene()->pageBorderWidth(); QRectF ret = innerBoundingRect(); ret.adjust(-penWidth/2, -penWidth/2, penWidth/2, penWidth/2); return ret; }
void DigestTreeScene::plotNode(const std::vector<TreeLayout::Coordinate>& childNodesCo, QString digest, int nodeSize) { RosterIterator it(m_roster); int n = childNodesCo.size(); int rim = 3; // plot root node QRectF rootBoundingRect(0, 0, nodeSize, nodeSize); QRectF rootInnerBoundingRect(rim, rim, nodeSize - rim * 2, nodeSize - rim * 2); addRect(rootBoundingRect, QPen(Qt::black), QBrush(Qt::darkRed)); addRect(rootInnerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray)); QRectF digestRect(- 5.5 * nodeSize , - nodeSize, 12 * nodeSize, 30); addRect(digestRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan)); QGraphicsTextItem *digestItem = addText(digest); QRectF digestBoundingRect = digestItem->boundingRect(); digestItem->setDefaultTextColor(Qt::black); digestItem->setFont(QFont("Cursive", 12, QFont::Bold)); digestItem->setPos(- 4.5 * nodeSize + (12 * nodeSize - digestBoundingRect.width()) / 2, - nodeSize + 5); m_displayRootDigest = digestItem; // plot child nodes for (int i = 0; i < n; i++) { if (it.hasNext()) it.next(); else abort(); double x = childNodesCo[i].x; double y = childNodesCo[i].y; QRectF boundingRect(x, y, nodeSize, nodeSize); QRectF innerBoundingRect(x + rim, y + rim, nodeSize - rim * 2, nodeSize - rim * 2); DisplayUserPtr p = it.value(); QGraphicsRectItem *rectItem = addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkBlue)); p->setRimRectItem(rectItem); QGraphicsRectItem *innerRectItem = addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray)); p->setInnerRectItem(innerRectItem); std::string s = boost::lexical_cast<std::string>(p->getSeqNo()); QGraphicsTextItem *seqItem = addText(s.c_str()); seqItem->setFont(QFont("Cursive", 12, QFont::Bold)); QRectF seqBoundingRect = seqItem->boundingRect(); seqItem->setPos(x + nodeSize / 2 - seqBoundingRect.width() / 2, y + nodeSize / 2 - seqBoundingRect.height() / 2); p->setSeqTextItem(seqItem); QRectF textRect(x - nodeSize / 2, y + nodeSize, 2 * nodeSize, 30); QGraphicsRectItem *nickRectItem = addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan)); p->setNickRectItem(nickRectItem); QGraphicsTextItem *nickItem = addText(p->getNick()); QRectF textBoundingRect = nickItem->boundingRect(); nickItem->setDefaultTextColor(Qt::white); nickItem->setFont(QFont("Cursive", 12, QFont::Bold)); nickItem->setPos(x + nodeSize / 2 - textBoundingRect.width() / 2, y + nodeSize + 5); p->setNickTextItem(nickItem); } }