# Path: omelette/fromage/common.py
# class Drawable(object):
#     """
#     Base for other Drawable objects.
#     Holds uml_object and list of anchors which are in slot relation with it.
#     """
# 
# 
#     def __init__(self, uml_object):
#         self.uml_object = uml_object
#         self.anchors = []
# 
#     """
#     Crops QLineF, used mainly in relation to properly draw line 
#     from one object to another. line_point is 0 when line.p1() is inside
#     of the drawable, everything else when line.p2() inside. 
#     
#     This method shall be overloaded in specific drawables.  
#     """
#     def crop_line(self, line, line_point):
#         return line
#     
#     def get_neighbours(self):
#         return map(self.__get_other, self.anchors)
#     
#     def __get_other(self, anchor):
#         link = anchor.connector
#         if link.source_anchor.slot == self:
#             return link.target_anchor.slot
#         else:
#             return link.source_anchor.slot
# 
#     """
#     Returns boundingRect in relation to the diagram. Doesn't work if
#     Drawable doesn't derive from QGraphicsItem (no boundingRect()).
#     """
#     #TODO: See if PyQt provides such functionality
#     #TODO: Seems like QRectF QGraphicsItem.sceneBoundingRect (self) does that
#     def globalBoundingRect(self):
#         global_rect = QRectF(self.boundingRect())
#         global_rect.translate(self.pos())
# 
#         return global_rect
#     
#     def globalFullBoundingRect(self):
#         full_rect = QRectF(self.childrenBoundingRect() | self.boundingRect())
#         full_rect.translate(self.pos())
#         
#         return full_rect
#     
#     def resize_scene_rect(self):
#         # Check if we are QGraphicsItem and if we are on scene
#         if(not callable(self.scene) or self.scene() == None): 
#             return
#         
#         # TODO: A place for optimization?
#         rect = QRectF(self.scene().sceneRect())
#         self.scene().setSceneRect(rect.united(self.globalBoundingRect()))
# 
#     neighbours = property(get_neighbours)
#     
#     # Why not.
#     @staticmethod
#     def get_font():
#         return QFont('Helvetica', 10)


from PyQt4.QtGui import *
from PyQt4.QtCore import QRectF, QPointF
from PyQt4.Qt import *
from omelette.fromage.common import Drawable


class DrawableText(QGraphicsItem):
    def __init__(self, parentItem):
        QGraphicsItem.__init__(self)
        self.setParentItem(parentItem)
        self.__font = Drawable.get_font()
        self.__text = ""
        self.__origin_pos = None
        self.reset_vector = QPointF(0,0)
        
        self.__extraFrame = 1
        
        self.setZValue(1)
        
        self.setFlag(QGraphicsItem.ItemIsMovable, 1)
        self.setFlag(QGraphicsItem.ItemIsSelectable, 1)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, 1)

    def boundingRect(self):
        metrics = QFontMetrics(self.__font)
        return (QRectF(0, 0, metrics.width(self.__text), metrics.height())
                .adjusted(0, 0, 2 * self.__extraFrame, 2 * self.__extraFrame)
                .united(QRectF(QPointF(0,0), self.__get_local_origin())))
    

# Path: omelette/fromage/common.py
# class Drawable(object):
#     """
#     Base for other Drawable objects.
#     Holds uml_object and list of anchors which are in slot relation with it.
#     """
# 
# 
#     def __init__(self, uml_object):
#         self.uml_object = uml_object
#         self.anchors = []
# 
#     """
#     Crops QLineF, used mainly in relation to properly draw line 
#     from one object to another. line_point is 0 when line.p1() is inside
#     of the drawable, everything else when line.p2() inside. 
#     
#     This method shall be overloaded in specific drawables.  
#     """
#     def crop_line(self, line, line_point):
#         return line
#     
#     def get_neighbours(self):
#         return map(self.__get_other, self.anchors)
#     
#     def __get_other(self, anchor):
#         link = anchor.connector
#         if link.source_anchor.slot == self:
#             return link.target_anchor.slot
#         else:
#             return link.source_anchor.slot
# 
#     """
#     Returns boundingRect in relation to the diagram. Doesn't work if
#     Drawable doesn't derive from QGraphicsItem (no boundingRect()).
#     """
#     #TODO: See if PyQt provides such functionality
#     #TODO: Seems like QRectF QGraphicsItem.sceneBoundingRect (self) does that
#     def globalBoundingRect(self):
#         global_rect = QRectF(self.boundingRect())
#         global_rect.translate(self.pos())
# 
#         return global_rect
#     
#     def globalFullBoundingRect(self):
#         full_rect = QRectF(self.childrenBoundingRect() | self.boundingRect())
#         full_rect.translate(self.pos())
#         
#         return full_rect
#     
#     def resize_scene_rect(self):
#         # Check if we are QGraphicsItem and if we are on scene
#         if(not callable(self.scene) or self.scene() == None): 
#             return
#         
#         # TODO: A place for optimization?
#         rect = QRectF(self.scene().sceneRect())
#         self.scene().setSceneRect(rect.united(self.globalBoundingRect()))
# 
#     neighbours = property(get_neighbours)
#     
#     # Why not.
#     @staticmethod
#     def get_font():
#         return QFont('Helvetica', 10)


# Path: omelette/fromage/diagramcommon.py
from PyQt4.QtGui import *
from PyQt4.QtCore import QRectF, QPointF
from PyQt4.Qt import *
from omelette.fromage.common import Drawable



class DrawableText(QGraphicsItem):
    def __init__(self, parentItem):
        QGraphicsItem.__init__(self)
        self.setParentItem(parentItem)
        self.__font = Drawable.get_font()
        self.__text = ""
        self.__origin_pos = None
        self.reset_vector = QPointF(0,0)
        
        self.__extraFrame = 1
        
        self.setZValue(1)
        
        self.setFlag(QGraphicsItem.ItemIsMovable, 1)
        self.setFlag(QGraphicsItem.ItemIsSelectable, 1)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, 1)

    def boundingRect(self):
        metrics = QFontMetrics(self.__font)
        return (QRectF(0, 0, metrics.width(self.__text), metrics.height())
                .adjusted(0, 0, 2 * self.__extraFrame, 2 * self.__extraFrame)
                .united(QRectF(QPointF(0,0), self.__get_local_origin())))
    

    def paint(self, painter, style, widget):