Beispiel #1
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(3)
     painter.setPen(pen)
     painter.setBrush(Qt.NoBrush)
     painter.drawPath(item.path())
     
     if self.showPoints():
         palette = QApplication.palette()
         pen = QPen(palette.color(palette.Base))
         pen.setWidth(2)
         
         painter.setBrush(dataset.color())
         painter.setPen(pen)
         
         for point in item.buildData('ellipses', []):
             painter.drawEllipse(point,
                                 self.pointRadius(),
                                 self.pointRadius())
     
     painter.restore()
Beispiel #2
0
 def __init__(self, pixmap):
     super(XImageItem, self).__init__()
     
     # define the mirror instance
     self._basePixmap = pixmap
     
     # set the pixmap
     palette = QApplication.palette()
     color = palette.color(palette.Highlight)
     effect = XGraphicsDropShadowEffect()
     effect.setOffset(0)
     effect.setBlurRadius(6)
     effect.setColor(color)
     
     self.setGraphicsEffect(effect)
     self.graphicsEffect().setEnabled(False)
     self.setFlags(self.ItemIsSelectable)
Beispiel #3
0
    def __init__(self, pixmap):
        super(XImageItem, self).__init__()

        # define the mirror instance
        self._basePixmap = pixmap

        # set the pixmap
        palette = QApplication.palette()
        color = palette.color(palette.Highlight)
        effect = XGraphicsDropShadowEffect()
        effect.setOffset(0)
        effect.setBlurRadius(6)
        effect.setColor(color)

        self.setGraphicsEffect(effect)
        self.graphicsEffect().setEnabled(False)
        self.setFlags(self.ItemIsSelectable)
Beispiel #4
0
 def __init__(self):
     # define custom properties
     palette = QApplication.palette()
     
     self._name = 'Default'
     self._axisColor = palette.color(palette.Mid).darker(125)
     self._alternateColor = palette.color(palette.Base).darker(104)
     self._baseColor = palette.color(palette.Base)
     self._borderColor = palette.color(palette.Mid)
     self._showGrid = True
     self._showRows = True
     self._showColumns = True
     self._showXAxis = True
     self._showYAxis = True
     self._verticalLabelPadding = 4
     self._horizontalLabelPadding = 4
     self._alternatingRowColors = True
     self._alternatingColumnColors = False
     self._buildData = {}
Beispiel #5
0
    def __init__(self):
        # define custom properties
        palette = QApplication.palette()

        self._name = 'Default'
        self._axisColor = palette.color(palette.Mid).darker(125)
        self._alternateColor = palette.color(palette.Base).darker(104)
        self._baseColor = palette.color(palette.Base)
        self._borderColor = palette.color(palette.Mid)
        self._showGrid = True
        self._showRows = True
        self._showColumns = True
        self._showXAxis = True
        self._showYAxis = True
        self._verticalLabelPadding = 4
        self._horizontalLabelPadding = 4
        self._alternatingRowColors = True
        self._alternatingColumnColors = False
        self._buildData = {}
Beispiel #6
0
    def __init__(self, chartWidget):
        super(XChartScene, self).__init__(chartWidget)

        # create custom properties
        self._chartWidget = chartWidget
        self._minimumWidth = -1
        self._minimumHeight = -1
        self._maximumWidth = -1
        self._maximumHeight = -1
        self._horizontalPadding = 6
        self._verticalPadding = 6
        self._showGrid = True
        self._showRows = True
        self._showColumns = True
        self._trackingEnabled = True
        self._chartType = XChartScene.Type.Line
        self._trackerItem = None

        # used with pie charts
        self._pieAxis = Qt.YAxis
        self._pieAlignment = Qt.AlignCenter

        self._horizontalRuler = XChartRuler(XChartRuler.Type.Number)
        self._verticalRuler = XChartRuler(XChartRuler.Type.Number)
        self._font = QApplication.font()

        self._alternatingColumnColors = False
        self._alternatingRowColors = True

        self._dirty = False
        self._buildData = {}

        palette = QApplication.palette()

        self._axisColor = palette.color(palette.Mid).darker(125)
        self._baseColor = palette.color(palette.Base)
        self._alternateColor = palette.color(palette.Base).darker(104)
        self._borderColor = palette.color(palette.Mid)

        # create custom properties
        chartWidget.installEventFilter(self)
        self.chartTypeChanged.connect(self.update)
Beispiel #7
0
 def __init__( self, chartWidget ):
     super(XChartScene, self).__init__(chartWidget)
     
     # create custom properties
     self._chartWidget       = chartWidget
     self._minimumWidth      = -1
     self._minimumHeight     = -1
     self._maximumWidth      = -1
     self._maximumHeight     = -1
     self._horizontalPadding = 6
     self._verticalPadding   = 6
     self._showGrid          = True
     self._showRows          = True
     self._showColumns       = True
     self._trackingEnabled   = True
     self._chartType         = XChartScene.Type.Line
     self._trackerItem       = None
     
     # used with pie charts
     self._pieAxis           = Qt.YAxis
     self._pieAlignment      = Qt.AlignCenter
     
     self._horizontalRuler   = XChartRuler(XChartRuler.Type.Number)
     self._verticalRuler     = XChartRuler(XChartRuler.Type.Number)
     self._font              = QApplication.font()
     
     self._alternatingColumnColors = False
     self._alternatingRowColors    = True
     
     self._dirty             = False
     self._buildData         = {}
     
     palette                 = QApplication.palette()
     
     self._axisColor         = palette.color(palette.Mid).darker(125)
     self._baseColor         = palette.color(palette.Base)
     self._alternateColor    = palette.color(palette.Base).darker(104)
     self._borderColor       = palette.color(palette.Mid)
     
     # create custom properties
     chartWidget.installEventFilter(self)
     self.chartTypeChanged.connect(self.update)
 def __init__( self, query, joiner = '' ):
     super(XQueryItem, self).__init__()
     
     # set the joiner
     self._joiner = joiner
     
     # update the hint
     self.setText(0, joiner)
     self.setSizeHint(1, QSize(80, 20))
     
     if ( Q.typecheck(query) ):
         op_name = Q.Op[query.operatorType()]
         op_name = projex.text.joinWords(op_name, ' ').lower()
         
         palette = QApplication.palette()
         for i in range(4):
             self.setBackground(i, palette.color(palette.Base))
         
         self.setTextAlignment(0, Qt.AlignRight | Qt.AlignVCenter)
         self.setText(1, query.columnName())
         self.setText(2, op_name)
         self.setText(3, query.valueString())
         
         flags = self.flags()
         flags |= Qt.ItemIsEditable
         self.setFlags(flags)
     
     else:
         sub_joiner = QueryCompound.Op[query.operatorType()].lower()
         for i, sub_query in enumerate(query.queries()):
             if ( i ):
                 item = XQueryItem(sub_query, sub_joiner)
             else:
                 item = XQueryItem(sub_query)
                 
             self.addChild(item)
Beispiel #9
0
    def __init__(self, query, joiner=''):
        super(XQueryItem, self).__init__()

        # set the joiner
        self._joiner = joiner

        # update the hint
        self.setText(0, joiner)
        self.setSizeHint(1, QSize(80, 20))

        if (Q.typecheck(query)):
            op_name = Q.Op[query.operatorType()]
            op_name = projex.text.joinWords(op_name, ' ').lower()

            palette = QApplication.palette()
            for i in range(4):
                self.setBackground(i, palette.color(palette.Base))

            self.setTextAlignment(0, Qt.AlignRight | Qt.AlignVCenter)
            self.setText(1, query.columnName())
            self.setText(2, op_name)
            self.setText(3, query.valueString())

            flags = self.flags()
            flags |= Qt.ItemIsEditable
            self.setFlags(flags)

        else:
            sub_joiner = QueryCompound.Op[query.operatorType()].lower()
            for i, sub_query in enumerate(query.queries()):
                if (i):
                    item = XQueryItem(sub_query, sub_joiner)
                else:
                    item = XQueryItem(sub_query)

                self.addChild(item)
    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)
 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)