Changeset 1093

Show
Ignore:
Timestamp:
12/04/06 23:08:52 (2 years ago)
Author:
arjanmol
Message:
  • made classifier resize work
  • fix loading (handle connections)
  • moved some constants into the style
  • made handle connection work better. Handles now automatically connect
    if you move the end handle in the element.
  • fixed few layout issues
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/branches/new-canvas/gaphor/adapters/connectors.py

    r1091 r1093  
    106106        ax, ay = glued.handles()[NW].pos 
    107107        bx, by = glued.handles()[SE].pos 
    108         if abs(hx - ax) < 0.01: 
    109             side = 3 
    110         elif abs(hy - ay) < 0.01: 
    111             side = 0 
    112         elif abs(hx - bx) < 0.01: 
    113             side = 1 
    114         else: 
    115             side = 2 
    116         return side 
     108        return min((abs(hy - ay), 0), (abs(hx - bx), 1), 
     109                   (abs(hy - by), 2),  (abs(hx - ax), 3))[1] 
    117110 
    118111    def glue(self, handle, x, y): 
     
    122115        """ 
    123116        h = self.element.handles() 
    124         bounds = (h[NW].pos + h[SE].pos
     117        bounds = map(float, (h[NW].pos + h[SE].pos)
    125118        return geometry.point_on_rectangle(bounds, (x, y), border=True) 
    126119 
  • gaphor/branches/new-canvas/gaphor/adapters/editors.py

    r1063 r1093  
    8080        """ 
    8181        self._edit = None 
    82         if y < items.ClassifierItem.NAME_COMPARTMENT_HEIGHT: 
     82        name_comp_height = self._item.get_name_size()[1] 
     83        if y < name_comp_height: 
    8384            self._edit = self._item 
    8485            return True 
    85         y -= items.ClassifierItem.NAME_COMPARTMENT_HEIGHT 
     86        y -= name_comp_height 
     87        margin = self._item.style.compartment_margin[0] 
     88        vspacing = self._item.style.compartment_vspacing 
    8689        for comp in self._item.compartments: 
    87             y -= comp.MARGIN_Y 
     90            y -= margin 
    8891            for item in comp: 
     92                y -= vspacing 
     93                y -= item.height 
    8994                if y < item.height: 
    9095                    self._edit = item 
    9196                    return True 
    92                 y -= item.height 
    93             y -= comp.MARGIN_Y 
     97            y -= margin 
    9498        return False 
    9599 
  • gaphor/branches/new-canvas/gaphor/diagram/classifier.py

    r1091 r1093  
    7676            cr.save() 
    7777            try: 
    78                 offset += item.height + vspacing 
     78                offset += item.height 
    7979                cr.move_to(0, offset) 
    8080                item.draw(context) 
     81                offset += vspacing 
    8182            finally: 
    8283                cr.restore() 
     
    269270 
    270271        sizes = [comp.get_size() for comp in self._compartments] 
    271  
     272        self.update_name_size(context) 
     273        sizes.append(self.get_name_size()) 
    272274        self.min_width = max(s_w, n_w, f_w) 
    273275        self.min_height = 0 
    274  
    275         super(ClassifierItem, self).pre_update(context) 
    276276 
    277277        if sizes: 
     
    281281            self.min_width = max(self.min_width, w) 
    282282            self.min_height += h 
     283 
     284        super(ClassifierItem, self).pre_update(context) 
    283285 
    284286 
  • gaphor/branches/new-canvas/gaphor/diagram/diagramline.py

    r1091 r1093  
    119119            self.orthogonal = self._load_orthogonal 
    120120            del self._load_orthogonal 
     121 
     122        # First update matrix and solve constraints (NE and SW handle are 
     123        # lazy and are resolved by the constraint solver rather than set 
     124        # directly. 
     125        self.canvas.update_matrix(self) 
     126        self.canvas.solver.solve() 
     127 
    121128        if hasattr(self, '_load_head_connection'): 
    122129            adapter = component.queryMultiAdapter((self._load_head_connection, self), IConnect) 
  • gaphor/branches/new-canvas/gaphor/diagram/feature.py

    r1023 r1093  
    99from gaphor.undomanager import undoable 
    1010from gaphor.diagram import DiagramItemMeta 
    11  
     11from gaphas.util import text_extents 
    1212 
    1313class FeatureItem(DiagramItem): 
     
    5050    def update_size(self, text, context): 
    5151        cr = context.cairo 
    52         x_bear, y_bear, self.width, self.height, x_adv, y_adv = cr.text_extents(text) 
     52        self.width, self.height = text_extents(cr, text) 
    5353 
    5454    def on_subject_notify(self, pspec, notifiers=()): 
     
    5757        self.text = self.subject and self.subject.render() or '' 
    5858 
    59     # CanvasItem callbacks: 
    60  
    6159    def point(self, x, y): 
    6260        """ 
    6361        """ 
    6462        return distance_rectangle_point((0, 0, self.width, self.height), (x, y)) 
    65  
    66     # Editable 
    67  
    68     def on_editable_get_editable_shape(self, x,y): 
    69         return self._expression 
    70  
    71     def on_editable_start_editing(self, shape): 
    72         #self.preserve_property('expression') 
    73         pass 
    74  
    75     def on_editable_editing_done(self, shape, new_text): 
    76         self.set_property('expression', new_text) 
    77         #if new_text != self.subject.name: 
    78         #    self.subject.name = new_text 
    79         self.request_update() 
    8063 
    8164 
  • gaphor/branches/new-canvas/gaphor/diagram/nameditem.py

    r1071 r1093  
    3737        self.name_x = 0 
    3838        self.name_y = 0 
     39        self._name_size = (0, 0) 
    3940 
    4041 
    41     def pre_update(self, context): 
     42    def get_name_size(self): 
     43        """ 
     44        Return width, height of the text (including padding) 
     45        """ 
     46        return self._name_size 
     47 
     48    def update_name_size(self, context): 
    4249        """ 
    4350        Calculate minimal size of named item. 
     
    4754        if text and not self.style.name_outside: 
    4855            width, height = text_extents(cr, text) 
    49  
    50             self.min_width, self.min_height = get_min_size(width, height, 
    51                     self.style.min_size, 
    52                     self.style.name_padding) 
    53  
    54         super(NamedItem, self).pre_update(context) 
     56            padding = self.style.name_padding 
     57            self._name_size = width + padding[0] + padding[2], height + padding[1] + padding[3] 
     58#            self.min_width, self.min_height = get_min_size(width, height, 
     59#                    self.style.min_size, 
     60#                    self.style.name_padding) 
     61
     62#        super(NamedItem, self).pre_update(context) 
    5563 
    5664 
  • gaphor/branches/new-canvas/gaphor/diagram/package.py

    r1059 r1093  
    1616    __style__ = { 
    1717        'name-padding': (25, 10, 5, 10), 
     18        'tab-x': 50, 
     19        'tab-y': 20, 
    1820    } 
    19  
    20     TAB_X = 50 
    21     TAB_Y = 20 
    2221 
    2322    def pre_update(self, context): 
     
    2524        w, h = text_extents(cr, self.subject.name) 
    2625        self.min_width = w + 60 
    27         self.min_height = h + 30 + self.TAB_Y 
     26        self.min_height = h + 30 + self.style.tab_y 
    2827        if self.stereotype: 
    2928            s_w, s_h = text_extents(cr, self.stereotype) 
     
    3938        h = self.height 
    4039        w = self.width 
    41         x = PackageItem.TAB_X 
    42         y = PackageItem.TAB_Y 
     40        x = self.style.tab_x 
     41        y = self.style.tab_y 
    4342        cr.move_to(x, y) 
    4443        cr.line_to(x, o) 
  • gaphor/branches/new-canvas/gaphor/diagram/tool.py

    r1068 r1093  
    4141        """ 
    4242        canvas = view.canvas 
     43        i2w = view.canvas.get_matrix_i2w 
     44        w2i = view.canvas.get_matrix_w2i 
    4345        min_dist, dummy = view.transform_distance_c2w(10, 0) 
    4446        glue_pos_w = (0, 0) 
     
    4951            adapter = component.queryMultiAdapter((i, item), IConnect) 
    5052            if adapter: 
    51                 x, y = view.canvas.get_matrix_w2i(i).transform_point(wx, wy) 
     53                x, y = w2i(i).transform_point(wx, wy) 
    5254                pos = adapter.glue(handle, x, y) 
    5355                if pos: 
    54                     x, y = view.canvas.get_matrix_i2w(i).transform_point(*pos) 
    55                     d = distance_point_point((wx, wy), (x, y))  
     56                    d = i.point(x, y) 
    5657                    if d <= min_dist: 
    5758                        min_dist = d 
    58                         glue_pos_w = (x, y
     59                        glue_pos_w = i2w(i).transform_point(*pos
    5960                        glue_item = i 
     61 
    6062        dist, _ = view.transform_distance_c2w(10, 0) 
    6163        if min_dist < dist: 
    62             x, y = view.canvas.get_matrix_w2i(item).transform_point(*glue_pos_w) 
     64            x, y = w2i(item).transform_point(*glue_pos_w) 
    6365            handle.x = x 
    6466            handle.y = y 
     67 
    6568        # Return the glued item, this can be used by connect() to 
    6669        # determine which item it should connect to