actorwidget.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "actorwidget.h"
00014
00015
00016 #include <qpainter.h>
00017
00018
00019 #include "actor.h"
00020 #include "umlview.h"
00021
00022
00023 ActorWidget::ActorWidget(UMLView * view, UMLActor *a) : UMLWidget(view, a) {
00024 UMLWidget::setBaseType( Uml::wt_Actor );
00025 }
00026
00027 ActorWidget::~ActorWidget() {}
00028
00029 void ActorWidget::draw(QPainter & p, int offsetX, int offsetY) {
00030 UMLWidget::setPen(p);
00031 if( UMLWidget::getUseFillColour() )
00032 p.setBrush( UMLWidget::getFillColour() );
00033 const int w = width();
00034 const int h = height();
00035 p.setFont( UMLWidget::getFont() );
00036 const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
00037 const int textWidth = fm.width(getName());
00038 const int fontHeight = fm.lineSpacing();
00039 const int a_height = h - fontHeight - A_MARGIN;
00040 const int h2 = a_height / 2;
00041 const int w2 = w - A_MARGIN * 2;
00042 const int a_width = (h2 > w2 || w > textWidth + A_MARGIN * 2 ? w2 : h2);
00043 const int middleX = w / 2;
00044 const int thirdY = a_height / 3;
00045
00046
00047 p.drawEllipse(offsetX + middleX - a_width / 2, offsetY, a_width, thirdY);
00048 p.drawLine(offsetX + middleX, offsetY + thirdY,
00049 offsetX + middleX, offsetY + thirdY * 2);
00050 p.drawLine(offsetX + middleX, offsetY + 2 * thirdY,
00051 offsetX + middleX - a_width / 2, offsetY + a_height);
00052 p.drawLine(offsetX + middleX, offsetY + 2 * thirdY,
00053 offsetX + middleX + a_width / 2, offsetY + a_height);
00054 p.drawLine(offsetX + middleX - a_width / 2, offsetY + thirdY + thirdY / 2,
00055 offsetX + middleX + a_width / 2, offsetY + thirdY + thirdY / 2);
00056
00057 p.setPen(QPen(Qt::black));
00058 p.drawText(offsetX + A_MARGIN, offsetY + h - fontHeight,
00059 w - A_MARGIN * 2, fontHeight, Qt::AlignCenter, getName());
00060 if(m_bSelected)
00061 drawSelected(&p, offsetX, offsetY);
00062 }
00063
00064 QSize ActorWidget::calculateSize() {
00065 const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
00066 const int fontHeight = fm.lineSpacing();
00067 const int textWidth = fm.width(getName());
00068 int width = textWidth > A_WIDTH ? textWidth : A_WIDTH;
00069 int height = A_HEIGHT + fontHeight + A_MARGIN;
00070 width += A_MARGIN * 2;
00071 return QSize(width, height);
00072 }
00073
00074 void ActorWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
00075 QDomElement actorElement = qDoc.createElement( "actorwidget" );
00076 UMLWidget::saveToXMI( qDoc, actorElement );
00077 qElement.appendChild( actorElement );
00078 }
00079
This file is part of the documentation for umbrello Version 3.1.0.