Пример #1
0
    def paintMilestone(self, painter):
        """
        Paints this item as the milestone look.
        
        :param      painter | <QPainter>
        """
        # generate the rect
        rect = self.rect()

        padding = self.padding()
        gantt = self.scene().ganttWidget()
        cell_w = gantt.cellWidth()
        cell_h = gantt.cellHeight()

        x = rect.width() - cell_w
        y = self.padding()
        w = cell_w
        h = rect.height() - padding - 2

        # grab the color options
        color = self.color()
        alt_color = self.alternateColor()

        if (self.isSelected()):
            color = self.highlightColor()
            alt_color = self.alternateHighlightColor()

        # create the background brush
        gradient = QLinearGradient()
        gradient.setStart(0, 0)
        gradient.setFinalStop(0, h)

        gradient.setColorAt(0, color)
        gradient.setColorAt(0.8, alt_color)
        gradient.setColorAt(1, color)

        painter.setPen(self.borderColor())
        painter.setBrush(QBrush(gradient))

        pen = painter.pen()
        pen.setWidthF(0.5)
        painter.setPen(pen)
        painter.setRenderHint(painter.Antialiasing)

        path = QPainterPath()
        path.moveTo(x - cell_w / 3.0, y + h / 2.0)
        path.lineTo(x, y)
        path.lineTo(x + cell_w / 3.0, y + h / 2.0)
        path.lineTo(x, y + h)
        path.lineTo(x - cell_w / 3.0, y + h / 2.0)

        painter.drawPath(path)
Пример #2
0
    def paint(self, painter, option, widget):
        widget = self.scene()._slider
        pixmap = self.pixmap()

        palette = widget.palette()
        base = palette.color(palette.Base)

        # draw the reflection
        painter.save()
        painter.setPen(Qt.NoPen)

        transform = painter.transform()
        transform.translate(pixmap.width() / 2.0, 0)
        transform.rotate(self.angle(), Qt.YAxis)
        transform.translate(-pixmap.width() / 2.0, 0)
        painter.setTransform(transform)

        self.graphicsEffect().setEnabled(self.isSelected())

        painter.drawPixmap(0, 0, pixmap)

        painter.setBrush(Qt.NoBrush)
        painter.setOpacity(0.2)
        painter.scale(1, -1)
        painter.translate(0, -(pixmap.height()) * 2)
        painter.drawPixmap(0, 0, pixmap)

        painter.setOpacity(1)

        grad = QLinearGradient()
        grad.setStart(0, 0)
        grad.setFinalStop(0, pixmap.height())
        grad.setColorAt(1.0, QColor(0, 0, 0, 0))
        grad.setColorAt(0.2, base)
        grad.setColorAt(0.0, base)

        painter.setBrush(grad)
        painter.drawRect(0, 0, pixmap.width(), pixmap.height())

        painter.restore()
Пример #3
0
    def drawItem(self, item, painter, option):
        """
        Draws the inputed item as a bar graph.
        
        :param      item    | <XChartDatasetItem>
                    painter | <QPainter>
                    option  | <QStyleOptionGraphicsItem>
        """
        dataset = item.dataset()

        painter.save()
        painter.setRenderHint(painter.Antialiasing)

        pen = QPen(dataset.color())
        pen.setWidth(0.75)
        painter.setPen(pen)

        for path in item.buildData('subpaths', []):
            gradient = QLinearGradient()

            clr = QColor(dataset.color())
            clr.setAlpha(220)

            gradient.setColorAt(0.0, clr.lighter(180))
            gradient.setColorAt(0.1, clr.lighter(160))
            gradient.setColorAt(0.25, clr.lighter(140))
            gradient.setColorAt(1.0, clr.lighter(125))

            if self.orientation() == Qt.Vertical:
                gradient.setStart(0, path.boundingRect().bottom())
                gradient.setFinalStop(0, path.boundingRect().top())
            else:
                gradient.setStart(path.boundingRect().left(), 0)
                gradient.setFinalStop(path.boundingRect().right(), 0)

            painter.setBrush(gradient)
            painter.drawPath(path)

        painter.restore()
Пример #4
0
    def drawForeground(self, painter, rect):
        palette = self._slider.palette()
        color = palette.color(palette.Base)

        trans = self._slider.viewportTransform()
        rect = trans.mapRect(self._slider.rect())
        width = rect.width()
        rect.setX(abs(rect.x()))
        rect.setWidth(width)

        clear = QColor(0, 0, 0, 0)

        grad = QLinearGradient()
        grad.setStart(rect.left(), 0)
        grad.setFinalStop(rect.right(), 0)
        grad.setColorAt(0.0, color)
        grad.setColorAt(0.3, clear)
        grad.setColorAt(0.7, clear)
        grad.setColorAt(1.0, color)

        painter.setBrush(grad)
        painter.setPen(Qt.NoPen)

        painter.drawRect(rect)
Пример #5
0
 def paintEvent(self, event):
     """
     Paints the background for the dock toolbar.
     
     :param      event | <QPaintEvent>
     """
     x = 1
     y = 1
     w = self.width()
     h = self.height()
     
     clr_a = QColor(220, 220, 220)
     clr_b = QColor(190, 190, 190)
     
     grad = QLinearGradient()
     grad.setColorAt(0.0, clr_a)
     grad.setColorAt(0.6, clr_a)
     grad.setColorAt(1.0, clr_b)
     
     # adjust the coloring for the horizontal toolbar
     if self.position() & (self.Position.North | self.Position.South):
         h = self.minimumPixmapSize().height() + 6
         
         if self.position() == self.Position.South:
             y = self.height() - h
             grad.setStart(0, y)
             grad.setFinalStop(0, self.height())
         else:
             grad.setStart(0, 0)
             grad.setFinalStart(0, h)
     
     # adjust the coloring for the vertical toolbar
     if self.position() & (self.Position.East | self.Position.West):
         w = self.minimumPixmapSize().width() + 6
         
         if self.position() == self.Position.West:
             x = self.width() - w
             grad.setStart(x, 0)
             grad.setFinalStop(self.width(), 0)
         else:
             grad.setStart(0, 0)
             grad.setFinalStop(w, 0)
     
     with XPainter(self) as painter:
         painter.fillRect(x, y, w, h, grad)
         
         # show the active action
         action = self.selectedAction()
         if action is not None and \
            not self.currentAction() and \
            not self._animating:
             for lbl in self.actionLabels():
                 if lbl.action() != action:
                     continue
                 
                 geom = lbl.geometry()
                 size = lbl.pixmapSize()
                 
                 if self.position() == self.Position.North:
                     x = geom.left()
                     y = 0
                     w = geom.width()
                     h = size.height() + geom.top() + 2
                 
                 elif self.position() == self.Position.East:
                     x = 0
                     y = geom.top()
                     w = size.width() + geom.left() + 2
                     h = geom.height()
                 
                 painter.setPen(QColor(140, 140, 40))
                 painter.setBrush(QColor(160, 160, 160))
                 painter.drawRect(x, y, w, h)
                 break
Пример #6
0
    def rebuildTiles(self):
        # create the foreground pixmap
        gantt  = self.ganttWidget()
        header = gantt.treeWidget().header()
        width  = self.sceneRect().width()
        height = header.height()
        
        # create the main color
        palette     = gantt.palette()
        color       = palette.color(palette.Button)
        textColor   = palette.color(palette.ButtonText)
        borderColor = color.darker(140)
        text_align  = Qt.AlignBottom | Qt.AlignHCenter
        
        # create the gradient
        gradient = QLinearGradient()
        gradient.setStart(0, 0)
        gradient.setFinalStop(0, height)
        gradient.setColorAt(0, color)
        gradient.setColorAt(1, color.darker(120))
        
        # generate the tiles
        tiles = []
        painters = []
        for rect, label in self._topLabels:
            tile_rect = QRectF(rect.x(), 0, rect.width(), height)
            pixmap = QPixmap(rect.width(), height)
            
            with XPainter(pixmap) as painter:
                painter.setBrush(QBrush(gradient))
                painter.drawRect(tile_rect)
                
                rx = 0
                ry = 0
                rw = rect.width()
                rh = rect.height()
                
                painter.setPen(borderColor)
                painter.drawRect(rx, ry, rw, rh)
                
                painter.setPen(textColor)
                painter.drawText(rx, ry, rw, rh - 2, text_align, label)
                
                tiles.append((tile_rect, pixmap))
                painters.append((tile_rect, pixmap, painter))
        
        # add bottom labels
        for rect, label in self._labels:
            for tile_rect, tile, painter in painters:
                if tile_rect.x() <= rect.x() and \
                   rect.right() <= tile_rect.right():
                    rx = rect.x() - tile_rect.x()
                    ry = rect.y()
                    rw = rect.width()
                    rh = rect.height()
                    
                    with painter:
                        painter.setPen(borderColor)
                        painter.drawRect(rx, ry, rw, rh)
                        
                        painter.setPen(textColor)
                        painter.drawText(rx, ry, rw, rh - 2, text_align, label)

        self._tiles = tiles
Пример #7
0
    def paint(self, painter, option, widget):
        """
        Draws this item with the inputed painter.
        
        :param      painter | <QPainter>
                    rect    | <QRect>
        """
        if self._dirty:
            self.rebuild()

        scene = self.scene()
        if not scene:
            return

        grid = scene.gridRect()
        typ = self.chartType()

        # draw the line chart
        if typ == XChartScene.Type.Line:
            painter.setRenderHint(painter.Antialiasing)

            # draw the path area
            area = self._buildData.get('path_area')
            if area and self.isShaded():
                clr = QColor(self.color())

                clr.setAlpha(120)
                painter.setPen(Qt.NoPen)
                painter.setBrush(clr)

                painter.drawPath(area)

            # draw the line data
            pen = QPen(self.color())
            pen.setWidth(2)

            painter.setPen(pen)
            painter.setBrush(Qt.NoBrush)

            painter.drawPath(self.path())

            if (self.showPointsInLine()):
                palette = QApplication.palette()
                pen = QPen(palette.color(palette.Base))
                pen.setWidth(2)

                painter.setBrush(self.color())
                painter.setPen(pen)

                for point in self._ellipses:
                    painter.drawEllipse(point, self.pointRadius(),
                                        self.pointRadius())

        # draw a bar chart
        elif typ == XChartScene.Type.Bar:
            painter.setRenderHint(painter.Antialiasing)

            pen = QPen(self.color())
            pen.setWidth(1)
            painter.setPen(pen)

            for key, value, sub_path in self._subpaths:
                gradient = QLinearGradient()

                clr = QColor(self.color())

                if (sub_path != self._hoveredPath):
                    clr.setAlpha(130)

                gradient.setColorAt(0.0, clr.lighter(140))
                gradient.setColorAt(0.1, clr.lighter(120))
                gradient.setColorAt(0.25, clr.lighter(110))
                gradient.setColorAt(1.0, clr.lighter(105))

                if (self.orientation() == Qt.Horizontal):
                    gradient.setStart(0, sub_path.boundingRect().top())
                    gradient.setFinalStop(0, sub_path.boundingRect().bottom())
                else:
                    gradient.setStart(sub_path.boundingRect().left(), 0)
                    gradient.setFinalStop(sub_path.boundingRect().right(), 0)

                painter.setBrush(gradient)
                painter.drawPath(sub_path)

        # draw a simple pie chart (calculated by scene)
        elif typ == XChartScene.Type.Pie:
            painter.setRenderHint(painter.Antialiasing)

            center = self.pieCenter()
            radius = self.radius()

            for key, value, sub_path in self._subpaths:
                clr = self.keyColor(key)

                gradient = QRadialGradient(QPointF(0, 0), radius)

                a = QColor(clr.lighter(140))
                b = QColor(clr.lighter(110))

                a.setAlpha(40)
                b.setAlpha(80)

                # look for mouse over
                if (sub_path == self._hoveredPath):
                    a.setAlpha(100)
                    b.setAlpha(200)

                gradient.setColorAt(0, a)
                gradient.setColorAt(1, b)

                pen = QPen(clr)
                pen.setWidth(1)

                painter.setBrush(gradient)
                painter.setPen(pen)

                painter.drawPath(sub_path)
Пример #8
0
    def paintNormal(self, painter):
        """
        Paints this item as the normal look.
        
        :param      painter | <QPainter>
        """
        # generate the rect
        rect = self.rect()

        x = 0
        y = self.padding()
        w = rect.width()
        h = rect.height() - (2 * self.padding()) - 1
        radius = self.borderRadius()

        # grab the color options
        color = self.color()
        alt_color = self.alternateColor()

        if (self.isSelected()):
            color = self.highlightColor()
            alt_color = self.alternateHighlightColor()

        # create the background brush
        gradient = QLinearGradient()
        gradient.setStart(0, 0)
        gradient.setFinalStop(0, h)

        gradient.setColorAt(0, color)
        gradient.setColorAt(0.8, alt_color)
        gradient.setColorAt(1, color)
        painter.setPen(self.borderColor())

        if (radius):
            painter.setRenderHint(painter.Antialiasing)
            pen = painter.pen()
            pen.setWidthF(0.5)
            painter.setPen(pen)

        painter.setBrush(QBrush(gradient))
        painter.drawRoundedRect(x, y, w, h, radius, radius)

        # create the progress brush
        if (self.showProgress()):
            gradient = QLinearGradient()
            gradient.setStart(0, 0)
            gradient.setFinalStop(0, h)
            gradient.setColorAt(0, self.progressColor())
            gradient.setColorAt(0.8, self.alternateProgressColor())
            gradient.setColorAt(1, self.progressColor())

            prog_w = (w - 4) * (self._percentComplete / 100.0)
            radius -= 2

            painter.setPen(Qt.NoPen)
            painter.setBrush(QBrush(gradient))
            painter.drawRoundedRect(x + 2, y + 2, prog_w, h - 4, radius,
                                    radius)

        # draw the text on this item
        if (self.text()):
            painter.setPen(self.textColor())
            painter.drawText(x, y, w, h, Qt.AlignCenter, self.text())
Пример #9
0
    def paintGroup(self, painter):
        """
        Paints this item as the group look.
        
        :param      painter | <QPainter>
        """
        # generate the rect
        rect = self.rect()

        padding = self.padding()
        gantt = self.scene().ganttWidget()
        cell_w = gantt.cellWidth()
        cell_h = gantt.cellHeight()

        x = 0
        y = self.padding()
        w = rect.width()
        h = rect.height() - (padding + 1)

        # grab the color options
        color = self.color()
        alt_color = self.alternateColor()

        if (self.isSelected()):
            color = self.highlightColor()
            alt_color = self.alternateHighlightColor()

        # create the background brush
        gradient = QLinearGradient()
        gradient.setStart(0, 0)
        gradient.setFinalStop(0, h)

        gradient.setColorAt(0, color)
        gradient.setColorAt(0.8, alt_color)
        gradient.setColorAt(1, color)

        painter.setPen(self.borderColor())
        painter.setBrush(QBrush(gradient))

        pen = painter.pen()
        pen.setWidthF(0.5)
        painter.setPen(pen)
        painter.setRenderHint(painter.Antialiasing)

        path = QPainterPath()
        path.moveTo(x - cell_w / 4.0, y)
        path.lineTo(w + cell_w / 4.0, y)
        path.lineTo(w + cell_w / 4.0, y + h / 2.0)
        path.lineTo(w, h)
        path.lineTo(w - cell_w / 4.0, y + h / 2.0)
        path.lineTo(x + cell_w / 4.0, y + h / 2.0)
        path.lineTo(x, h)
        path.lineTo(x - cell_w / 4.0, y + h / 2.0)
        path.lineTo(x - cell_w / 4.0, y)

        painter.drawPath(path)

        # create the progress brush
        if (self.showProgress()):
            gradient = QLinearGradient()
            gradient.setStart(0, 0)
            gradient.setFinalStop(0, h)
            gradient.setColorAt(0, self.progressColor())
            gradient.setColorAt(0.8, self.alternateProgressColor())
            gradient.setColorAt(1, self.progressColor())

            prog_w = (w - 4) * (self._percentComplete / 100.0)

            painter.setPen(Qt.NoPen)
            painter.setBrush(QBrush(gradient))
            painter.drawRect(x, y, prog_w, y + h / 2.0)

        # draw the text on this item
        if (self.text()):
            painter.setPen(self.textColor())
            painter.drawText(x, y, w, h, Qt.AlignCenter, self.text())