umbrello API Documentation

actorwidget.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2002-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header file
00013 #include "actorwidget.h"
00014 
00015 // system includes
00016 #include <qpainter.h>
00017 
00018 // local includes
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     //draw actor
00047     p.drawEllipse(offsetX + middleX - a_width / 2, offsetY, a_width, thirdY); //head
00048     p.drawLine(offsetX + middleX, offsetY + thirdY,
00049                offsetX + middleX, offsetY + thirdY * 2); //body
00050     p.drawLine(offsetX + middleX, offsetY + 2 * thirdY,
00051                offsetX + middleX - a_width / 2, offsetY + a_height); //left leg
00052     p.drawLine(offsetX + middleX, offsetY +  2 * thirdY,
00053                offsetX + middleX + a_width / 2, offsetY + a_height); //right leg
00054     p.drawLine(offsetX + middleX - a_width / 2, offsetY + thirdY + thirdY / 2,
00055                offsetX + middleX + a_width / 2, offsetY + thirdY + thirdY / 2); //arms
00056     //draw text
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 
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:53 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003