• 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
actorwidget.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) 2002-2013 *
8  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9  ***************************************************************************/
10 
11 // own header file
12 #include "actorwidget.h"
13 
14 // local includes
15 #include "actor.h"
16 #include "umlview.h"
17 
24 ActorWidget::ActorWidget(UMLScene * scene, UMLActor *a)
25  : UMLWidget(scene, WidgetBase::wt_Actor, a)
26 {
27 }
28 
32 ActorWidget::~ActorWidget()
33 {
34 }
35 
39 void ActorWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
40 {
41  Q_UNUSED(option);
42  Q_UNUSED(widget);
43  UMLWidget::setPenFromSettings(painter);
44  if(UMLWidget::useFillColor())
45  painter->setBrush(UMLWidget::fillColor());
46  const int w = width();
47  const int h = height();
48  painter->setFont(UMLWidget::font());
49  const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
50  const int textWidth = fm.width(name());
51  const int fontHeight = fm.lineSpacing();
52  const int a_height = h - fontHeight - A_MARGIN;
53  const int h2 = a_height / 2;
54  const int w2 = w - A_MARGIN * 2;
55  const int a_width = (h2 > w2 || w > textWidth + A_MARGIN * 2 ? w2 : h2);
56  const int middleX = w / 2;
57  const int thirdY = a_height / 3;
58 
59  //draw actor
60  painter->drawEllipse(middleX - a_width / 2, 0, a_width, thirdY); //head
61  painter->drawLine(middleX, thirdY,
62  middleX, thirdY * 2); //body
63  painter->drawLine(middleX, 2 * thirdY,
64  middleX - a_width / 2, a_height); //left leg
65  painter->drawLine(middleX, 2 * thirdY,
66  middleX + a_width / 2, a_height); //right leg
67  painter->drawLine(middleX - a_width / 2, thirdY + thirdY / 2,
68  middleX + a_width / 2, thirdY + thirdY / 2); //arms
69  //draw text
70  painter->setPen(textColor());
71  painter->drawText(A_MARGIN, h - fontHeight,
72  w - A_MARGIN * 2, fontHeight, Qt::AlignCenter, name());
73  UMLWidget::paint(painter, option, widget);
74 }
75 
80 void ActorWidget::saveToXMI(QDomDocument & qDoc, QDomElement & qElement)
81 {
82  QDomElement actorElement = qDoc.createElement("actorwidget");
83  UMLWidget::saveToXMI(qDoc, actorElement);
84  qElement.appendChild(actorElement);
85 }
86 
90 QSizeF ActorWidget::minimumSize()
91 {
92  const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
93  const int fontHeight = fm.lineSpacing();
94  const int textWidth = fm.width(name());
95  int width = textWidth > A_WIDTH ? textWidth : A_WIDTH;
96  int height = A_HEIGHT + fontHeight + A_MARGIN;
97  width += A_MARGIN * 2;
98  return QSizeF(width, height);
99 }
100 
101 
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
ActorWidget::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Overrides the standard paint event.
Definition: actorwidget.cpp:39
WidgetBase
Common base class for UMLWidget and AssociationWidget.
Definition: widgetbase.h:35
A_HEIGHT
#define A_HEIGHT
Definition: actorwidget.h:17
QWidget
UMLWidget::FT_NORMAL
Definition: umlwidget.h:220
A_MARGIN
#define A_MARGIN
Definition: actorwidget.h:18
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
actorwidget.h
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
ActorWidget::~ActorWidget
virtual ~ActorWidget()
Destructor.
Definition: actorwidget.cpp:32
actor.h
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
A_WIDTH
#define A_WIDTH
Definition: actorwidget.h:16
ActorWidget::ActorWidget
ActorWidget(UMLScene *scene, UMLActor *o)
Constructs an ActorWidget.
Definition: actorwidget.cpp:24
UMLWidget::setPenFromSettings
void setPenFromSettings(QPainter &p)
Set the pen.
Definition: umlwidget.cpp:1101
UMLWidget::width
qreal width() const
Returns the width of the widget.
Definition: umlwidget.h:129
UMLActor
This class contains the non-graphical information required for a UML Actor.
Definition: actor.h:27
ActorWidget::minimumSize
QSizeF minimumSize()
Overrides method from UMLWidget.
Definition: actorwidget.cpp:90
ActorWidget::saveToXMI
virtual void saveToXMI(QDomDocument &qDoc, QDomElement &qElement)
Saves the widget to the "actorwidget" XMI element.
Definition: actorwidget.cpp:80
WidgetBase::font
virtual QFont font() const
Returns the font used for diaplaying any text.
Definition: widgetbase.cpp:431
UMLScene
UMLScene instances represent diagrams.
Definition: umlscene.h:70
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