Пример #1
0
 def paintEvent(self, event):
     """
     Handles the drawing for this widget and its selection region.
     
     :param      event | <QPaintEvent>
     """
     pen = QPen(Qt.DashLine)
     pen.setColor(QColor('red'))
     with XPainter(self) as painter:
         painter.setPen(pen)
         clr = QColor('black')
         clr.setAlpha(100)
         painter.setBrush(clr)
         
         painter.drawRect(self._region)
Пример #2
0
 def setColor( self, color ):
     """
     Convenience method to set the border, fill and highlight colors based
     on the inputed color.
     
     :param      color | <QColor>
     """
     # sets the border color as the full value
     self.setBorderColor(color)
     
     # set the highlight color as the color with a 140 % alpha
     clr = QColor(color)
     clr.setAlpha(150)
     self.setHighlightColor(clr)
     
     # set the fill color as the color with a 50 % alpha
     clr = QColor(color)
     clr.setAlpha(80)
     self.setFillColor(clr)
Пример #3
0
    def setColor(self, color):
        """
        Convenience method to set the border, fill and highlight colors based
        on the inputed color.
        
        :param      color | <QColor>
        """
        # sets the border color as the full value
        self.setBorderColor(color)

        # set the highlight color as the color with a 140 % alpha
        clr = QColor(color)
        clr.setAlpha(150)
        self.setHighlightColor(clr)

        # set the fill color as the color with a 50 % alpha
        clr = QColor(color)
        clr.setAlpha(80)
        self.setFillColor(clr)
Пример #4
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()
Пример #5
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()
Пример #6
0
    def setRecordState(self, recordState):
        """
        Sets the record state for this item to the inputed state.
        
        :param      recordState | <XOrbRecordItem.State>
        """
        self._recordState = recordState

        try:
            is_colored = self.treeWidget().isColored()
        except AttributeError:
            return

        if not is_colored:
            return

        # determine the color for the item based on the state
        if recordState & XOrbRecordItem.State.Removed:
            clr = self.treeWidget().colorSet().color("RecordRemoved")
        elif recordState & XOrbRecordItem.State.New:
            clr = self.treeWidget().colorSet().color("RecordNew")
        elif recordState & XOrbRecordItem.State.Modified:
            clr = self.treeWidget().colorSet().color("RecordModified")
        else:
            clr = None

        # set the color based on the record state
        if clr is not None:
            clr = QColor(clr)
            clr.setAlpha(40)
            brush = QBrush(clr)
        else:
            brush = QBrush()

        for c in range(self.treeWidget().columnCount()):
            self.setBackground(c, brush)
Пример #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 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)