Changeset 1058

Show
Ignore:
Timestamp:
10/31/06 16:08:10 (2 years ago)
Author:
wrobell
Message:

- align name of package, action and use case using styles

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/branches/new-canvas/gaphor/diagram/action.py

    r1033 r1058  
    66 
    77from gaphor import UML 
    8 from gaphor.diagram.nameditem import NamedItem 
     8from gaphor.diagram.nameditem import NamedItem, ALIGN_CENTER, ALIGN_MIDDLE 
    99from gaphas.util import text_align, text_extents 
    1010 
    1111class ActionItem(NamedItem): 
    12     __uml__      = UML.Action 
    13 #    __s_valign__ = V_ALIGN_MIDDLE 
     12    __uml__   = UML.Action 
     13    __style__ = { 
     14        'name-align': (ALIGN_CENTER, ALIGN_MIDDLE), 
     15    } 
    1416 
    1517    def draw(self, context): 
  • gaphor/branches/new-canvas/gaphor/diagram/nameditem.py

    r1039 r1058  
    44""" 
    55 
     6# padding 
     7PADDING_TOP, PADDING_RIGHT, PADDING_BOTTOM, PADDING_LEFT = range(4) 
     8# horizontal align 
     9ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT = range(3) 
     10# vertical align 
     11ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM = range(3) 
     12 
     13 
    614from gaphor.diagram.elementitem import ElementItem 
    7  
    815from gaphas.util import text_align, text_extents 
    916 
    1017 
    1118class NamedItem(ElementItem): 
     19 
     20    __style__ = { 
     21        'name-align'  : (ALIGN_CENTER, ALIGN_TOP), 
     22        'name-padding': (5, 10, 5, 10), 
     23        'name-outside': False, 
     24    } 
     25 
    1226    popup_menu = ElementItem.popup_menu + ( 
    1327        'RenameItem', 
     
    4054        if text: 
    4155            width, height = text_extents(cr, text) 
    42             self.min_width, self.min_height = width + 10, height + 20 
     56            self.min_width, self.min_height = \ 
     57                get_min_size(width, height, self.style.name_padding) 
    4358        super(NamedItem, self).pre_update(context) 
    4459 
     
    4863        Draw item's name. 
    4964        """ 
    50         c = context.cairo 
    51         rx = self.width / 2.0 
    52         ry = self.height / 2.0 
     65        cr = context.cairo 
    5366 
    5467        text = self.subject.name 
    5568        if text: 
    56             text_align(c, rx, ry, text, align_x = 0) 
     69            x, y = get_pos(cr, text, self.width, self.height, 
     70                    self.style.name_align, self.style.name_padding, 
     71                    self.style.name_outside) 
     72            cr.move_to(x, y) 
     73            cr.show_text(text) 
     74        super(NamedItem, self).draw(context) 
     75 
     76 
     77         
     78 
     79def get_min_size(width, height, padding): 
     80    """ 
     81    Get minimum size of an object using padding information. 
     82 
     83    @param width: object width 
     84    @param height: object height 
     85    @param padding: padding information as a tuple 
     86        (top, right, bottom, left) 
     87 
     88    fixme: move this method outside the class some utility function to 
     89        other package? 
     90    """ 
     91    return width + padding[PADDING_LEFT] + padding[PADDING_RIGHT], \ 
     92        height + padding[PADDING_TOP] + padding[PADDING_BOTTOM] 
     93 
     94 
     95def get_pos(cr, text, width, height, align, padding, outside): 
     96    """ 
     97    Calculate position of the text relative to containing box defined by 
     98    tuple (0, 0, width, height).  Text is aligned using align and padding 
     99    information. It can be also placed outside the box if @C{outside} 
     100    parameter is set to @C{True}. 
     101 
     102    @param width:   width of the containing box 
     103    @param height:  height of the containing box 
     104    @param align:   text align information (center, top, etc.) 
     105    @param padding: text padding 
     106    @param outside: should text be put outside containing box 
     107 
     108    fixme: move this method outside the class some utility function to 
     109        other package? 
     110    """ 
     111    assert text 
     112 
     113    x_bear, y_bear, w, h, x_adv, y_adv = cr.text_extents(text) 
     114 
     115    halign, valign = align 
     116 
     117    if outside: 
     118        if halign == ALIGN_LEFT: 
     119            x = -w - padding[PADDING_LEFT] 
     120        elif halign == ALIGN_CENTER: 
     121            x = (width - w) / 2 
     122        elif halign == ALIGN_RIGHT: 
     123            x = width + padding[PADDING_RIGHT] 
     124        else: 
     125            assert False 
     126 
     127        if valign == ALIGN_TOP: 
     128            y = -h - padding[PADDING_TOP] 
     129        elif valign == ALIGN_MIDDLE: 
     130            y = (height - h) / 2 
     131        elif valign == ALIGN_BOTTOM: 
     132            y = height + padding[PADDING_BOTTOM] 
     133        else: 
     134            assert False 
     135 
     136    else: 
     137        if halign == ALIGN_LEFT: 
     138            x = padding[PADDING_LEFT] 
     139        elif halign == ALIGN_CENTER: 
     140            x = (width - w) / 2 
     141        elif halign == ALIGN_RIGHT: 
     142            x = width - w - padding[PADDING_RIGHT] 
     143        else: 
     144            assert False 
     145 
     146        if valign == ALIGN_TOP: 
     147            y = h + padding[PADDING_TOP] 
     148        elif valign == ALIGN_MIDDLE: 
     149            y = (height + h) / 2 
     150        elif valign == ALIGN_BOTTOM: 
     151            y = height - h - padding[PADDING_BOTTOM] 
     152        else: 
     153            assert False 
     154    return x, y 
    57155 
    58156 
  • gaphor/branches/new-canvas/gaphor/diagram/package.py

    r1033 r1058  
    66from gaphor import UML 
    77from gaphor.diagram.nameditem import NamedItem 
    8 from gaphor.diagram.align import MARGIN_TOP 
    98import font 
    109 
     
    1413    __stereotype__ = { 
    1514        'profile': UML.Profile, 
     15    } 
     16    __style__ = { 
     17        'name-padding': (35, 10, 5, 10), 
    1618    } 
    1719 
  • gaphor/branches/new-canvas/gaphor/diagram/usecase.py

    r1046 r1058  
    77from gaphor import UML 
    88from gaphor.diagram.classifier import ClassifierItem 
     9from gaphor.diagram.nameditem import ALIGN_CENTER, ALIGN_MIDDLE 
    910from gaphas.util import text_align, text_extents, path_ellipse 
    1011 
     
    1314    """ 
    1415    __uml__ = UML.UseCase 
     16    __style__ = { 
     17        'name-align'  : (ALIGN_CENTER, ALIGN_MIDDLE), 
     18    } 
    1519 
    1620    def __init__(self, id): 
    1721        ClassifierItem.__init__(self, id, 50, 30) 
    1822        self.drawing_style = -1 
     23 
    1924 
    2025    def pre_update(self, context): 
     
    2530            self.min_width, self.min_height = width + 10, height + 20 
    2631        super(UseCaseItem, self).pre_update(context) 
     32 
    2733 
    2834    def draw(self, context): 
     
    3642        c.stroke() 
    3743 
    38         text = self.subject.name 
    39         if text: 
    40             text_align(c, rx, ry, text, align_x=0) 
     44        super(UseCaseItem, self).draw(context) 
    4145 
    4246