umbrello API Documentation

usecasewidget.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-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header file
00013 #include "usecasewidget.h"
00014 // system includes
00015 #include <qpainter.h>
00016 #include <kdebug.h>
00017 // local includes
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     //updateComponentSize();  Doing this during loadFromXMI() gives futile updates.
00025     //                  Instead, it is done afterwards by UMLWidget::activate()
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     //int middleX = w / 2;
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 
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:08:03 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003