nodewidget.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "nodewidget.h"
00014
00015
00016 #include <qpainter.h>
00017 #include <kdebug.h>
00018
00019
00020 #include "node.h"
00021 #include "uml.h"
00022 #include "umldoc.h"
00023 #include "umlview.h"
00024
00025 NodeWidget::NodeWidget(UMLView * view, UMLNode *n )
00026 : UMLWidget(view, n) {
00027 UMLWidget::setBaseType(Uml::wt_Node);
00028 setZ(m_origZ = 1);
00029 setSize(100, 30);
00030 if (n && !UMLApp::app()->getDocument()->loading())
00031 updateComponentSize();
00032 }
00033
00034 NodeWidget::~NodeWidget() {}
00035
00036 void NodeWidget::draw(QPainter & p, int offsetX, int offsetY) {
00037 UMLWidget::setPen(p);
00038 if ( UMLWidget::getUseFillColour() ) {
00039 p.setBrush( UMLWidget::getFillColour() );
00040 } else {
00041 p.setBrush( m_pView->viewport()->backgroundColor() );
00042 }
00043 const int w = width();
00044 const int h = height();
00045 const int wDepth = (w/3 > DEPTH ? DEPTH : w/3);
00046 const int hDepth = (h/3 > DEPTH ? DEPTH : h/3);
00047 const int bodyOffsetY = offsetY + hDepth;
00048 const int bodyWidth = w - wDepth;
00049 const int bodyHeight = h - hDepth;
00050 QFont font = UMLWidget::getFont();
00051 font.setBold(true);
00052 const QFontMetrics &fm = getFontMetrics(FT_BOLD);
00053 const int fontHeight = fm.lineSpacing();
00054 QString name = getName();
00055
00056 QPointArray pointArray(5);
00057 pointArray.setPoint(0, offsetX, bodyOffsetY);
00058 pointArray.setPoint(1, offsetX + wDepth, offsetY);
00059 pointArray.setPoint(2, offsetX + w - 1, offsetY);
00060 pointArray.setPoint(3, offsetX + w - 1, offsetY + bodyHeight );
00061 pointArray.setPoint(4, offsetX + bodyWidth, offsetY + h - 1);
00062 p.drawPolygon(pointArray);
00063 p.drawRect(offsetX, bodyOffsetY, bodyWidth, bodyHeight);
00064 p.drawLine(offsetX + w - 1, offsetY, offsetX + bodyWidth - 2, bodyOffsetY + 1);
00065
00066 p.setPen( QPen(Qt::black) );
00067 p.setFont(font);
00068
00069 int lines = 1;
00070 if (m_pObject) {
00071 QString stereotype = m_pObject->getStereotype();
00072 if (!stereotype.isEmpty()) {
00073 p.drawText(offsetX, bodyOffsetY + (bodyHeight/2) - fontHeight,
00074 bodyWidth, fontHeight, Qt::AlignCenter, m_pObject->getStereotype(true));
00075 lines = 2;
00076 }
00077 }
00078
00079 if ( UMLWidget::getIsInstance() ) {
00080 font.setUnderline(true);
00081 p.setFont(font);
00082 name = UMLWidget::getInstanceName() + " : " + name;
00083 }
00084
00085 if (lines == 1) {
00086 p.drawText(offsetX, bodyOffsetY + (bodyHeight/2) - (fontHeight/2),
00087 bodyWidth, fontHeight, Qt::AlignCenter, name);
00088 } else {
00089 p.drawText(offsetX, bodyOffsetY + (bodyHeight/2),
00090 bodyWidth, fontHeight, Qt::AlignCenter, name);
00091 }
00092
00093 if(m_bSelected) {
00094 drawSelected(&p, offsetX, offsetY);
00095 }
00096 }
00097
00098 QSize NodeWidget::calculateSize() {
00099 if (m_pObject == NULL) {
00100 kDebug() << "NodeWidget::calculateSize: m_pObject is NULL" << endl;
00101 return UMLWidget::calculateSize();
00102 }
00103
00104 const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC);
00105 const int fontHeight = fm.lineSpacing();
00106
00107 QString name = m_pObject->getName();
00108 if ( UMLWidget::getIsInstance() ) {
00109 name = UMLWidget::getInstanceName() + " : " + name;
00110 }
00111
00112 int width = fm.width(name);
00113
00114 int tempWidth = 0;
00115 if (!m_pObject->getStereotype().isEmpty()) {
00116 tempWidth = fm.width(m_pObject->getStereotype(true));
00117 }
00118 if (tempWidth > width)
00119 width = tempWidth;
00120 width += DEPTH;
00121
00122 int height = (2*fontHeight) + DEPTH;
00123
00124 return QSize(width, height);
00125 }
00126
00127 void NodeWidget::saveToXMI(QDomDocument& qDoc, QDomElement& qElement) {
00128 QDomElement conceptElement = qDoc.createElement("nodewidget");
00129 UMLWidget::saveToXMI(qDoc, conceptElement);
00130 qElement.appendChild(conceptElement);
00131 }
00132
This file is part of the documentation for umbrello Version 3.1.0.