QSize DatatypeWidget::calculateSize() { if (!m_pObject) { return UMLWidget::calculateSize(); } int width, height; const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); int lines = 1;//always have one line - for name lines++; //for the stereotype height = width = 0; height += lines * fontHeight; //now set the width of the concept //set width to name to start with //set width to name to start with width = getFontMetrics(FT_BOLD_ITALIC).boundingRect(m_pObject->fullyQualifiedName()).width(); int w = getFontMetrics(FT_BOLD).boundingRect(m_pObject->stereotype(true)).width(); width = w > width?w:width; //allow for width margin width += DATATYPE_MARGIN * 2; return QSize(width, height); }
/** * Overrides method from UMLWidget */ QSizeF StateWidget::minimumSize() const { int width = 10, height = 10; switch (m_stateType) { case StateWidget::Normal: { const QFontMetrics &fm = getFontMetrics(FT_BOLD); const int fontHeight = fm.lineSpacing(); int textWidth = fm.width(name()); const int count = m_Activities.count(); height = fontHeight; if(count > 0) { height = fontHeight * (count + 1); QStringList::ConstIterator end(m_Activities.end()); for(QStringList::ConstIterator it(m_Activities.begin()); it != end; ++it) { int w = fm.width(*it); if(w > textWidth) textWidth = w; }//end for }//end if width = textWidth > STATE_WIDTH?textWidth:STATE_WIDTH; height = height > STATE_HEIGHT?height:STATE_HEIGHT; width += STATE_MARGIN * 2; height += STATE_MARGIN * 2; break; } case StateWidget::Fork: case StateWidget::Join: if (m_drawVertical) { width = 8; height = 60; } else { width = 60; height = 8; } break; case StateWidget::Junction: width = 18; height = 18; break; case StateWidget::DeepHistory: case StateWidget::ShallowHistory: { const QFontMetrics &fm = getFontMetrics(FT_NORMAL); width = height = fm.lineSpacing(); } break; case StateWidget::Choice: width = 25; height = 25; break; default: break; } return QSizeF(width, height); }
/** 大きさを設定する @param x x座標 @param y y座標 @param width 幅 @param height 高さ */ void TextArea::setBounds(int x, int y, int width, int height) { // TextField::setBounds( x, y, getWidth(), getHeight() ); TextField::setBounds( x, y, width, height ); int draw_left = 4; int draw_top = 4; _max_line = (getHeight() - draw_top) / getFontMetrics()->getHeight(WIDTH_BASE) - 1; _max_col = (width - draw_left) / getFontMetrics()->getWidth(WIDTH_BASE) - 1; updateScrollbar(false, true); }
void Button::paint(Graphics* g) { int w = getWidth(); int h = getHeight(); // 一度背景色でクリア g->setColor(getBackground()); g->fillRect(0, 0, w, h); // 枠を描画 g->setColor(Color::black); g->drawLine(2, 0, w - 3, 0); g->drawLine(2, h - 1, w - 3, h - 1); g->drawLine(0, 2, 0, h - 3); g->drawLine(w - 1, 2, w - 1, h - 3); g->drawLine(1, 1, 1, 1); g->drawLine(1, h - 2 , 1, h - 2); g->drawLine(w - 2 , 1, w - 2, 1); g->drawLine(w - 2 , h - 2, w - 2, h - 2); if (this->pushed) { g->setColor(Color::white); g->drawLine(2, h - 2, w - 3, h - 2); g->drawLine(w - 2, 2, w - 2, h - 3); g->drawLine(w - 3 , h - 3, w - 3, h - 3); g->setColor(Color::gray); g->drawLine(1, 2, 1, h - 3); g->drawLine(2, 1, w - 3, 1); } else { g->setColor(Color::gray); g->drawLine(2, h - 2, w - 3, h - 2); g->drawLine(w - 2, 2, w - 2, h - 3); g->drawLine(w - 3 , h - 3, w - 3, h - 3); g->setColor(Color::white); g->drawLine(1, 2, 1, h - 3); g->drawLine(2, 1, w - 3, 1); } // 文字 int fw = getFontMetrics()->getWidth(getLabel()); int fh = getFontMetrics()->getHeight(getLabel()); int x = (w - fw) / 2; int y = (h - fh) / 2; if (this->pushed) { x++; y++; } if (getEnabled() == true) { g->setColor(getForeground()); } else { g->setColor(Color::gray); } g->drawString(getLabel(), x, y); }
QSize EntityWidget::calculateSize() { if (!m_pObject) { return UMLWidget::calculateSize(); } int width, height; QFont font = UMLWidget::getFont(); font.setItalic(false); font.setUnderline(false); font.setBold(false); const QFontMetrics fm(font); const int fontHeight = fm.lineSpacing(); int lines = 1;//always have one line - for name if ( !m_pObject->getStereotype().isEmpty() ) { lines++; } const int numberOfEntityAttributes = ((UMLEntity*)m_pObject)->entityAttributes(); height = width = 0; //set the height of the entity lines += numberOfEntityAttributes; if (numberOfEntityAttributes == 0) { height += fontHeight / 2; //no entity literals, so just add a bit of space } height += lines * fontHeight; //now set the width of the concept //set width to name to start with // FIXME spaces to get round beastie with font width, // investigate UMLWidget::getFontMetrics() width = getFontMetrics(FT_BOLD_ITALIC).boundingRect(' ' + getName() + ' ').width(); const int w = getFontMetrics(FT_BOLD).boundingRect(m_pObject->getStereotype(true)).width(); width = w > width?w:width; UMLClassifier* classifier = (UMLClassifier*)m_pObject; UMLClassifierListItemList list = classifier->getFilteredList(Uml::ot_EntityAttribute); UMLClassifierListItem* listItem = 0; for (listItem = list.first(); listItem; listItem = list.next()) { int w = fm.width( listItem->getName() ); width = w > width?w:width; } //allow for width margin width += ENTITY_MARGIN * 2; return QSize(width, height); }
void Frame::repaint() { if (this->__g == NULL) return; /* 矩形ウィンドウ */ int w = getWidth(); int h = getHeight(); /* 外枠 */ __g->setColor(Color::lightGray); __g->fillRect(0, 0, w, h); __g->setColor(Color::black); __g->drawRect(0, 0, w, h); /* 内枠 */ __g->setColor(Color::black); __g->drawRect(5, 21, w - 10, h - 26); /* 枠 */ __g->setColor(Color::white); __g->drawLine(1, 1, w - 2, 1); __g->drawLine(1, 1, 1, h - 2); __g->drawLine(w - 5, 21, w - 5, h - 5); __g->drawLine(5, h - 5, w - 5, h - 5); __g->setColor(Color::gray); __g->drawLine(w - 2, 2, w - 2, h - 2); __g->drawLine(2, h - 2, w - 2, h - 2); __g->drawLine(4, 20, w - 6, 20); __g->drawLine(4, 20, 4, h - 6); if (getFocused() == true) { /* タイトルバー */ for (int i = 4; i <= 14; i = i + 2) { __g->setColor(Color::gray); __g->drawLine(20, i, w - 7, i); __g->setColor(Color::white); __g->drawLine(21, i + 1, w - 6, i + 1); } drawCloseButton(__g); } /* タイトル */ int fw = getFontMetrics()->getWidth(getTitle()); int fh = getFontMetrics()->getHeight(getTitle()); __g->setColor(Color::lightGray); __g->fillRect(((w - fw) / 2) - 4, 2, fw + 8, getInsets()->top - 4); if (getFocused() == true) { __g->setColor(Color::black); } else { __g->setColor(Color::gray); } __g->drawString(getTitle(), ((w - fw) / 2), ((getInsets()->top - fh) / 2)); Container::repaint(); }
/** * Overrides method from UMLWidget */ UMLSceneSize PackageWidget::minimumSize() { if ( !m_pObject ) { return UMLWidget::minimumSize(); } const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC); const int fontHeight = fm.lineSpacing(); int lines = 1; int width = fm.width( m_pObject->name() ); int tempWidth = 0; if (!m_pObject->stereotype().isEmpty()) { tempWidth = fm.width(m_pObject->stereotype(true)); lines = 2; } if (tempWidth > width) width = tempWidth; width += PACKAGE_MARGIN * 2; if (width < 70) width = 70; // minumin width of 70 int height = (lines*fontHeight) + fontHeight + (PACKAGE_MARGIN * 2); return UMLSceneSize(width, height); }
QSize ComponentWidget::calculateSize() { if ( !m_pObject) { return QSize(70, 70); } const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC); const int fontHeight = fm.lineSpacing(); QString name = m_pObject->getName(); if ( UMLWidget::getIsInstance() ) { name = UMLWidget::getInstanceName() + " : " + name; } int width = fm.width(name); int stereoWidth = 0; if (!m_pObject->getStereotype().isEmpty()) { stereoWidth = fm.width(m_pObject->getStereotype(true)); } if (stereoWidth > width) width = stereoWidth; width += COMPONENT_MARGIN * 6; width = 70>width ? 70 : width; //minumin width of 70 int height = (2*fontHeight) + (COMPONENT_MARGIN * 3); return QSize(width, height); }
void OsmAnd::TextRasterizer_P::measureHalo(const Style& style, QVector<LinePaint>& paints) const { for (auto& linePaint : paints) { linePaint.maxBoundsTop = 0; linePaint.minBoundsTop = std::numeric_limits<SkScalar>::max(); for (auto& textPaint : linePaint.textPaints) { const auto haloPaint = getHaloPaint(textPaint.paint, style); SkPaint::FontMetrics metrics; textPaint.height = haloPaint.getFontMetrics(&metrics); linePaint.maxFontHeight = qMax(linePaint.maxFontHeight, textPaint.height); linePaint.minFontHeight = qMin(linePaint.minFontHeight, textPaint.height); linePaint.maxFontLineSpacing = qMax(linePaint.maxFontLineSpacing, metrics.fLeading); linePaint.minFontLineSpacing = qMin(linePaint.minFontLineSpacing, metrics.fLeading); linePaint.maxFontTop = qMax(linePaint.maxFontTop, -metrics.fTop); linePaint.minFontTop = qMin(linePaint.minFontTop, -metrics.fTop); linePaint.maxFontBottom = qMax(linePaint.maxFontBottom, metrics.fBottom); linePaint.minFontBottom = qMin(linePaint.minFontBottom, metrics.fBottom); SkRect haloBounds; haloPaint.measureText( textPaint.text.constData(), textPaint.text.length()*sizeof(QChar), &haloBounds); textPaint.bounds.join(haloBounds); linePaint.maxBoundsTop = qMax(linePaint.maxBoundsTop, -textPaint.bounds.top()); linePaint.minBoundsTop = qMin(linePaint.minBoundsTop, -textPaint.bounds.top()); } } }
void ActorWidget::draw(QPainter & p, int offsetX, int offsetY) { UMLWidget::setPenFromSettings(p); if( UMLWidget::getUseFillColour() ) p.setBrush( UMLWidget::getFillColour() ); const int w = width(); const int h = height(); p.setFont( UMLWidget::font() ); const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int textWidth = fm.width(name()); const int fontHeight = fm.lineSpacing(); const int a_height = h - fontHeight - A_MARGIN; const int h2 = a_height / 2; const int w2 = w - A_MARGIN * 2; const int a_width = (h2 > w2 || w > textWidth + A_MARGIN * 2 ? w2 : h2); const int middleX = w / 2; const int thirdY = a_height / 3; //draw actor p.drawEllipse(offsetX + middleX - a_width / 2, offsetY, a_width, thirdY); //head p.drawLine(offsetX + middleX, offsetY + thirdY, offsetX + middleX, offsetY + thirdY * 2); //body p.drawLine(offsetX + middleX, offsetY + 2 * thirdY, offsetX + middleX - a_width / 2, offsetY + a_height); //left leg p.drawLine(offsetX + middleX, offsetY + 2 * thirdY, offsetX + middleX + a_width / 2, offsetY + a_height); //right leg p.drawLine(offsetX + middleX - a_width / 2, offsetY + thirdY + thirdY / 2, offsetX + middleX + a_width / 2, offsetY + thirdY + thirdY / 2); //arms //draw text p.setPen(QPen(Qt::black)); p.drawText(offsetX + A_MARGIN, offsetY + h - fontHeight, w - A_MARGIN * 2, fontHeight, Qt::AlignCenter, name()); if(m_bSelected) drawSelected(&p, offsetX, offsetY); }
void DatatypeWidget::draw(QPainter& p, int offsetX, int offsetY) { setPenFromSettings(p); if (UMLWidget::getUseFillColour()) { p.setBrush(UMLWidget::getFillColour()); } else { p.setBrush( m_pView->viewport()->palette().color(QPalette::Background) ); } int w = width(); int h = height(); QFontMetrics &fm = getFontMetrics(FT_NORMAL); int fontHeight = fm.lineSpacing(); p.drawRect(offsetX, offsetY, w, h); p.setPen(QPen(Qt::black)); QFont font = UMLWidget::font(); font.setBold(true); p.setFont(font); p.drawText(offsetX + DATATYPE_MARGIN, offsetY, w - DATATYPE_MARGIN* 2,fontHeight, Qt::AlignCenter, m_pObject->stereotype(true)); font.setItalic( m_pObject->isAbstract() ); p.setFont(font); p.drawText(offsetX + DATATYPE_MARGIN, offsetY + fontHeight, w - DATATYPE_MARGIN * 2, fontHeight, Qt::AlignCenter, name()); if (m_bSelected) { drawSelected(&p, offsetX, offsetY); } }
/** * Overrides the standard paint event. */ void UseCaseWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); setPenFromSettings(painter); if (UMLWidget::useFillColor()) painter->setBrush(UMLWidget::fillColor()); QFont font = UMLWidget::font(); font.setUnderline(false); font.setBold(false); font.setItalic(m_umlObject->isAbstract()); painter->setFont(font); const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); const int w = width(); const int h = height(); //int middleX = w / 2; bool drawStereotype = umlObject() && !umlObject()->stereotype().isEmpty(); const int textStartY = (h / 2) - (drawStereotype ? fontHeight / 4 : fontHeight / 2); painter->drawEllipse(0, 0, w, h); painter->setPen(textColor()); if (drawStereotype) painter->drawText(UC_MARGIN, textStartY-fontHeight, w - UC_MARGIN * 2, fontHeight, Qt::AlignCenter, umlObject()->stereotype(true)); painter->drawText(UC_MARGIN, textStartY, w - UC_MARGIN * 2, fontHeight, Qt::AlignCenter, name()); setPenFromSettings(painter); UMLWidget::paint(painter, option, widget); }
QSize StateWidget::calculateSize() { int width = 10, height = 10; if ( m_StateType == Normal ) { const QFontMetrics &fm = getFontMetrics(FT_BOLD); const int fontHeight = fm.lineSpacing(); int textWidth = fm.width(getName()); const int count = m_Activities.count(); height = fontHeight; if( count > 0 ) { height = fontHeight * ( count + 1); QStringList::Iterator end(m_Activities.end()); for( QStringList::Iterator it(m_Activities.begin()); it != end; ++it ) { int w = fm.width( *it ); if( w > textWidth ) textWidth = w; }//end for }//end if width = textWidth > STATE_WIDTH?textWidth:STATE_WIDTH; height = height > STATE_HEIGHT?height:STATE_HEIGHT; width += STATE_MARGIN * 2; height += STATE_MARGIN * 2; } return QSize(width, height); }
/** * Overrides method from UMLWidget. */ QSizeF FloatingTextWidget::minimumSize() const { const QFontMetrics &fm = getFontMetrics(FT_NORMAL); int h = fm.lineSpacing(); int w = fm.width(displayText()); return QSizeF(w + 8, h + 4); // give a small margin }
/** * Draw the object as an actor. */ void ObjectWidget::paintActor(QPainter *painter) { const QFontMetrics &fm = getFontMetrics(FT_UNDERLINE); setPenFromSettings(painter); if (UMLWidget::useFillColor()) painter->setBrush(UMLWidget::fillColor()); const int w = width(); const int textStartY = A_HEIGHT + A_MARGIN; const int fontHeight = fm.lineSpacing(); const int middleX = w / 2; const int thirdH = A_HEIGHT / 3; //draw actor painter->drawEllipse(middleX - A_WIDTH / 2, 0, A_WIDTH, thirdH);//head painter->drawLine(middleX, thirdH, middleX, thirdH * 2);//body painter->drawLine(middleX, 2 * thirdH, middleX - A_WIDTH / 2, A_HEIGHT);//left leg painter->drawLine(middleX, 2 * thirdH, middleX + A_WIDTH / 2, A_HEIGHT);//right leg painter->drawLine(middleX - A_WIDTH / 2, thirdH + thirdH / 2, middleX + A_WIDTH / 2, thirdH + thirdH / 2);//arms //draw text painter->setPen(textColor()); QString t = m_instanceName + QLatin1String(" : ") + name(); painter->drawText(A_MARGIN, textStartY, w - A_MARGIN * 2, fontHeight, Qt::AlignCenter, t); }
/** * Overrides method from UMLWidget. */ QSizeF NodeWidget::minimumSize() const { if (m_umlObject == 0) { DEBUG(DBG_SRC) << "m_umlObject is NULL"; return UMLWidget::minimumSize(); } const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC); const int fontHeight = fm.lineSpacing(); QString name = m_umlObject->name(); if (UMLWidget::isInstance()) { name = UMLWidget::instanceName() + QLatin1String(" : ") + name; } int width = fm.width(name) + 2 * defaultMargin; int tempWidth = 0; if (!m_umlObject->stereotype().isEmpty()) { tempWidth = fm.width(m_umlObject->stereotype(true)); } if (tempWidth > width) width = tempWidth; width += DEPTH; int height = (2*fontHeight) + DEPTH; return QSizeF(width, height); }
void ComponentWidget::draw(QPainter & p, int offsetX, int offsetY) { UMLComponent *umlcomp = static_cast<UMLComponent*>(m_pObject); if (umlcomp == NULL) return; UMLWidget::setPen(p); if ( umlcomp->getExecutable() ) { QPen thickerPen = p.pen(); thickerPen.setWidth(2); p.setPen(thickerPen); } if ( UMLWidget::getUseFillColour() ) { p.setBrush( UMLWidget::getFillColour() ); } else { p.setBrush( m_pView->viewport()->backgroundColor() ); } const int w = width(); const int h = height(); QFont font = UMLWidget::getFont(); font.setBold(true); const QFontMetrics &fm = getFontMetrics(FT_BOLD); const int fontHeight = fm.lineSpacing(); QString name = getName(); const QString stereotype = m_pObject->getStereotype(); p.drawRect(offsetX + 2*COMPONENT_MARGIN, offsetY, w - 2*COMPONENT_MARGIN, h); p.drawRect(offsetX, offsetY + h/2 - fontHeight/2 - fontHeight, COMPONENT_MARGIN*4, fontHeight); p.drawRect(offsetX, offsetY + h/2 + fontHeight/2, COMPONENT_MARGIN*4, fontHeight); p.setPen( QPen(Qt::black) ); p.setFont(font); int lines = 1; if (!stereotype.isEmpty()) { p.drawText(offsetX + (COMPONENT_MARGIN*4), offsetY + (h/2) - fontHeight, w - (COMPONENT_MARGIN*4), fontHeight, Qt::AlignCenter, m_pObject->getStereotype(true)); lines = 2; } if ( UMLWidget::getIsInstance() ) { font.setUnderline(true); p.setFont(font); name = UMLWidget::getInstanceName() + " : " + name; } if (lines == 1) { p.drawText(offsetX + (COMPONENT_MARGIN*4), offsetY + (h/2) - (fontHeight/2), w - (COMPONENT_MARGIN*4), fontHeight, Qt::AlignCenter, name ); } else { p.drawText(offsetX + (COMPONENT_MARGIN*4), offsetY + (h/2), w - (COMPONENT_MARGIN*4), fontHeight, Qt::AlignCenter, name ); } if(m_bSelected) { drawSelected(&p, offsetX, offsetY); } }
void hdSimpleTextFigure::recalculateDisplayBox() { int w, h; getFontMetrics(w, h); hdGeometry g; displayBox().width = g.max(w, 10) + padding; displayBox().height = g.max(h, 10) + padding; }
QSize ActorWidget::calculateSize() { const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); const int textWidth = fm.width(name()); int width = textWidth > A_WIDTH ? textWidth : A_WIDTH; int height = A_HEIGHT + fontHeight + A_MARGIN; width += A_MARGIN * 2; return QSize(width, height); }
/** * Overrides method from UMLWidget. */ QSizeF ObjectNodeWidget::minimumSize() const { int widthtmp = 10, height = 10, width=10; if (m_objectNodeType == Buffer) { const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); const int textWidth = fm.width(QLatin1String("<< centralBuffer >>")); const int namewidth = fm.width(name()); height = fontHeight * 2; widthtmp = textWidth > OBJECTNODE_WIDTH ? textWidth : OBJECTNODE_WIDTH; width = namewidth > widthtmp ? namewidth : widthtmp; height = height > OBJECTNODE_HEIGHT ? height : OBJECTNODE_HEIGHT; width += OBJECTNODE_MARGIN * 2; height += OBJECTNODE_MARGIN * 2 + 5; } else if (m_objectNodeType == Data) { const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); const int textWidth = fm.width(QLatin1String("<< datastore >>")); const int namewidth = fm.width(name()); height = fontHeight * 2; widthtmp = textWidth > OBJECTNODE_WIDTH ? textWidth : OBJECTNODE_WIDTH; width = namewidth > widthtmp ? namewidth : widthtmp; height = height > OBJECTNODE_HEIGHT ? height : OBJECTNODE_HEIGHT; width += OBJECTNODE_MARGIN * 2; height += OBJECTNODE_MARGIN * 2 + 5; } else if (m_objectNodeType == Flow) { const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); const int textWidth = fm.width(QLatin1Char('[') + state() + QLatin1Char(']')); const int namewidth = fm.width(name()); height = fontHeight * 2; widthtmp = textWidth > OBJECTNODE_WIDTH ? textWidth : OBJECTNODE_WIDTH; width = namewidth > widthtmp ? namewidth : widthtmp; height = height > OBJECTNODE_HEIGHT ? height : OBJECTNODE_HEIGHT; width += OBJECTNODE_MARGIN * 2; height += OBJECTNODE_MARGIN * 4; } return QSizeF(width, height); }
/** * Overrides method from UMLWidget. */ QSizeF PreconditionWidget::minimumSize() const { int width = 10, height = 10; const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); const int textWidth = fm.width(name()) + 25; height = fontHeight; width = textWidth > PRECONDITION_WIDTH ? textWidth : PRECONDITION_WIDTH; height = height > PRECONDITION_HEIGHT ? height : PRECONDITION_HEIGHT; width += PRECONDITION_MARGIN * 2; height += PRECONDITION_MARGIN * 2; return QSizeF(width, height); }
/** * Overrides standard method. */ void PackageWidget::paint(QPainter & p, int offsetX, int offsetY) { setPenFromSettings(p); if ( UMLWidget::useFillColor() ) p.setBrush( UMLWidget::fillColor() ); else p.setBrush( m_scene->viewport()->palette().color(QPalette::Background) ); int w = width(); int h = height(); QFont font = UMLWidget::font(); font.setBold(true); //FIXME italic is true when a package is first created until you click elsewhere, not sure why font.setItalic(false); const QFontMetrics &fm = getFontMetrics(FT_BOLD); const int fontHeight = fm.lineSpacing(); p.drawRect(offsetX, offsetY, 50, fontHeight); if (m_pObject->stereotype() == "subsystem") { const int fHalf = fontHeight / 2; const int symY = offsetY + fHalf; const int symX = offsetX + 38; p.drawLine(symX, symY, symX, symY + fHalf - 2); // left leg p.drawLine(symX + 8, symY, symX + 8, symY + fHalf - 2); // right leg p.drawLine(symX, symY, symX + 8, symY); // waist p.drawLine(symX + 4, symY, symX + 4, symY - fHalf + 2); // head } p.drawRect(offsetX, offsetY + fontHeight - 1, w, h - fontHeight); p.setPen(textColor()); p.setFont(font); int lines = 1; if (m_pObject != NULL) { QString stereotype = m_pObject->stereotype(); if (!stereotype.isEmpty()) { p.drawText(offsetX, offsetY + fontHeight + PACKAGE_MARGIN, w, fontHeight, Qt::AlignCenter, m_pObject->stereotype(true)); lines = 2; } } p.drawText(offsetX, offsetY + (fontHeight*lines) + PACKAGE_MARGIN, w, fontHeight, Qt::AlignCenter, name() ); if(m_selected) { drawSelected(&p, offsetX, offsetY); } }
UMLSceneSize RegionWidget::minimumSize() { int width = 10, height = 10; const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); int textWidth = fm.width(getName()); height = fontHeight; width = textWidth > REGION_WIDTH?textWidth:REGION_WIDTH; height = height > REGION_HEIGHT ? height : REGION_HEIGHT; width += REGION_MARGIN * 2; height += REGION_MARGIN * 2; return UMLSceneSize(width, height); }
void TextField::paint(Graphics* g) { int w = getWidth(), h = getHeight(); // 外枠 if (getFocused() == true && getEnabled() == true) { g->setColor(0, 128, 255); g->drawRect(0, 0, w, h); } else { g->setColor(getParent()->getBackground()); g->drawRect(0, 0, w, h); } // 内枠 g->setColor(getBackground()); g->fillRect(1, 1, w - 2, h - 2); g->setColor(getForeground()); g->drawRect(1, 1, w - 2, h - 2); // 文字 int fh = getFontMetrics()->getHeight(getText()); int fw = getFontMetrics()->getWidth(getText()); if (getEnabled() == true) { g->setColor(getForeground()); } else { g->setColor(Color::gray); } g->drawString(getText(), this->offx, (h - fh) / 2); // キャレット if (getFocused() == true && getEnabled() == true) { g->drawLine(offx + fw, offy, offx + fw, offy + 12); } // todo pullup int width = _imeManager->isOn() ? 100 : 0; _imeManager->setBounds(getX() + offx + fw, getY() + offy, width, getHeight() - offy * 2); }
/** * Override default method. */ void NoteWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); const int margin = 10; int w = width(); int h = height(); const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); QPolygon poly(6); poly.setPoint(0, 0, 0); poly.setPoint(1, 0, h); poly.setPoint(2, w, h); poly.setPoint(3, w, margin); poly.setPoint(4, w - margin, 0); poly.setPoint(5, 0, 0); setPenFromSettings(painter); if (UMLWidget::useFillColor()) { QBrush brush(UMLWidget::fillColor()); painter->setBrush(brush); painter->drawPolygon(poly); } else painter->drawPolyline(poly); painter->drawLine(w - margin, 0, w - margin, margin); painter->drawLine(w - margin, margin, w, margin); painter->setPen(textColor()); switch(m_noteType) { case NoteWidget::PreCondition : painter->drawText(0, margin, w, fontHeight, Qt::AlignCenter, QLatin1String("<< precondition >>")); break; case NoteWidget::PostCondition : painter->drawText(0, margin, w, fontHeight, Qt::AlignCenter, QLatin1String("<< postcondition >>")); break; case NoteWidget::Transformation : painter->drawText(0, margin, w, fontHeight, Qt::AlignCenter, QLatin1String("<< transformation >>")); break; case NoteWidget::Normal : default : break; } UMLWidget::paint(painter, option, widget); // paintText(&p, 0, 0); paintTextWordWrap(painter); }
void CategoryWidget::paint(QPainter & p, int offsetX, int offsetY) { UMLWidget::setPenFromSettings(p); if ( UMLWidget::useFillColor() ) p.setBrush( UMLWidget::fillColor() ); QFont font = UMLWidget::font(); font.setUnderline(false); font.setBold(false); font.setItalic( m_pObject->isAbstract() ); p.setFont( font ); const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); // the height is our radius const int h = height(); const int w = width(); const int r = h > w ? h : w; //int middleX = w / 2; const int textStartY = (r / 2) - (fontHeight / 2); // draw a circle p.drawEllipse(offsetX, offsetY, r, r); p.setPen(textColor()); QString letterType('D'); switch( static_cast<UMLCategory*>( m_pObject )->getType() ) { case UMLCategory::ct_Disjoint_Specialisation: letterType = 'D'; break; case UMLCategory::ct_Overlapping_Specialisation: letterType = 'O'; break; case UMLCategory::ct_Union: letterType = 'U'; break; default: break; } p.drawText(offsetX + UC_MARGIN, offsetY + textStartY, r - UC_MARGIN * 2, fontHeight, Qt::AlignCenter, letterType ); UMLWidget::setPenFromSettings(p); if(m_selected) drawSelected(&p, offsetX, offsetY); }
void TPopupMenu::show(Component* origin, int x, int y) { if (items.size() <= 0) { return; } base = origin; int fw = 100; FontMetrics* fm = getFontMetrics(); int fh = fm->getHeight("0") + 6; int h = 0; for (int ii = 0; ii < items.size(); ii++) { TMenuItem* item = (TMenuItem*)items.get(ii); switch (item->getType()) { case TMenuItem::TYPE_ITEM: if (fm->getWidth(item->getTitle()) + 20 > fw) { fw = fm->getWidth(item->getTitle()) + 20; } break; default: break; } } for (int ii = 0; ii < items.size(); ii++) { TMenuItem* item = (TMenuItem*)items.get(ii); switch (item->getType()) { case TMenuItem::TYPE_ITEM: item->setBounds(base->getX() + x + 2, base->getY() + y + h + 2, fw, fh); h += fh; break; case TMenuItem::TYPE_SEPARATOR: item->setBounds(base->getX() + x + 2, base->getY() + y + h + 2, fw, 8); h += 8; break; } } setBounds(base->getX() + x, base->getY() + y, fw + 4, h + 4); //boo RootWindow* root = (RootWindow*)base->getMainWindow(); if (root) { root->ShowPopupMenu(this); } }
/** * Overrides the standard paint event. */ void PreconditionWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); int w = width(); int h = height(); int x = m_objectWidget->x() + m_objectWidget->width() / 2; x -= w/2; setX(x); int y = this->y(); //test if y isn't above the object if (y <= m_objectWidget->y() + m_objectWidget->height()) { y = m_objectWidget->y() + m_objectWidget->height() + 15; } if (y + h >= m_objectWidget->getEndLineY()) { y = m_objectWidget->getEndLineY() - h; } setY(y); setPenFromSettings(painter); if (UMLWidget::useFillColor()) { painter->setBrush(UMLWidget::fillColor()); } { const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); const QString precondition_value = QLatin1String("{ ") + name() + QLatin1String(" }"); //int middleX = w / 2; int textStartY = (h / 2) - (fontHeight / 2); painter->drawRoundRect(0, 0, w, h, (h * 60) / w, 60); painter->setPen(textColor()); painter->setFont(UMLWidget::font()); painter->drawText(PRECONDITION_MARGIN, textStartY, w - PRECONDITION_MARGIN * 2, fontHeight, Qt::AlignCenter, precondition_value); } UMLWidget::paint(painter, option, widget); }
/** * Overrides method from UMLWidget */ QSizeF StateWidget::maximumSize() { switch (m_stateType) { case StateWidget::Initial: case StateWidget::End: case StateWidget::Junction: case StateWidget::Choice: return QSizeF(35, 35); break; case StateWidget::DeepHistory: case StateWidget::ShallowHistory: { const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); return QSizeF(fontHeight + 10, fontHeight + 10); } break; default: break; } return UMLWidget::maximumSize(); }
/** * Overrides method from UMLWidget */ QSizeF ObjectWidget::minimumSize() const { int width, height; const QFontMetrics &fm = getFontMetrics(FT_UNDERLINE); const int fontHeight = fm.lineSpacing(); const QString t = m_instanceName + QLatin1String(" : ") + name(); const int textWidth = fm.width(t); if (m_drawAsActor) { width = textWidth > A_WIDTH?textWidth:A_WIDTH; height = A_HEIGHT + fontHeight + A_MARGIN; width += A_MARGIN * 2; } else { width = textWidth > O_WIDTH?textWidth:O_WIDTH; height = fontHeight + O_MARGIN * 2; width += O_MARGIN * 2; if (m_multipleInstance) { width += 10; height += 10; } }//end else drawasactor return QSizeF(width, height); }