Fixed text editing of classifiers. Also some text placement has been improved.
git-svn-id: file:///Users/arjan/backup/gaphor/gaphor/trunk@1193 a8418922-720d-0410-834f-a69b97ada669
This commit is contained in:
parent
9aaaa92e84
commit
7af7e000c3
@ -153,22 +153,29 @@ class ClassifierItemEditor(object):
|
||||
return True
|
||||
|
||||
self._edit = None
|
||||
# Edit is in name compartment -> edit name
|
||||
name_comp_height = self._item.get_name_size()[1]
|
||||
if y < name_comp_height:
|
||||
self._edit = self._item
|
||||
return True
|
||||
y -= name_comp_height
|
||||
margin = self._item.style.compartment_margin[0]
|
||||
|
||||
padding = self._item.style.compartment_padding
|
||||
vspacing = self._item.style.compartment_vspacing
|
||||
|
||||
# place offset at top of first comparement
|
||||
y -= name_comp_height
|
||||
y += vspacing / 2.0
|
||||
for comp in self._item.compartments:
|
||||
y -= margin
|
||||
y -= padding[0]
|
||||
for item in comp:
|
||||
y -= vspacing
|
||||
y -= item.height
|
||||
if y < item.height:
|
||||
self._edit = item
|
||||
return True
|
||||
y -= margin
|
||||
y -= item.height
|
||||
y -= vspacing
|
||||
y -= padding[2]
|
||||
# Compensate for last substraction action
|
||||
y += vspacing
|
||||
return False
|
||||
|
||||
def get_text(self):
|
||||
|
@ -96,7 +96,6 @@ class DiagramItemMeta(type):
|
||||
from gaphas import state
|
||||
from gaphor.undomanager import get_undo_manager, transactional
|
||||
|
||||
print 'state', state
|
||||
state.observers.add(state.revert_handler)
|
||||
|
||||
def _undo_handler(event):
|
||||
|
@ -4,7 +4,7 @@ Activity control nodes.
|
||||
|
||||
import math
|
||||
|
||||
from gaphas.util import path_ellipse
|
||||
from gaphas.util import path_ellipse, text_align
|
||||
from gaphas.state import observed, reversible_property
|
||||
|
||||
from gaphor import UML
|
||||
@ -216,8 +216,8 @@ class ForkNodeItem(ForkDecisionNodeItem):
|
||||
cr.move_to(self.name_x, self.name_y)
|
||||
|
||||
if isinstance(self.subject, UML.JoinNode):
|
||||
cr.move_to(self._join_spec_x, self._join_spec_y)
|
||||
cr.show_text(self.subject.joinSpec.value)
|
||||
text_align(cr, self._join_spec_x, self._join_spec_y,
|
||||
self.subject.joinSpec.value, align_x=1, align_y=1)
|
||||
|
||||
cr.stroke()
|
||||
super(ForkNodeItem, self).draw(context)
|
||||
|
@ -15,7 +15,7 @@ Plan:
|
||||
|
||||
from math import atan2, pi
|
||||
|
||||
from gaphas.util import text_extents, text_multiline
|
||||
from gaphas.util import text_extents, text_align, text_multiline
|
||||
from gaphas.state import reversible_property
|
||||
from gaphas import Item
|
||||
from gaphas.geometry import Rectangle
|
||||
@ -367,8 +367,10 @@ class AssociationItem(DiagramLine):
|
||||
cr.restore()
|
||||
|
||||
if self.subject and self.subject.name:
|
||||
cr.move_to(self._label_bounds[0], self._label_bounds[1])
|
||||
cr.show_text(self.subject.name or '')
|
||||
#cr.move_to(self._label_bounds[0], self._label_bounds[1])
|
||||
#cr.show_text(self.subject.name or '')
|
||||
text_align(cr, self._label_bounds[0], self._label_bounds[1],
|
||||
self.subject.name or '', align_x=1, align_y=1)
|
||||
|
||||
|
||||
class AssociationEnd(SubjectSupport):
|
||||
@ -706,12 +708,8 @@ class AssociationEnd(SubjectSupport):
|
||||
return
|
||||
|
||||
cr = context.cairo
|
||||
#cr.move_to(self._name_bounds[0], self._name_bounds[3])
|
||||
#cr.show_text(self._name or '')
|
||||
text_multiline(cr, self._name_bounds[0], self._name_bounds[3], self._name)
|
||||
#cr.move_to(self._mult_bounds[0], self._mult_bounds[3])
|
||||
#cr.show_text(self._mult or '')
|
||||
text_multiline(cr, self._mult_bounds[0], self._mult_bounds[3], self._mult)
|
||||
text_multiline(cr, self._name_bounds[0], self._name_bounds[1], self._name)
|
||||
text_multiline(cr, self._mult_bounds[0], self._mult_bounds[1], self._mult)
|
||||
cr.stroke()
|
||||
|
||||
if context.hovered or context.focused or context.draw_all:
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
import itertools
|
||||
|
||||
from gaphas.util import text_extents, text_center, text_set_font
|
||||
from gaphas.util import text_extents, text_align, text_set_font
|
||||
from gaphas.state import observed, reversible_property
|
||||
from gaphor import UML
|
||||
from gaphor.i18n import _
|
||||
@ -11,7 +11,6 @@ from gaphor.i18n import _
|
||||
from gaphor.diagram.nameditem import NamedItem
|
||||
from gaphor.diagram.feature import FeatureItem
|
||||
|
||||
from gaphas.util import text_center
|
||||
import font
|
||||
|
||||
class Compartment(list):
|
||||
@ -46,7 +45,8 @@ class Compartment(list):
|
||||
return self.width, self.height
|
||||
|
||||
def pre_update(self, context):
|
||||
"""Pre update, determine width and height of the compartment.
|
||||
"""
|
||||
Pre update, determine width and height of the compartment.
|
||||
"""
|
||||
self.width = self.height = 0
|
||||
cr = context.cairo
|
||||
@ -57,7 +57,7 @@ class Compartment(list):
|
||||
self.width = max(map(lambda p: p[0], sizes))
|
||||
self.height = sum(map(lambda p: p[1], sizes))
|
||||
vspacing = self.owner.style.compartment_vspacing
|
||||
self.height += vspacing * len(sizes)
|
||||
self.height += vspacing * (len(sizes) - 1)
|
||||
padding = self.owner.style.compartment_padding
|
||||
self.width += padding[1] + padding[3]
|
||||
self.height += padding[0] + padding[2]
|
||||
@ -76,10 +76,10 @@ class Compartment(list):
|
||||
for item in self:
|
||||
cr.save()
|
||||
try:
|
||||
offset += item.height
|
||||
cr.move_to(0, offset)
|
||||
cr.translate(0, offset)
|
||||
#cr.move_to(0, offset)
|
||||
item.draw(context)
|
||||
offset += vspacing
|
||||
offset += vspacing + item.height
|
||||
finally:
|
||||
cr.restore()
|
||||
|
||||
@ -119,7 +119,7 @@ class ClassifierItem(NamedItem):
|
||||
'icon-size': (20, 20),
|
||||
'from-padding': (7, 2, 7, 2),
|
||||
'compartment-padding': (5, 5, 5, 5), # (top, right, bottom, left)
|
||||
'compartment-vspacing': 2,
|
||||
'compartment-vspacing': 3,
|
||||
# Fix name, stereotype and from drawing!
|
||||
'name-padding': (10, 10, 10, 10),
|
||||
'stereotype-padding': (10, 10, 2, 10),
|
||||
@ -354,7 +354,7 @@ class ClassifierItem(NamedItem):
|
||||
padding = self.style.stereotype_padding
|
||||
y += padding[0]
|
||||
text_set_font(cr, font.FONT)
|
||||
text_center(cr, width / 2, y, self.stereotype)
|
||||
text_align(cr, width / 2, y, self.stereotype)
|
||||
y += padding[2]
|
||||
|
||||
# draw name
|
||||
@ -363,7 +363,7 @@ class ClassifierItem(NamedItem):
|
||||
n_w, n_h = text_extents(cr, self.subject.name)
|
||||
text_set_font(cr, self.subject.isAbstract and \
|
||||
font.FONT_ABSTRACT_NAME or font.FONT_NAME)
|
||||
text_center(cr, width / 2, y + n_h/2, self.subject.name)
|
||||
text_align(cr, width / 2, y + n_h/2, self.subject.name)
|
||||
y += padding[2] + n_h/2
|
||||
|
||||
# draw 'from ... '
|
||||
@ -371,7 +371,7 @@ class ClassifierItem(NamedItem):
|
||||
padding = self.style.from_padding
|
||||
y += padding[0]
|
||||
text_set_font(cr, font.FONT_SMALL)
|
||||
text_center(cr, width / 2, y, self._from)
|
||||
text_align(cr, width / 2, y, self._from)
|
||||
y += padding[2]
|
||||
|
||||
cr.translate(0, y)
|
||||
|
@ -78,7 +78,7 @@ class CommentItem(ElementItem):
|
||||
c.stroke()
|
||||
if self.subject.body:
|
||||
# Do not print empty string, since cairo-win32 can't handle it.
|
||||
text_multiline(c, 5, 5, self.subject.body, padding=2)
|
||||
text_multiline(c, 5, 15, self.subject.body, padding=2)
|
||||
#c.move_to(10, 15)
|
||||
#c.show_text(self.subject.body)
|
||||
|
||||
|
@ -5,7 +5,7 @@ Basic functionality for canvas line based items on a diagram.
|
||||
import itertools
|
||||
|
||||
import gaphas
|
||||
from gaphas.util import text_extents
|
||||
from gaphas.util import text_extents, text_align
|
||||
from gaphas.geometry import Rectangle
|
||||
from diagramitem import DiagramItem
|
||||
from interfaces import IConnect
|
||||
@ -77,8 +77,8 @@ class LineItem(gaphas.Line, DiagramItem):
|
||||
super(LineItem, self).draw(context)
|
||||
cr = context.cairo
|
||||
if self._stereotype:
|
||||
cr.move_to(self._stereotype_bounds[0], self._stereotype_bounds[1])
|
||||
cr.show_text(self._stereotype)
|
||||
text_align(cr, self._stereotype_bounds[0], self._stereotype_bounds[1],
|
||||
self._stereotype, align_x=1, align_y=1)
|
||||
|
||||
|
||||
class DiagramLine(LineItem):
|
||||
|
@ -7,7 +7,7 @@ Methods.
|
||||
from gaphas.item import Item
|
||||
from diagramitem import DiagramItem
|
||||
from gaphor.diagram import DiagramItemMeta
|
||||
from gaphas.util import text_extents, text_set_font
|
||||
from gaphas.util import text_extents, text_set_font, text_align
|
||||
import font
|
||||
|
||||
class FeatureItem(DiagramItem):
|
||||
@ -40,7 +40,8 @@ class FeatureItem(DiagramItem):
|
||||
self._expression.set_text(self.subject.render())
|
||||
|
||||
def get_size(self, update=False):
|
||||
"""Return the size of the feature. If update == True the item is
|
||||
"""
|
||||
Return the size of the feature. If update == True the item is
|
||||
directly updated.
|
||||
"""
|
||||
return self.width, self.height
|
||||
@ -126,7 +127,8 @@ class AttributeItem(FeatureItem):
|
||||
def draw(self, context):
|
||||
cr = context.cairo
|
||||
text_set_font(cr, font.FONT)
|
||||
cr.show_text(self.subject.render() or '')
|
||||
text_align(cr, 0, 0, self.subject.render() or '', align_x=1, align_y=1)
|
||||
#cr.show_text(self.subject.render() or '')
|
||||
|
||||
|
||||
|
||||
@ -177,7 +179,8 @@ class OperationItem(FeatureItem):
|
||||
def draw(self, context):
|
||||
cr = context.cairo
|
||||
text_set_font(cr, font.FONT)
|
||||
cr.show_text(self.subject.render() or '')
|
||||
text_align(cr, 0, 0, self.subject.render() or '', align_x=1, align_y=1)
|
||||
#cr.show_text(self.subject.render() or '')
|
||||
|
||||
|
||||
# vim:sw=4:et
|
||||
|
@ -3,7 +3,7 @@ Base classes related to items, which represent UML classes deriving
|
||||
from NamedElement.
|
||||
"""
|
||||
|
||||
from gaphas.util import text_extents
|
||||
from gaphas.util import text_extents, text_align
|
||||
|
||||
from gaphor.diagram.elementitem import ElementItem
|
||||
from gaphor.diagram.style import get_min_size, get_text_point, \
|
||||
@ -90,6 +90,7 @@ class NamedItem(ElementItem):
|
||||
|
||||
text = self.subject.name
|
||||
if text:
|
||||
cr.move_to(self.name_x, self.name_y)
|
||||
cr.show_text(text)
|
||||
#cr.move_to(self.name_x, self.name_y)
|
||||
#cr.show_text(text)
|
||||
text_align(cr, self.name_x, self.name_y, text, *self.style.name_align)
|
||||
super(NamedItem, self).draw(context)
|
||||
|
@ -2,7 +2,7 @@
|
||||
Package diagram item.
|
||||
"""
|
||||
|
||||
from gaphas.util import text_center, text_extents, text_set_font
|
||||
from gaphas.util import text_align, text_extents, text_set_font
|
||||
from gaphor import UML
|
||||
from gaphor.diagram.nameditem import NamedItem
|
||||
import font
|
||||
@ -48,7 +48,7 @@ class PackageItem(NamedItem):
|
||||
cr.line_to(o, y)
|
||||
cr.stroke()
|
||||
if self.stereotype:
|
||||
text_center(cr, w / 2, y + 10, self.stereotype)
|
||||
text_align(cr, w / 2, y + 10, self.stereotype)
|
||||
|
||||
super(PackageItem, self).draw(context)
|
||||
|
||||
|
@ -6,10 +6,10 @@ Style classes and constants.
|
||||
PADDING_TOP, PADDING_RIGHT, PADDING_BOTTOM, PADDING_LEFT = range(4)
|
||||
|
||||
# horizontal align
|
||||
ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT = range(3)
|
||||
ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT = -1, 0, 1
|
||||
|
||||
# vertical align
|
||||
ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM = range(3)
|
||||
ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM = -1, 0, 1
|
||||
|
||||
|
||||
class Style(object):
|
||||
|
Loading…
x
Reference in New Issue
Block a user