#
# Support routines for XMI-DI elements regarding graphics
#
import di_support as DISUPP
import qt

def getFgColor(xelement):
    """Returns foregound color for XMI-DI @xelement as a QColor."""
    return qt.QColor(DISUPP.getFgColorValue(xelement))

def getBgColor(xelement):
    """Returns background color for XMI-DI @xelement as a QColor."""
    return qt.QColor(DISUPP.getBgColorValue(xelement))

def getFontColor(xelement):
    """Returns font color for XMI-DI @xelement as a QColor."""
    return qt.QColor(DISUPP.getFontColorValue(xelement))


def setPenStyle(painter, style):
    """Bloody QT resets all pen properties (style, color, thickness)
    so we have to make a copy, then modify, then set instead of
    just modifying the painter directly."""
    oldpen = painter.pen()
    p = qt.QPen(oldpen)
    p.setStyle(style)
    painter.setPen(p)


def setPenColor(painter, color):
    """Bloody QT resets all pen properties (style, color, thickness)
    so we have to make a copy, then modify, then set instead of
    just modifying the painter directly."""
    p = qt.QPen(painter.pen())
    p.setColor(color)
    painter.setPen(p)

def setPenThickness(painter, width):
    """Bloody QT resets all pen properties (style, color, thickness)
    so we have to make a copy, then modify, then set instead of
    just modifying the painter directly."""
    w = width
    if w < 1:
        w = 1
    p = qt.QPen(painter.pen())
    p.setWidth(w)
    painter.setPen(p)

