~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to umbrello/umbrello/regionwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *                                                                         *
 
3
 *   This program is free software; you can redistribute it and/or modify  *
 
4
 *   it under the terms of the GNU General Public License as published by  *
 
5
 *   the Free Software Foundation; either version 2 of the License, or     *
 
6
 *   (at your option) any later version.                                   *
 
7
 *                                                                         *
 
8
 *   copyright (C) 2002-2008                                               *
 
9
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 
10
 ***************************************************************************/
 
11
 
 
12
// own header
 
13
#include "regionwidget.h"
 
14
 
 
15
// qt includes
 
16
#include <qevent.h>
 
17
#include <QPolygon>
 
18
 
 
19
// kde includes
 
20
#include <klocale.h>
 
21
#include <kdebug.h>
 
22
#include <kinputdialog.h>
 
23
 
 
24
// app includes
 
25
#include "uml.h"
 
26
#include "umldoc.h"
 
27
#include "docwindow.h"
 
28
#include "umlwidget.h"
 
29
#include "umlview.h"
 
30
#include "floatingtextwidget.h"
 
31
 
 
32
RegionWidget::RegionWidget(UMLView * view, Uml::IDType id)
 
33
        : UMLWidget(view, id) {
 
34
     UMLWidget::setBaseType( Uml::wt_Region );
 
35
    updateComponentSize();
 
36
}
 
37
 
 
38
RegionWidget::~RegionWidget() {}
 
39
 
 
40
void RegionWidget::draw(QPainter & p, int offsetX, int offsetY)
 
41
{
 
42
    setPenFromSettings(p);
 
43
    const int w = width();
 
44
    const int h = height();
 
45
    QPen pen = p.pen();
 
46
    {
 
47
        setPenFromSettings(p);
 
48
        pen.setColor ( Qt::red );
 
49
        pen.setStyle ( Qt::DashLine );
 
50
        p.setPen( pen );
 
51
        p.drawRoundRect(offsetX, offsetY, w, h, (h * 60) / w, 60);
 
52
 
 
53
    }
 
54
    if(m_bSelected)
 
55
        drawSelected(&p, offsetX, offsetY);
 
56
}
 
57
 
 
58
QSize RegionWidget::calculateSize() {
 
59
 
 
60
    int width = 10, height = 10;
 
61
    const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
 
62
    const int fontHeight  = fm.lineSpacing();
 
63
    int textWidth = fm.width(getName());
 
64
 
 
65
    height  = fontHeight;
 
66
    width   = textWidth > REGION_WIDTH?textWidth:REGION_WIDTH;
 
67
    height  = height > REGION_HEIGHT ? height : REGION_HEIGHT;
 
68
    width  += REGION_MARGIN * 2;
 
69
    height += REGION_MARGIN * 2;
 
70
 
 
71
    return QSize(width, height);
 
72
}
 
73
 
 
74
void RegionWidget::setName(const QString &strName) {
 
75
    m_Text = strName;
 
76
    updateComponentSize();
 
77
    adjustAssocs( getX(), getY() );
 
78
}
 
79
 
 
80
QString RegionWidget::getName() const {
 
81
    return m_Text;
 
82
}
 
83
 
 
84
 
 
85
void RegionWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
 
86
    QDomElement regionElement = qDoc.createElement( "regionwidget" );
 
87
    UMLWidget::saveToXMI( qDoc, regionElement );
 
88
    regionElement.setAttribute( "regionname", m_Text );
 
89
    regionElement.setAttribute( "documentation", m_Doc );
 
90
 
 
91
    qElement.appendChild( regionElement );
 
92
}
 
93
 
 
94
bool RegionWidget::loadFromXMI( QDomElement & qElement ) {
 
95
    if( !UMLWidget::loadFromXMI( qElement ) )
 
96
        return false;
 
97
    m_Text = qElement.attribute( "regionname", "" );
 
98
    m_Doc = qElement.attribute( "documentation", "" );
 
99
    return true;
 
100
}
 
101
 
 
102
 
 
103
#include "regionwidget.moc"
 
104