root/gaphor/trunk/gaphor/diagram/component.py

Revision 1441, 1.3 kB (checked in by wrobe..@pld-linux.org, 1 year ago)

- use padding information to align in the centre
- fixed component name padding
- fixed classifier minimal size calculation for comparment (so item can be

scaled down) and for comparment + icon (so item's icon is taken into
minimal width calculation)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 """
2 Component item.
3 """
4
5 from gaphor import UML
6 from gaphor.diagram.classifier import ClassifierItem
7
8 class ComponentItem(ClassifierItem):
9
10     __uml__  = UML.Component
11     __icon__ = True
12
13     __style__ = {
14             'name-padding': (10, 25, 10, 10),
15     }
16
17     BAR_WIDTH     = 10
18     BAR_HEIGHT    =  5
19     BAR_PADDING   =  5
20
21     def __init__(self, id=None):
22         ClassifierItem.__init__(self, id)
23         # Set drawing style to compartment w// small icon
24         self.drawing_style = self.DRAW_COMPARTMENT_ICON
25
26     def draw_compartment_icon(self, context):
27         cr = context.cairo
28         cr.save()
29         self.draw_compartment(context)
30         cr.restore()
31
32         ix, iy = self.get_icon_pos()
33
34         cr.set_line_width(1.0)
35         cr.rectangle(ix, iy, self.ICON_WIDTH, self.ICON_HEIGHT)
36         cr.stroke()
37
38         bx = ix - self.BAR_PADDING
39         bar_upper_y = iy + self.BAR_PADDING
40         bar_lower_y = iy + self.BAR_PADDING * 3
41
42         color = cr.get_source()
43         cr.rectangle(bx, bar_lower_y, self.BAR_WIDTH, self.BAR_HEIGHT)
44         cr.set_source_rgb(1,1,1) # white
45         cr.fill_preserve()
46         cr.set_source(color)
47         cr.stroke()
48
49         cr.rectangle(bx, bar_upper_y, self.BAR_WIDTH, self.BAR_HEIGHT)
50         cr.set_source_rgb(1,1,1) # white
51         cr.fill_preserve()
52         cr.set_source(color)
53         cr.stroke()
54
55
56
57 # vim:sw=4:et
Note: See TracBrowser for help on using the browser.