1
# -*- coding: utf-8 -*-
3
# Copyright (c) 2004 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
7
Module implementing a module widget.
11
from qtcanvas import *
13
from UMLWidget import UMLWidget
17
Class implementing the module model.
19
def __init__(self, name, classlist=[]):
23
@param name the module name (string)
24
@param classlist list of class names (list of strings)
27
self.classlist = classlist
29
def addClass(self, classname):
31
Method to add a class to the module model.
33
@param classname class name to be added (string)
35
self.classlist.append(classname)
39
Method to retrieve the classes of the module.
41
@return list of class names (list of strings)
43
return self.classlist[:]
47
Method to retrieve the module name.
49
@return module name (string)
53
class ModuleWidget(UMLWidget):
55
Class implementing a module widget.
57
def __init__(self, canvas, model=None, x=0, y=0, rounded=0):
61
@param canvas canvas containing the class widget (QCanvas)
62
@param model module model containing the module data (ModuleModel)
63
@param x x-coordinate (integer)
64
@param y y-coordinate (integer)
65
@param rounded flag indicating a rounded corner (boolean)
67
UMLWidget.__init__(self, canvas, x, y, rounded)
75
def calculateSize(self):
77
Method to calculate the size of the module widget.
79
if self.model is None:
82
classes = self.model.getClasses()
84
font = QFont(self.font)
87
fm = QFontMetrics(font)
90
fontHeight = fm.lineSpacing()
96
height = lines * fontHeight
99
width = fm.width(self.model.getName())
103
width = max(w, width)
105
width += self.margin * 2
106
width += 4 # a little bit more for strange fonts
107
height += self.margin * 4
109
self.setSize(width, height)
111
def setModel(self, model):
113
Method to set the module model.
115
@param model module model containing the module data (ModuleModel)
121
def drawShape(self, painter):
123
Overriden method to draw the shape.
125
@param painter painter the shape is drawn to (QPainter)
127
painter.setPen(Qt.black)
132
fm = QFontMetrics(self.font)
133
fontHeight = fm.lineSpacing() + 1 # one for the baseline itself
135
painter.drawRect(offsetX, offsetY, w, h)
139
painter.setFont(self.font)
140
painter.drawText(offsetX + self.margin,
145
self.model.getName())
146
y += fontHeight + self.margin
148
painter.setFont(self.font)
149
painter.drawLine(offsetX, offsetY + y,
150
offsetX + w - 1, offsetY + y)
153
classes = self.model.getClasses()
156
painter.drawText(offsetX + self.margin,
164
painter.drawText(offsetX + self.margin,
172
if self.isSelected():
173
self.drawSelected(painter, offsetX, offsetY)