Ejemplo n.º 1
0
    def paint(self, painter, option, index):
        ''' Override the tree widget draw widget function.
        '''
        rect = option.rect

        tree_widget = self.parent()
        model = tree_widget.model()
        item = index.model().itemFromIndex(index)

        line = item.script_line.clean_line
        line_number = item.line_number
        is_title = item.script_line.has_children()
        is_comment = item.script_line.is_comment()

        color_value = self._color_default_value

        if item.script_line.is_comment():
            font = self._font_comment
            color_default = self._color_comment
            highlight_value = False

        elif item.script_line.is_layer_addition():
            font = self._font_default
            color_default = self._color_layer_addition
            highlight_value = False

        elif (item.script_line.stack_pushed() != None
              or item.script_line.stack_set() != None):
            font = self._font_default
            color_default = self._color_stacked_pushed
            color_value = self._color_stacked_pushed_value
            highlight_value = True

        elif item.script_line.has_children():
            font = self._font_has_children
            color_default = self._color_has_children
            highlight_value = True

        else:
            font = self._font_default
            color_default = self._color_default
            highlight_value = True

        font.setPixelSize(tree_widget.font_size)

        # Get the size of the text according to the chosen font
        fm = QtGui.QFontMetrics(font)

        # Separate the line in a list of tuple (text, color) to draw the text
        if item.script_line.has_children(
        ) and not tree_widget.isExpanded(index):
            to_write = [(line + "...}", color_default)]
        else:
            to_write = [(line, color_default)]

        if highlight_value:

            # Try to highlight the name and the value(s) if possible
            tuple_split = item.script_line.clean_line.split(" ", 1)
            if len(tuple_split) > 1:
                if tuple_split[-1].strip() not in ["{", "{...}"]:
                    to_write = [(tuple_split[0], color_default),
                                (tuple_split[-1], color_value)]

        # Set line number indentation
        font_line_number = self._font_default
        font_line_number.setPixelSize(tree_widget.font_size)
        fm_line_number = QtGui.QFontMetrics(font_line_number)

        self.line_numbers_indent = fm_line_number.width(
            str(model.total_line_number))

        # Draw the line number if the option has been set
        painter.setPen(
            QtGui.QPen(self._color_line_number, 1, QtCore.Qt.SolidLine))
        painter.setFont(font_line_number)
        painter.drawText(5, rect.top() + 15, str(item.line_number))
        interval_left = rect.left() + 15 + self.line_numbers_indent

        # Draw the filter if we need one
        if tree_widget.filter != None:
            self._color_selection.setAlpha(70)
            elements = re.findall(tree_widget.filter, line, re.IGNORECASE)
            tmp_line = line
            interval_rect = interval_left
            for element in elements:
                prefix, tmp_line = tmp_line.split(element, 1)
                interval_rect += fm.width(prefix)
                width = fm.width(element)
                rect_selection = QtCore.QRect(interval_rect, rect.y(), width,
                                              rect.height())
                painter.setBrush(self._color_selection)
                painter.setPen(
                    QtGui.QPen(self._color_selection, 2, QtCore.Qt.SolidLine))
                painter.drawRect(rect_selection)
                interval_rect += width

        # Draw the text
        for tuple_to_write in to_write:
            text, color = tuple_to_write
            pen = QtGui.QPen(color, 1, QtCore.Qt.SolidLine)
            painter.setPen(QtGui.QPen(color, 1, QtCore.Qt.SolidLine))
            painter.setFont(font)
            painter.drawText(interval_left, rect.top() + 15, text)
            interval_left += fm.width(text) + 5
Ejemplo n.º 2
0
 def sizeHint(self, option, index):
     tree_widget = self.parent()
     font = self._font_has_children
     font.setPixelSize(tree_widget.font_size)
     fm = QtGui.QFontMetrics(font)
     return QtCore.QSize(200, fm.height() + 5)
Ejemplo n.º 3
0
    def __init__(self, parent, minimum_width=200, show_thumbnail=True):
        super(TreeDelegateStyle, self).__init__(parent)

        self._view = parent
        self._minimum_width = minimum_width
        self._show_thumbnail = show_thumbnail

        self._thumnbail_default = QtGui.QImage()
        default_thumb = os.environ["FTRACK_SERVER"] + "/img/thumbnail2.png"
        self._thumnbail_default.loadFromData(
            urllib.urlopen(default_thumb).read())

        # Fonts...
        self._font_name = QtGui.QFont()
        self._font_name.setPixelSize(12)
        self._font_name.setWeight(QtGui.QFont.Bold)
        self._fm_name = QtGui.QFontMetrics(self._font_name)

        self._font_desc = QtGui.QFont()
        self._font_desc.setPixelSize(11)
        self._font_desc.setWeight(QtGui.QFont.Normal)
        self._fm_desc = QtGui.QFontMetrics(self._font_desc)

        # Sizes...
        self._thumnbail_size = QtCore.QSize(150, 100)
        self._thumnbail_child_size = QtCore.QSize(96, 64)

        self._type_indicator_width = 12

        # Colors...
        self._background = QtGui.QColor(68, 68, 68)
        self._background_regenerated = QtGui.QColor(20, 20, 20)

        self._background_comment = QtGui.QColor(58, 58, 58)

        self._name_color = QtGui.QColor(195, 207, 164)
        self._desc_color = QtGui.QColor(240, 240, 240)
        self._owner_color = QtGui.QColor(200, 200, 200)
        self._comment_color = QtGui.QColor(240, 240, 240)

        self._btn_color = QtGui.QColor(255, 255, 255, 80)
        self._btn_color_hover = QtGui.QColor(255, 255, 255, 200)
        self._btn_color_pressed = QtGui.QColor(255, 255, 255, 255)

        # Flags...
        self._comment_flags = QtCore.Qt.TextWordWrap | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop

        # Paddings...
        self._padding_item = dict(left=3, top=3, right=3, bottom=0)
        self._padding_content = dict(left=5, top=5, right=5, bottom=10)
        self._padding_comment = 5
        self._inter_text = 5
        self._inter_item = 3
        self._space_before_btn = 8

        # method...
        self._width = self._minimum_width

        # Keep the QRect of the "show previous versions" button if necessary
        self._button_rect = None

        # Keep the QRect of the "date" to show the real date in hover mode
        self._date_rect = None

        # Hover state
        self._hover_state = dict(no_hover=0,
                                 btn_hover=1,
                                 btn_pressed=2,
                                 date_hover=3)

        # Keep in memory the index under the mouse
        self._current_index = None