datatypewidget.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "datatypewidget.h"
00014
00015
00016 #include <qpainter.h>
00017 #include <kdebug.h>
00018
00019
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;
00086 lines++;
00087
00088 height = width = 0;
00089 height += lines * fontHeight;
00090
00091
00092
00093
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
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
This file is part of the documentation for umbrello Version 3.1.0.