'Updates the legend, repositioning the items according to the legend\'s orientation.'

def update_items(self):

    self.box_rect = QRectF()
    x = y = 0
    for lst in self.items.values():
        for item in lst:
            if hasattr(item, 'text_item'):
                item.text_item.setDefaultTextColor(self.graph.color(OWPalette.Text))
            if hasattr(item, 'rect_item'):
                item.rect_item.setBrush(self.graph.color(OWPalette.Canvas))
            if hasattr(item, 'set_orientation'):
                item.set_orientation(self._orientation)
    if (self._orientation == Qt.Vertical):
        for lst in self.items.values():
            for item in lst:
                if (self.max_size.height() and y and ((y + item.boundingRect().height()) > self.max_size.height())):
                    y = 0
                    x = (x + item.boundingRect().width())
                self.box_rect = (self.box_rect | item.boundingRect().translated(x, y))
                move_item_xy(item, x, y, self.graph.animate_plot)
                y = (y + item.boundingRect().height())
    elif (self._orientation == Qt.Horizontal):
        for lst in self.items.values():
            max_h = max((item.boundingRect().height() for item in lst))
            for item in lst:
                if (self.max_size.width() and x and ((x + item.boundingRect().width()) > self.max_size.width())):
                    x = 0
                    y = (y + max_h)
                self.box_rect = (self.box_rect | item.boundingRect().translated(x, y))
                move_item_xy(item, x, y, self.graph.animate_plot)
                x = (x + item.boundingRect().width())
            if lst:
                x = 0
                y = (y + max_h)
