usecasewidget.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "usecasewidget.h"
00014
00015 #include <qpainter.h>
00016 #include <kdebug.h>
00017
00018 #include "usecase.h"
00019 #include "umlview.h"
00020
00021
00022 UseCaseWidget::UseCaseWidget(UMLView * view, UMLUseCase *o) : UMLWidget(view, o) {
00023 UMLWidget::setBaseType(Uml::wt_UseCase);
00024
00025
00026 }
00027
00028 UseCaseWidget::~UseCaseWidget() {}
00029
00030 void UseCaseWidget::draw(QPainter & p, int offsetX, int offsetY) {
00031 UMLWidget::setPen(p);
00032 if ( UMLWidget::getUseFillColour() )
00033 p.setBrush( UMLWidget::getFillColour() );
00034 QFont font = UMLWidget::getFont();
00035 font.setUnderline(false);
00036 font.setBold(false);
00037 font.setItalic( m_pObject->getAbstract() );
00038 p.setFont( font );
00039 const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
00040 const int fontHeight = fm.lineSpacing();
00041 const int w = width();
00042 const int h = height();
00043
00044 const int textStartY = (h / 2) - (fontHeight / 2);
00045
00046 p.drawEllipse(offsetX, offsetY, w, h);
00047 p.setPen(Qt::black);
00048 p.drawText(offsetX + UC_MARGIN, offsetY + textStartY, w - UC_MARGIN * 2, fontHeight, Qt::AlignCenter, getName());
00049 UMLWidget::setPen(p);
00050 if(m_bSelected)
00051 drawSelected(&p, offsetX, offsetY);
00052 }
00053
00054 QSize UseCaseWidget::calculateSize() {
00055 const UMLWidget::FontType ft = ( m_pObject->getAbstract() ? FT_BOLD_ITALIC : FT_BOLD );
00056 const QFontMetrics &fm = UMLWidget::getFontMetrics(ft);
00057 const int fontHeight = fm.lineSpacing();
00058 const int textWidth = fm.width(getName());
00059 int width = textWidth > UC_WIDTH?textWidth:UC_WIDTH;
00060 int height = UC_HEIGHT + fontHeight + UC_MARGIN;
00061
00062 width += UC_MARGIN * 2;
00063
00064 return QSize(width, height);
00065 }
00066
00067 void UseCaseWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
00068 QDomElement usecaseElement = qDoc.createElement( "usecasewidget" );
00069 UMLWidget::saveToXMI( qDoc, usecaseElement );
00070 qElement.appendChild( usecaseElement );
00071 }
00072
This file is part of the documentation for umbrello Version 3.1.0.