Changeset 1193

Show
Ignore:
Timestamp:
04/04/07 22:50:42 (1 year ago)
Author:
arj..@yirdis.nl
Message:

Fixed text editing of classifiers. Also some text placement has been improved.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/adapters/editors.py

    r1121 r1193  
    154154 
    155155        self._edit = None 
     156        # Edit is in name compartment -> edit name 
    156157        name_comp_height = self._item.get_name_size()[1] 
    157158        if y < name_comp_height: 
    158159            self._edit = self._item 
    159160            return True 
     161 
     162        padding = self._item.style.compartment_padding 
     163        vspacing = self._item.style.compartment_vspacing 
     164         
     165        # place offset at top of first comparement 
    160166        y -= name_comp_height 
    161         margin = self._item.style.compartment_margin[0] 
    162         vspacing = self._item.style.compartment_vspacing 
     167        y += vspacing / 2.0 
    163168        for comp in self._item.compartments: 
    164             y -= margin 
     169            y -= padding[0] 
    165170            for item in comp: 
    166                 y -= vspacing 
    167                 y -= item.height 
    168171                if y < item.height: 
    169172                    self._edit = item 
    170173                    return True 
    171             y -= margin 
     174                y -= item.height 
     175                y -= vspacing 
     176            y -= padding[2] 
     177            # Compensate for last substraction action 
     178            y += vspacing 
    172179        return False 
    173180 
  • gaphor/trunk/gaphor/diagram/__init__.py

    r1170 r1193  
    9797from gaphor.undomanager import get_undo_manager, transactional 
    9898 
    99 print 'state', state 
    10099state.observers.add(state.revert_handler) 
    101100 
  • gaphor/trunk/gaphor/diagram/activitynodes.py

    r1178 r1193  
    55import math 
    66 
    7 from gaphas.util import path_ellipse 
     7from gaphas.util import path_ellipse, text_align 
    88from gaphas.state import observed, reversible_property 
    99 
     
    217217 
    218218        if isinstance(self.subject, UML.JoinNode): 
    219             cr.move_to(self._join_spec_x, self._join_spec_y) 
    220             cr.show_text(self.subject.joinSpec.value
     219            text_align(cr, self._join_spec_x, self._join_spec_y, 
     220                       self.subject.joinSpec.value, align_x=1, align_y=1
    221221 
    222222        cr.stroke() 
  • gaphor/trunk/gaphor/diagram/association.py

    r1178 r1193  
    1616from math import atan2, pi 
    1717 
    18 from gaphas.util import text_extents, text_multiline 
     18from gaphas.util import text_extents, text_align, text_multiline 
    1919from gaphas.state import reversible_property 
    2020from gaphas import Item 
     
    368368 
    369369        if self.subject and self.subject.name: 
    370             cr.move_to(self._label_bounds[0], self._label_bounds[1]) 
    371             cr.show_text(self.subject.name or '') 
     370            #cr.move_to(self._label_bounds[0], self._label_bounds[1]) 
     371            #cr.show_text(self.subject.name or '') 
     372            text_align(cr, self._label_bounds[0], self._label_bounds[1], 
     373                       self.subject.name or '', align_x=1, align_y=1) 
    372374 
    373375 
     
    707709 
    708710        cr = context.cairo 
    709         #cr.move_to(self._name_bounds[0], self._name_bounds[3]) 
    710         #cr.show_text(self._name or '') 
    711         text_multiline(cr, self._name_bounds[0], self._name_bounds[3], self._name) 
    712         #cr.move_to(self._mult_bounds[0], self._mult_bounds[3]) 
    713         #cr.show_text(self._mult or '') 
    714         text_multiline(cr, self._mult_bounds[0], self._mult_bounds[3], self._mult) 
     711        text_multiline(cr, self._name_bounds[0], self._name_bounds[1], self._name) 
     712        text_multiline(cr, self._mult_bounds[0], self._mult_bounds[1], self._mult) 
    715713        cr.stroke() 
    716714 
  • gaphor/trunk/gaphor/diagram/classifier.py

    r1178 r1193  
    44import itertools 
    55 
    6 from gaphas.util import text_extents, text_center, text_set_font 
     6from gaphas.util import text_extents, text_align, text_set_font 
    77from gaphas.state import observed, reversible_property 
    88from gaphor import UML 
     
    1212from gaphor.diagram.feature import FeatureItem 
    1313 
    14 from gaphas.util import text_center 
    1514import font 
    1615 
     
    4746 
    4847    def pre_update(self, context): 
    49         """Pre update, determine width and height of the compartment. 
     48        """ 
     49        Pre update, determine width and height of the compartment. 
    5050        """ 
    5151        self.width = self.height = 0 
     
    5858            self.height = sum(map(lambda p: p[1], sizes)) 
    5959            vspacing = self.owner.style.compartment_vspacing 
    60             self.height += vspacing * len(sizes
     60            self.height += vspacing * (len(sizes) - 1
    6161        padding = self.owner.style.compartment_padding 
    6262        self.width += padding[1] + padding[3] 
     
    7777            cr.save() 
    7878            try: 
    79                 offset += item.height 
    80                 cr.move_to(0, offset) 
     79                cr.translate(0, offset) 
     80                #cr.move_to(0, offset) 
    8181                item.draw(context) 
    82                 offset += vspacing 
     82                offset += vspacing + item.height 
    8383            finally: 
    8484                cr.restore() 
     
    120120        'from-padding': (7, 2, 7, 2), 
    121121        'compartment-padding': (5, 5, 5, 5), # (top, right, bottom, left) 
    122         'compartment-vspacing': 2
     122        'compartment-vspacing': 3
    123123# Fix name, stereotype and from drawing! 
    124124        'name-padding': (10, 10, 10, 10), 
     
    355355            y += padding[0] 
    356356            text_set_font(cr, font.FONT) 
    357             text_center(cr, width / 2, y, self.stereotype) 
     357            text_align(cr, width / 2, y, self.stereotype) 
    358358            y += padding[2] 
    359359 
     
    364364        text_set_font(cr, self.subject.isAbstract and \ 
    365365                          font.FONT_ABSTRACT_NAME or font.FONT_NAME) 
    366         text_center(cr, width / 2, y + n_h/2, self.subject.name) 
     366        text_align(cr, width / 2, y + n_h/2, self.subject.name) 
    367367        y += padding[2] + n_h/2 
    368368 
     
    372372            y += padding[0] 
    373373            text_set_font(cr, font.FONT_SMALL) 
    374             text_center(cr, width / 2, y, self._from) 
     374            text_align(cr, width / 2, y, self._from) 
    375375            y += padding[2] 
    376376 
  • gaphor/trunk/gaphor/diagram/comment.py

    r1121 r1193  
    7979        if self.subject.body: 
    8080            # Do not print empty string, since cairo-win32 can't handle it. 
    81             text_multiline(c, 5, 5, self.subject.body, padding=2) 
     81            text_multiline(c, 5, 15, self.subject.body, padding=2) 
    8282            #c.move_to(10, 15) 
    8383            #c.show_text(self.subject.body) 
  • gaphor/trunk/gaphor/diagram/diagramline.py

    r1178 r1193  
    66 
    77import gaphas 
    8 from gaphas.util import text_extents 
     8from gaphas.util import text_extents, text_align 
    99from gaphas.geometry import Rectangle 
    1010from diagramitem import DiagramItem 
     
    7878        cr = context.cairo 
    7979        if self._stereotype: 
    80             cr.move_to(self._stereotype_bounds[0], self._stereotype_bounds[1]) 
    81             cr.show_text(self._stereotype
     80            text_align(cr, self._stereotype_bounds[0], self._stereotype_bounds[1], 
     81                       self._stereotype, align_x=1, align_y=1
    8282 
    8383 
  • gaphor/trunk/gaphor/diagram/feature.py

    r1178 r1193  
    88from diagramitem import DiagramItem 
    99from gaphor.diagram import DiagramItemMeta 
    10 from gaphas.util import text_extents, text_set_font 
     10from gaphas.util import text_extents, text_set_font, text_align 
    1111import font 
    1212 
     
    4141 
    4242    def get_size(self, update=False): 
    43         """Return the size of the feature. If update == True the item is 
     43        """ 
     44        Return the size of the feature. If update == True the item is 
    4445        directly updated. 
    4546        """ 
     
    127128        cr = context.cairo 
    128129        text_set_font(cr, font.FONT) 
    129         cr.show_text(self.subject.render() or '') 
     130        text_align(cr, 0, 0, self.subject.render() or '', align_x=1, align_y=1) 
     131        #cr.show_text(self.subject.render() or '') 
    130132 
    131133 
     
    178180        cr = context.cairo 
    179181        text_set_font(cr, font.FONT) 
    180         cr.show_text(self.subject.render() or '') 
     182        text_align(cr, 0, 0, self.subject.render() or '', align_x=1, align_y=1) 
     183        #cr.show_text(self.subject.render() or '') 
    181184 
    182185 
  • gaphor/trunk/gaphor/diagram/nameditem.py

    r1137 r1193  
    44""" 
    55 
    6 from gaphas.util import text_extents 
     6from gaphas.util import text_extents, text_align 
    77 
    88from gaphor.diagram.elementitem import ElementItem 
     
    9191        text = self.subject.name 
    9292        if text: 
    93             cr.move_to(self.name_x, self.name_y) 
    94             cr.show_text(text) 
     93            #cr.move_to(self.name_x, self.name_y) 
     94            #cr.show_text(text) 
     95            text_align(cr, self.name_x, self.name_y, text, *self.style.name_align) 
    9596        super(NamedItem, self).draw(context) 
  • gaphor/trunk/gaphor/diagram/package.py

    r1121 r1193  
    33""" 
    44 
    5 from gaphas.util import text_center, text_extents, text_set_font 
     5from gaphas.util import text_align, text_extents, text_set_font 
    66from gaphor import UML 
    77from gaphor.diagram.nameditem import NamedItem 
     
    4949        cr.stroke() 
    5050        if self.stereotype: 
    51             text_center(cr, w / 2, y + 10, self.stereotype) 
     51            text_align(cr, w / 2, y + 10, self.stereotype) 
    5252 
    5353        super(PackageItem, self).draw(context) 
  • gaphor/trunk/gaphor/diagram/style.py

    r1121 r1193  
    77 
    88# horizontal align 
    9 ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT = range(3) 
     9ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT = -1, 0, 1 
    1010 
    1111# vertical align 
    12 ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM = range(3) 
     12ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM = -1, 0, 1 
    1313 
    1414