umbrello API Documentation

datatypewidget.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) 2003-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "datatypewidget.h"
00014 
00015 // qt/kde includes
00016 #include <qpainter.h>
00017 #include <kdebug.h>
00018 
00019 // app includes
00020 #include "classifier.h"
00021 #include "operation.h"
00022 #include "classifierlistitem.h"
00023 #include "umlview.h"
00024 #include "umldoc.h"
00025 #include "listpopupmenu.h"
00026 
00027 
00028 #define CIRCLE_SIZE 30
00029 
00030 DatatypeWidget::DatatypeWidget(UMLView* view, UMLClassifier *d) : UMLWidget(view, d) {
00031     init();
00032 }
00033 
00034 DatatypeWidget::~DatatypeWidget() {}
00035 
00036 void DatatypeWidget::init() {
00037     UMLWidget::setBaseType(Uml::wt_Datatype);
00038     setSize(100, 30);
00039     m_pMenu = 0;
00040 }
00041 
00042 void DatatypeWidget::draw(QPainter& p, int offsetX, int offsetY) {
00043     UMLWidget::setPen(p);
00044     if (UMLWidget::getUseFillColour())  {
00045         p.setBrush(UMLWidget::getFillColour());
00046     } else {
00047         p.setBrush(m_pView->viewport()->backgroundColor());
00048     }
00049 
00050     int w = width();
00051     int h = height();
00052 
00053     QFontMetrics &fm = getFontMetrics(FT_NORMAL);
00054     int fontHeight  = fm.lineSpacing();
00055     QString name = getName();
00056 
00057     p.drawRect(offsetX, offsetY, w, h);
00058     p.setPen(QPen(Qt::black));
00059 
00060     QFont font = UMLWidget::getFont();
00061     font.setBold(true);
00062     p.setFont(font);
00063     p.drawText(offsetX + DATATYPE_MARGIN, offsetY,
00064                w - DATATYPE_MARGIN* 2,fontHeight,
00065                Qt::AlignCenter, m_pObject->getStereotype(true));
00066 
00067     font.setItalic( m_pObject->getAbstract() );
00068     p.setFont(font);
00069     p.drawText(offsetX + DATATYPE_MARGIN, offsetY + fontHeight,
00070                w - DATATYPE_MARGIN * 2, fontHeight, Qt::AlignCenter, name);
00071 
00072     if (m_bSelected) {
00073         drawSelected(&p, offsetX, offsetY);
00074     }
00075 }
00076 
00077 QSize DatatypeWidget::calculateSize() {
00078     if (!m_pObject)  {
00079         return UMLWidget::calculateSize();
00080     }
00081     int width, height;
00082     const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
00083     const int fontHeight = fm.lineSpacing();
00084 
00085     int lines = 1;//always have one line - for name
00086     lines++; //for the stereotype
00087 
00088     height = width = 0;
00089     height += lines * fontHeight;
00090 
00091     //now set the width of the concept
00092     //set width to name to start with
00093     //set width to name to start with
00094     width = getFontMetrics(FT_BOLD_ITALIC).boundingRect(m_pObject->getFullyQualifiedName()).width();
00095     int w = getFontMetrics(FT_BOLD).boundingRect(m_pObject->getStereotype(true)).width();
00096 
00097     width = w > width?w:width;
00098 
00099     //allow for width margin
00100     width += DATATYPE_MARGIN * 2;
00101 
00102     return QSize(width, height);
00103 }
00104 
00105 void DatatypeWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
00106     QDomElement conceptElement = qDoc.createElement("datatypewidget");
00107     UMLWidget::saveToXMI(qDoc, conceptElement);
00108     qElement.appendChild(conceptElement);
00109 }
00110 
00111 bool DatatypeWidget::loadFromXMI( QDomElement & qElement ) {
00112     return UMLWidget::loadFromXMI(qElement);
00113 }
00114 
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:56 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003