Changeset 1093
- Timestamp:
- 12/04/06 23:08:52 (2 years ago)
- Files:
-
- gaphor/branches/new-canvas/gaphor/adapters/connectors.py (modified) (2 diffs)
- gaphor/branches/new-canvas/gaphor/adapters/editors.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/classifier.py (modified) (3 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/diagramline.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/feature.py (modified) (3 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/nameditem.py (modified) (2 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/package.py (modified) (3 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/tool.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/branches/new-canvas/gaphor/adapters/connectors.py
r1091 r1093 106 106 ax, ay = glued.handles()[NW].pos 107 107 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] 117 110 118 111 def glue(self, handle, x, y): … … 122 115 """ 123 116 h = self.element.handles() 124 bounds = (h[NW].pos + h[SE].pos)117 bounds = map(float, (h[NW].pos + h[SE].pos)) 125 118 return geometry.point_on_rectangle(bounds, (x, y), border=True) 126 119 gaphor/branches/new-canvas/gaphor/adapters/editors.py
r1063 r1093 80 80 """ 81 81 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: 83 84 self._edit = self._item 84 85 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 86 89 for comp in self._item.compartments: 87 y -= comp.MARGIN_Y90 y -= margin 88 91 for item in comp: 92 y -= vspacing 93 y -= item.height 89 94 if y < item.height: 90 95 self._edit = item 91 96 return True 92 y -= item.height 93 y -= comp.MARGIN_Y 97 y -= margin 94 98 return False 95 99 gaphor/branches/new-canvas/gaphor/diagram/classifier.py
r1091 r1093 76 76 cr.save() 77 77 try: 78 offset += item.height + vspacing78 offset += item.height 79 79 cr.move_to(0, offset) 80 80 item.draw(context) 81 offset += vspacing 81 82 finally: 82 83 cr.restore() … … 269 270 270 271 sizes = [comp.get_size() for comp in self._compartments] 271 272 self.update_name_size(context) 273 sizes.append(self.get_name_size()) 272 274 self.min_width = max(s_w, n_w, f_w) 273 275 self.min_height = 0 274 275 super(ClassifierItem, self).pre_update(context)276 276 277 277 if sizes: … … 281 281 self.min_width = max(self.min_width, w) 282 282 self.min_height += h 283 284 super(ClassifierItem, self).pre_update(context) 283 285 284 286 gaphor/branches/new-canvas/gaphor/diagram/diagramline.py
r1091 r1093 119 119 self.orthogonal = self._load_orthogonal 120 120 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 121 128 if hasattr(self, '_load_head_connection'): 122 129 adapter = component.queryMultiAdapter((self._load_head_connection, self), IConnect) gaphor/branches/new-canvas/gaphor/diagram/feature.py
r1023 r1093 9 9 from gaphor.undomanager import undoable 10 10 from gaphor.diagram import DiagramItemMeta 11 11 from gaphas.util import text_extents 12 12 13 13 class FeatureItem(DiagramItem): … … 50 50 def update_size(self, text, context): 51 51 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) 53 53 54 54 def on_subject_notify(self, pspec, notifiers=()): … … 57 57 self.text = self.subject and self.subject.render() or '' 58 58 59 # CanvasItem callbacks:60 61 59 def point(self, x, y): 62 60 """ 63 61 """ 64 62 return distance_rectangle_point((0, 0, self.width, self.height), (x, y)) 65 66 # Editable67 68 def on_editable_get_editable_shape(self, x,y):69 return self._expression70 71 def on_editable_start_editing(self, shape):72 #self.preserve_property('expression')73 pass74 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_text79 self.request_update()80 63 81 64 gaphor/branches/new-canvas/gaphor/diagram/nameditem.py
r1071 r1093 37 37 self.name_x = 0 38 38 self.name_y = 0 39 self._name_size = (0, 0) 39 40 40 41 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): 42 49 """ 43 50 Calculate minimal size of named item. … … 47 54 if text and not self.style.name_outside: 48 55 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) 55 63 56 64 gaphor/branches/new-canvas/gaphor/diagram/package.py
r1059 r1093 16 16 __style__ = { 17 17 'name-padding': (25, 10, 5, 10), 18 'tab-x': 50, 19 'tab-y': 20, 18 20 } 19 20 TAB_X = 5021 TAB_Y = 2022 21 23 22 def pre_update(self, context): … … 25 24 w, h = text_extents(cr, self.subject.name) 26 25 self.min_width = w + 60 27 self.min_height = h + 30 + self. TAB_Y26 self.min_height = h + 30 + self.style.tab_y 28 27 if self.stereotype: 29 28 s_w, s_h = text_extents(cr, self.stereotype) … … 39 38 h = self.height 40 39 w = self.width 41 x = PackageItem.TAB_X42 y = PackageItem.TAB_Y40 x = self.style.tab_x 41 y = self.style.tab_y 43 42 cr.move_to(x, y) 44 43 cr.line_to(x, o) gaphor/branches/new-canvas/gaphor/diagram/tool.py
r1068 r1093 41 41 """ 42 42 canvas = view.canvas 43 i2w = view.canvas.get_matrix_i2w 44 w2i = view.canvas.get_matrix_w2i 43 45 min_dist, dummy = view.transform_distance_c2w(10, 0) 44 46 glue_pos_w = (0, 0) … … 49 51 adapter = component.queryMultiAdapter((i, item), IConnect) 50 52 if adapter: 51 x, y = view.canvas.get_matrix_w2i(i).transform_point(wx, wy)53 x, y = w2i(i).transform_point(wx, wy) 52 54 pos = adapter.glue(handle, x, y) 53 55 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) 56 57 if d <= min_dist: 57 58 min_dist = d 58 glue_pos_w = (x, y)59 glue_pos_w = i2w(i).transform_point(*pos) 59 60 glue_item = i 61 60 62 dist, _ = view.transform_distance_c2w(10, 0) 61 63 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) 63 65 handle.x = x 64 66 handle.y = y 67 65 68 # Return the glued item, this can be used by connect() to 66 69 # determine which item it should connect to
