• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • kdesdk
  • Sitemap
  • Contact Us
 

umbrello/umbrello

artifactwidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   This program is free software; you can redistribute it and/or modify  *
00003  *   it under the terms of the GNU General Public License as published by  *
00004  *   the Free Software Foundation; either version 2 of the License, or     *
00005  *   (at your option) any later version.                                   *
00006  *                                                                         *
00007  *   copyright (C) 2003-2009                                               *
00008  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00009  ***************************************************************************/
00010 
00011 // own header
00012 #include "artifactwidget.h"
00013 
00014 // qt/kde includes
00015 #include <QtGui/QPainter>
00016 #include <q3pointarray.h>
00017 #include <kdebug.h>
00018 
00019 // app includes
00020 #include "artifact.h"
00021 #include "umlview.h"
00022 
00023 
00024 ArtifactWidget::ArtifactWidget(UMLView *view, UMLArtifact *a)
00025   : UMLWidget(view, a)
00026 {
00027     init();
00028     setSize(100, 30);
00029     updateComponentSize();
00030 }
00031 
00032 
00033 void ArtifactWidget::init()
00034 {
00035     UMLWidget::setBaseType( Uml::wt_Artifact );
00036     m_pMenu = 0;
00037 }
00038 
00039 ArtifactWidget::~ArtifactWidget()
00040 {
00041 }
00042 
00043 void ArtifactWidget::drawAsNormal(QPainter& p, int offsetX, int offsetY)
00044 {
00045     int w = width();
00046     int h = height();
00047     QFont font = UMLWidget::font();
00048     font.setBold(true);
00049     const QFontMetrics &fm = getFontMetrics(FT_BOLD);
00050     const int fontHeight  = fm.lineSpacing();
00051     QString stereotype = m_pObject->getStereotype();
00052 
00053     p.drawRect(offsetX, offsetY, w, h);
00054 
00055     p.setPen( QPen(Qt::black) );
00056     p.setFont(font);
00057 
00058     if (!stereotype.isEmpty()) {
00059         p.drawText(offsetX + ARTIFACT_MARGIN, offsetY + (h/2) - fontHeight,
00060                    w, fontHeight, Qt::AlignCenter, m_pObject->getStereotype(true));
00061     }
00062 
00063     int lines;
00064     if (!stereotype.isEmpty()) {
00065         lines = 2;
00066     } else {
00067         lines = 1;
00068     }
00069 
00070     if (lines == 1) {
00071         p.drawText(offsetX, offsetY + (h/2) - (fontHeight/2),
00072                    w, fontHeight, Qt::AlignCenter, name());
00073     } else {
00074         p.drawText(offsetX, offsetY + (h/2),
00075                    w, fontHeight, Qt::AlignCenter, name());
00076     }
00077 
00078     if(m_bSelected) {
00079         drawSelected(&p, offsetX, offsetY);
00080     }
00081 }
00082 
00083 void ArtifactWidget::drawAsFile(QPainter& p, int offsetX, int offsetY)
00084 {
00085     const int w = width();
00086     const int h = height();
00087     QFont font = UMLWidget::font();
00088     const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
00089     const int fontHeight  = fm.lineSpacing();
00090 
00091     int startX = offsetX + (w/2) - 25;
00092     int iconHeight = h - fontHeight;
00093     QPolygon pointArray(5);
00094     pointArray.setPoint(0, startX, offsetY);
00095     pointArray.setPoint(1, startX + 40, offsetY);
00096     pointArray.setPoint(2, startX + 50, offsetY + 10);
00097     pointArray.setPoint(3, startX + 50, offsetY + iconHeight);
00098     pointArray.setPoint(4, startX, offsetY + iconHeight);
00099     p.drawPolygon(pointArray);
00100 
00101     p.drawLine(startX + 40, offsetY, startX + 40, offsetY + 10);
00102     p.drawLine(startX + 40, offsetY + 10, startX + 50, offsetY + 10);
00103     p.drawLine(startX + 40, offsetY, startX + 50, offsetY + 10);
00104 
00105     p.setPen( QPen(Qt::black) );
00106     p.setFont(font);
00107 
00108     p.drawText(offsetX, offsetY + h - fontHeight,
00109                w, fontHeight, Qt::AlignCenter, name());
00110 
00111     if(m_bSelected) {
00112         drawSelected(&p, offsetX, offsetY);
00113     }
00114 }
00115 
00116 void ArtifactWidget::drawAsLibrary(QPainter& p, int offsetX, int offsetY)
00117 {
00118     //FIXME this should have gears on it
00119     const int w = width();
00120     const int h = height();
00121     const QFont font = UMLWidget::font();
00122     const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
00123     const int fontHeight  = fm.lineSpacing();
00124 
00125     const int startX = offsetX + (w/2) - 25;
00126     const int iconHeight = h - fontHeight;
00127     QPolygon pointArray(5);
00128     pointArray.setPoint(0, startX, offsetY);
00129     pointArray.setPoint(1, startX + 40, offsetY);
00130     pointArray.setPoint(2, startX + 50, offsetY + 10);
00131     pointArray.setPoint(3, startX + 50, offsetY + iconHeight);
00132     pointArray.setPoint(4, startX, offsetY + iconHeight);
00133     p.drawPolygon(pointArray);
00134 
00135     p.drawLine(startX + 40, offsetY, startX + 40, offsetY + 10);
00136     p.drawLine(startX + 40, offsetY + 10, startX + 50, offsetY + 10);
00137     p.drawLine(startX + 40, offsetY, startX + 50, offsetY + 10);
00138 
00139     p.setPen( QPen(Qt::black) );
00140     p.setFont(font);
00141 
00142     p.drawText(offsetX, offsetY + h - fontHeight,
00143                w, fontHeight, Qt::AlignCenter, name());
00144 
00145     if(m_bSelected) {
00146         drawSelected(&p, offsetX, offsetY);
00147     }
00148 }
00149 
00150 void ArtifactWidget::drawAsTable(QPainter& p, int offsetX, int offsetY)
00151 {
00152     const int w = width();
00153     const int h = height();
00154     const QFont font = UMLWidget::font();
00155     const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
00156     const int fontHeight  = fm.lineSpacing();
00157 
00158     const int startX = offsetX + (w/2) - 25;
00159     const int iconHeight = h - fontHeight;
00160 
00161     p.drawRect(startX, offsetY, 50, h - fontHeight + 1);
00162     p.drawLine(startX + 20, offsetY, startX + 20, offsetY + iconHeight);
00163     p.drawLine(startX + 30, offsetY, startX + 30, offsetY + iconHeight);
00164     p.drawLine(startX + 40, offsetY, startX + 40, offsetY + iconHeight);
00165     p.drawLine(startX, offsetY + (iconHeight/2), startX + 49, offsetY + (iconHeight/2));
00166     p.drawLine(startX, offsetY + (iconHeight/2) + (iconHeight/4),
00167                startX + 49, offsetY + (iconHeight/2) + (iconHeight/4));
00168 
00169     QPen thickerPen = p.pen();
00170     thickerPen.setWidth(2);
00171     p.setPen(thickerPen);
00172     p.drawLine(startX + 10, offsetY, startX + 10, offsetY + iconHeight);
00173     p.drawLine(startX, offsetY + (iconHeight/4), startX + 50, offsetY + (iconHeight/4));
00174 
00175     p.setPen( QPen(Qt::black) );
00176     p.setFont(font);
00177 
00178     p.drawText(offsetX, offsetY + h - fontHeight,
00179                w, fontHeight, Qt::AlignCenter, name());
00180 
00181     if(m_bSelected) {
00182         drawSelected(&p, offsetX, offsetY);
00183     }
00184 }
00185 
00186 void ArtifactWidget::draw(QPainter& p, int offsetX, int offsetY)
00187 {
00188     UMLWidget::setPenFromSettings(p);
00189     if ( UMLWidget::getUseFillColour() ) {
00190         p.setBrush( UMLWidget::getFillColour() );
00191     } else {
00192         p.setBrush( m_pView->viewport()->palette().color(QPalette::Background) );
00193     }
00194 
00195     UMLArtifact *umlart = static_cast<UMLArtifact*>(m_pObject);
00196     UMLArtifact::Draw_Type drawType = umlart->getDrawAsType();
00197     switch (drawType) {
00198     case UMLArtifact::defaultDraw:
00199         return drawAsNormal(p, offsetX, offsetY);
00200         break;
00201     case UMLArtifact::file:
00202         return drawAsFile(p, offsetX, offsetY);
00203         break;
00204     case UMLArtifact::library:
00205         return drawAsLibrary(p, offsetX, offsetY);
00206         break;
00207     case UMLArtifact::table:
00208         return drawAsTable(p, offsetX, offsetY);
00209         break;
00210     default:
00211         uWarning() << "Artifact drawn as unknown type";
00212         break;
00213     }
00214 }
00215 
00216 QSize ArtifactWidget::calculateIconSize()
00217 {
00218     const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC);
00219     const int fontHeight  = fm.lineSpacing();
00220 
00221     int width = fm.width( m_pObject->getName() );
00222 
00223     width = width<50 ? 50 : width;
00224 
00225     int height = 50 + fontHeight;
00226 
00227     return QSize(width, height);
00228 }
00229 
00230 QSize ArtifactWidget::calculateNormalSize()
00231 {
00232     const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC);
00233     const int fontHeight  = fm.lineSpacing();
00234 
00235     int width = fm.width( m_pObject->getName() );
00236 
00237     int tempWidth = 0;
00238     if(!m_pObject->getStereotype().isEmpty()) {
00239         tempWidth = fm.width( m_pObject->getStereotype(true) );
00240     }
00241     width = tempWidth>width ? tempWidth : width;
00242     width += ARTIFACT_MARGIN * 2;
00243 
00244     int height = (2*fontHeight) + (ARTIFACT_MARGIN * 2);
00245 
00246     return QSize(width, height);
00247 }
00248 
00249 QSize ArtifactWidget::calculateSize()
00250 {
00251     if ( !m_pObject) {
00252         return UMLWidget::calculateSize();
00253     }
00254     UMLArtifact *umlart = static_cast<UMLArtifact*>(m_pObject);
00255     if (umlart->getDrawAsType() == UMLArtifact::defaultDraw) {
00256         return calculateNormalSize();
00257     } else {
00258         return calculateIconSize();
00259     }
00260 }
00261 
00262 void ArtifactWidget::saveToXMI(QDomDocument& qDoc, QDomElement& qElement)
00263 {
00264     QDomElement conceptElement = qDoc.createElement("artifactwidget");
00265     UMLWidget::saveToXMI(qDoc, conceptElement);
00266     qElement.appendChild(conceptElement);
00267 }
00268 

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdesdk

Skip menu "kdesdk"
  • kapptemplate
  • kate
  •     kate
  • kbugbuster
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello
Generated for kdesdk by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal