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

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
  • widgets
artifactwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2003-2013 *
8  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9  ***************************************************************************/
10 
11 // own header
12 #include "artifactwidget.h"
13 
14 // app includes
15 #include "artifact.h"
16 #include "debug_utils.h"
17 #include "umlscene.h"
18 #include "umlview.h"
19 
26 ArtifactWidget::ArtifactWidget(UMLScene *scene, UMLArtifact *a)
27  : UMLWidget(scene, WidgetBase::wt_Artifact, a)
28 {
29  setSize(100, 30);
30 }
31 
35 ArtifactWidget::~ArtifactWidget()
36 {
37 }
38 
43 void ArtifactWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
44 {
45  Q_UNUSED(option);
46  Q_UNUSED(widget);
47 
48  UMLWidget::setPenFromSettings(painter);
49  if (UMLWidget::useFillColor()) {
50  painter->setBrush(UMLWidget::fillColor());
51  } else {
52  painter->setBrush(m_scene->activeView()->viewport()->palette().color(QPalette::Background));
53  }
54 
55  if (umlObject()) {
56  UMLArtifact *umlart = static_cast<UMLArtifact*>(m_umlObject);
57  UMLArtifact::Draw_Type drawType = umlart->getDrawAsType();
58  switch (drawType) {
59  case UMLArtifact::defaultDraw:
60  paintAsNormal(painter);
61  break;
62  case UMLArtifact::file:
63  paintAsFile(painter);
64  break;
65  case UMLArtifact::library:
66  paintAsLibrary(painter);
67  break;
68  case UMLArtifact::table:
69  paintAsTable(painter);
70  break;
71  default:
72  uWarning() << "Artifact drawn as unknown type";
73  break;
74  }
75  }
76  else {
77  uWarning() << "Cannot draw as there is no UMLArtifact for this widget.";
78  }
79 }
80 
85 void ArtifactWidget::saveToXMI(QDomDocument& qDoc, QDomElement& qElement)
86 {
87  QDomElement conceptElement = qDoc.createElement("artifactwidget");
88  UMLWidget::saveToXMI(qDoc, conceptElement);
89  qElement.appendChild(conceptElement);
90 }
91 
95 QSizeF ArtifactWidget::minimumSize()
96 {
97  if (!m_umlObject) {
98  return UMLWidget::minimumSize();
99  }
100  UMLArtifact *umlart = static_cast<UMLArtifact*>(m_umlObject);
101  if (umlart->getDrawAsType() == UMLArtifact::defaultDraw) {
102  return calculateNormalSize();
103  } else {
104  return calculateIconSize();
105  }
106 }
107 
111 QSize ArtifactWidget::calculateIconSize()
112 {
113  const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC);
114  const int fontHeight = fm.lineSpacing();
115 
116  int width = fm.width(m_umlObject->name());
117 
118  width = width<50 ? 50 : width;
119 
120  int height = 50 + fontHeight;
121 
122  return QSize(width, height);
123 }
124 
128 QSize ArtifactWidget::calculateNormalSize()
129 {
130  const QFontMetrics &fm = getFontMetrics(FT_BOLD_ITALIC);
131  const int fontHeight = fm.lineSpacing();
132 
133  int width = fm.width(m_umlObject->name());
134 
135  int tempWidth = 0;
136  if(!m_umlObject->stereotype().isEmpty()) {
137  tempWidth = fm.width(m_umlObject->stereotype(true));
138  }
139  width = tempWidth>width ? tempWidth : width;
140  width += ARTIFACT_MARGIN * 2;
141 
142  int height = (2*fontHeight) + (ARTIFACT_MARGIN * 2);
143 
144  return QSize(width, height);
145 }
146 
150 void ArtifactWidget::paintAsFile(QPainter *painter)
151 {
152  const int w = width();
153  const int h = height();
154  QFont font = UMLWidget::font();
155  const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
156  const int fontHeight = fm.lineSpacing();
157 
158  int startX = (w/2) - 25;
159  int iconHeight = h - fontHeight;
160  QPolygon pointArray(5);
161  pointArray.setPoint(0, startX, 0);
162  pointArray.setPoint(1, startX + 40, 0);
163  pointArray.setPoint(2, startX + 50, 10);
164  pointArray.setPoint(3, startX + 50, iconHeight);
165  pointArray.setPoint(4, startX, iconHeight);
166  painter->drawPolygon(pointArray);
167 
168  painter->drawLine(startX + 40, 0, startX + 40, 10);
169  painter->drawLine(startX + 40, 10, startX + 50, 10);
170  painter->drawLine(startX + 40, 0, startX + 50, 10);
171 
172  painter->setPen(textColor());
173  painter->setFont(font);
174 
175  painter->drawText(0, h - fontHeight,
176  w, fontHeight, Qt::AlignCenter, name());
177 
178  UMLWidget::paint(painter, 0);
179 }
180 
184 void ArtifactWidget::paintAsLibrary(QPainter *painter)
185 {
186  //FIXME this should have gears on it
187  const int w = width();
188  const int h = height();
189  const QFont font = UMLWidget::font();
190  const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
191  const int fontHeight = fm.lineSpacing();
192 
193  const int startX = (w/2) - 25;
194  const int iconHeight = h - fontHeight;
195  QPolygon pointArray(5);
196  pointArray.setPoint(0, startX, 0);
197  pointArray.setPoint(1, startX + 40, 0);
198  pointArray.setPoint(2, startX + 50, 10);
199  pointArray.setPoint(3, startX + 50, iconHeight);
200  pointArray.setPoint(4, startX, iconHeight);
201  painter->drawPolygon(pointArray);
202 
203  painter->drawLine(startX + 40, 0, startX + 40, 10);
204  painter->drawLine(startX + 40, 10, startX + 50, 10);
205  painter->drawLine(startX + 40, 0, startX + 50, 10);
206 
207  painter->setPen(textColor());
208  painter->setFont(font);
209 
210  painter->drawText(0, h - fontHeight,
211  w, fontHeight, Qt::AlignCenter, name());
212 
213  UMLWidget::paint(painter, 0);
214 }
215 
219 void ArtifactWidget::paintAsTable(QPainter *painter)
220 {
221  const int w = width();
222  const int h = height();
223  const QFont font = UMLWidget::font();
224  const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
225  const int fontHeight = fm.lineSpacing();
226 
227  const int startX = (w/2) - 25;
228  const int iconHeight = h - fontHeight;
229 
230  painter->drawRect(startX, 0, 50, h - fontHeight + 1);
231  painter->drawLine(startX + 20, 0, startX + 20, iconHeight);
232  painter->drawLine(startX + 30, 0, startX + 30, iconHeight);
233  painter->drawLine(startX + 40, 0, startX + 40, iconHeight);
234  painter->drawLine(startX, (iconHeight/2), startX + 49, (iconHeight/2));
235  painter->drawLine(startX, (iconHeight/2) + (iconHeight/4),
236  startX + 49, (iconHeight/2) + (iconHeight/4));
237 
238  QPen thickerPen = painter->pen();
239  thickerPen.setWidth(2);
240  painter->setPen(thickerPen);
241  painter->drawLine(startX + 10, 0, startX + 10, iconHeight);
242  painter->drawLine(startX, (iconHeight/4), startX + 50, (iconHeight/4));
243 
244  painter->setPen(textColor());
245  painter->setFont(font);
246 
247  painter->drawText(0, h - fontHeight,
248  w, fontHeight, Qt::AlignCenter, name());
249 
250  UMLWidget::paint(painter, 0);
251 }
252 
256 void ArtifactWidget::paintAsNormal(QPainter *painter)
257 {
258  int w = width();
259  int h = height();
260  QFont font = UMLWidget::font();
261  font.setBold(true);
262  const QFontMetrics &fm = getFontMetrics(FT_BOLD);
263  const int fontHeight = fm.lineSpacing();
264  QString stereotype = m_umlObject->stereotype();
265 
266  painter->drawRect(0, 0, w, h);
267 
268  painter->setPen(textColor());
269  painter->setFont(font);
270 
271  if (!stereotype.isEmpty()) {
272  painter->drawText(ARTIFACT_MARGIN, (h/2) - fontHeight,
273  w, fontHeight, Qt::AlignCenter, m_umlObject->stereotype(true));
274  }
275 
276  int lines;
277  if (!stereotype.isEmpty()) {
278  lines = 2;
279  } else {
280  lines = 1;
281  }
282 
283  if (lines == 1) {
284  painter->drawText(0, (h/2) - (fontHeight/2),
285  w, fontHeight, Qt::AlignCenter, name());
286  } else {
287  painter->drawText(0, (h/2),
288  w, fontHeight, Qt::AlignCenter, name());
289  }
290 
291  UMLWidget::paint(painter, 0);
292 }
293 
UMLArtifact::table
Definition: artifact.h:39
WidgetBase::umlObject
UMLObject * umlObject() const
Returns the UMLObject set to represent.
Definition: widgetbase.cpp:113
UMLWidget::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Draws the UMLWidget on the given paint device.
Definition: umlwidget.cpp:1565
WidgetBase::fillColor
QColor fillColor() const
Returns fill color.
Definition: widgetbase.cpp:265
umlview.h
UMLWidget::minimumSize
virtual QSizeF minimumSize()
Compute the minimum possible width and height.
Definition: umlwidget.cpp:185
WidgetBase
Common base class for UMLWidget and AssociationWidget.
Definition: widgetbase.h:35
UMLArtifact::getDrawAsType
Draw_Type getDrawAsType()
Returns the value of m_drawAsType.
Definition: artifact.cpp:86
umlscene.h
ARTIFACT_MARGIN
#define ARTIFACT_MARGIN
Definition: artifactwidget.h:19
QWidget
UMLWidget::FT_NORMAL
Definition: umlwidget.h:220
ArtifactWidget::saveToXMI
virtual void saveToXMI(QDomDocument &qDoc, QDomElement &qElement)
Reimplemented from WidgetBase::saveToXMI to save the widget to the "artifactwidget" XMI element...
Definition: artifactwidget.cpp:85
UMLWidget::setSize
void setSize(qreal width, qreal height)
Sets the size.
Definition: umlwidget.cpp:1452
WidgetBase::textColor
QColor textColor() const
Returns text color.
Definition: widgetbase.cpp:223
UMLWidget::getFontMetrics
QFontMetrics & getFontMetrics(UMLWidget::FontType fontType)
Returns the font metric used by this object for Text which uses bold/italic fonts.
Definition: umlwidget.cpp:1619
UMLWidget::height
qreal height() const
Returns the height of widget.
Definition: umlwidget.h:122
uWarning
#define uWarning()
Definition: debug_utils.h:97
WidgetBase::name
QString name() const
Gets the name from the corresponding UMLObject if this widget has an underlying UMLObject; if it does...
Definition: widgetbase.cpp:197
WidgetBase::useFillColor
bool useFillColor()
Return state of fill color usage.
Definition: widgetbase.cpp:307
debug_utils.h
WidgetBase::m_umlObject
UMLObject * m_umlObject
Definition: widgetbase.h:155
ArtifactWidget::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented to paint the articraft widget.
Definition: artifactwidget.cpp:43
UMLArtifact::defaultDraw
Definition: artifact.h:36
ArtifactWidget::ArtifactWidget
ArtifactWidget(UMLScene *scene, UMLArtifact *a)
Constructs a ArtifactWidget.
Definition: artifactwidget.cpp:26
UMLArtifact::Draw_Type
Draw_Type
Artifacts can be drawn using one of several icons.
Definition: artifact.h:35
ArtifactWidget::~ArtifactWidget
virtual ~ArtifactWidget()
Destructor.
Definition: artifactwidget.cpp:35
UMLObject::stereotype
QString stereotype(bool includeAdornments=false) const
Returns the stereotype.
Definition: umlobject.cpp:581
artifactwidget.h
UMLArtifact::file
Definition: artifact.h:37
UMLWidget::FT_BOLD
Definition: umlwidget.h:221
UMLArtifact
This class contains the non-graphical information required for a UML Artifact.
Definition: artifact.h:27
UMLWidget::saveToXMI
virtual void saveToXMI(QDomDocument &qDoc, QDomElement &qElement)
A virtual method to save the properties of this widget into a QDomElement i.e xml.
Definition: umlwidget.cpp:1707
UMLScene::activeView
UMLView * activeView() const
Returns the active view associated with this scene.
Definition: umlscene.cpp:193
UMLWidget::setPenFromSettings
void setPenFromSettings(QPainter &p)
Set the pen.
Definition: umlwidget.cpp:1101
ArtifactWidget::minimumSize
QSizeF minimumSize()
Overrides method from UMLWidget.
Definition: artifactwidget.cpp:95
UMLWidget::width
qreal width() const
Returns the width of the widget.
Definition: umlwidget.h:129
UMLArtifact::library
Definition: artifact.h:38
UMLWidget::FT_BOLD_ITALIC
Definition: umlwidget.h:224
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
WidgetBase::font
virtual QFont font() const
Returns the font used for diaplaying any text.
Definition: widgetbase.cpp:431
artifact.h
UMLScene
UMLScene instances represent diagrams.
Definition: umlscene.h:70
WidgetBase::m_scene
UMLScene * m_scene
Definition: widgetbase.h:154
UMLWidget
This is the base class for nearly all graphical widgets.
Definition: umlwidget.h:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:05:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

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

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal