Exemplo n.º 1
0
 def updateColor(self):
     """
     Update the color on the sampleModel
     modify to fit to the actual view
     
     """
     if not self.view.sampleTableView.selectedIndexes():#not self.acTree.selectedIndexes():
         return
     
     idx = self.view.sampleTableView.selectedIndexes()[0]
     sample = self.model.sample(idx.data().toString(), fullNameEntry=False)
     
     if sample is None:
         self.view.showErrorMessage('Error', 'Please choose only one file...')            
         return
     
     color = QColorDialog.getColor()
     if not color.isValid():
         return
         
     sample.color=color.getRgbF()[:-1]
     
     #make the gradient color here to
     color =QColor.fromRgbF(*(sample.color+(1.,)))
     colorr=QColor.fromRgbF(*(sample.color+(.5,)))
     gradient=QLinearGradient(-100, -100, 100, 100)
     gradient.setColorAt(0.7, colorr)
     gradient.setColorAt(1, color)
     
     #for m in (self.view.sampleModel, self.view.spectraModel, self.view.peakModel, 
     #          self.view.clusterModel):#self.view.chromaModel,
     for i in xrange(self.view.sampleModel.rowCount()):
         item=self.view.sampleModel.item(i,0)
         if item.text()== sample.shortName():
             item.setBackground(QBrush(gradient))
Exemplo n.º 2
0
    def drawLineSection(self, painter, firstP, secondP, firstCorner,
                        secondCorner):
        direction = self.getPointToPointDirection(firstP, secondP)

        thickness = self.CONNECTION_THICKNESS * self.zoomFactor()
        halfthick = thickness / 2
        cornerRoundness = halfthick**0.5
        cornerOffset = halfthick * cornerRoundness * (4 * self.zoomFactor()**2)
        innerCorner = halfthick * (cornerRoundness + 1)
        outerCorner = halfthick * (cornerRoundness - 1)

        rect = self.getRectBetweenTwoPoints(firstP, secondP, firstCorner,
                                            secondCorner)
        # Paint witch color gradient (PyQt4)
        if direction == self.ConnectionDirection.LEFT:  # horizontal, negative
            brush = QLinearGradient(rect.x(), rect.y(), rect.x(),
                                    rect.y() + halfthick)
        elif direction == self.ConnectionDirection.RIGHT:  # horizontal, positive
            brush = QLinearGradient(rect.x(), rect.y(), rect.x(),
                                    rect.y() + halfthick)
        elif direction == self.ConnectionDirection.UP:  # vertical, negative
            brush = QLinearGradient(rect.x(), rect.y(),
                                    rect.x() + halfthick, rect.y())
        elif direction == self.ConnectionDirection.DOWN:  # vertical, positive
            brush = QLinearGradient(rect.x(), rect.y(),
                                    rect.x() + halfthick, rect.y())

        brush.setSpread(QLinearGradient.ReflectSpread)
        brush.setColorAt(0, self.FILL_COLOR1)
        brush.setColorAt(1, self.FILL_COLOR2)
        painter.setBrush(brush)

        painter.drawRect(rect)
Exemplo n.º 3
0
class ReflectivityFrame(QFrame):
    SIZE_X = 400
    SIZE_Y = 100

    def __init__(self, parent=None):
        QFrame.__init__(self, parent)
        self.reflectivity = 0
        self.setMinimumSize(self.SIZE_X, self.SIZE_Y)
        self.setMaximumSize(self.SIZE_X, self.SIZE_Y)

        self.gradient = QLinearGradient(0.0, 0.0, 0.0, self.SIZE_Y)
        self.gradient.setColorAt(0, Qt.white)
        self.gradient.setColorAt(1, Qt.black)

    def set_reflectivity(self, r):
        self.reflectivity = self.SIZE_Y - r*self.SIZE_Y/4095.0
        self.repaint()

    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        qp.setBrush(self.gradient)
        qp.setPen(Qt.transparent)
        qp.drawRect(0, 0, self.SIZE_X, self.SIZE_Y)
        qp.setBrush(QBrush(Qt.red))
        qp.setPen(Qt.red)
        qp.drawLine(0, self.reflectivity, self.SIZE_X, self.reflectivity)
        qp.end()
Exemplo n.º 4
0
def gradient_darker(grad, factor):
    """Return a copy of the QGradient darkened by factor.

    .. note:: Only QLinearGradeint and QRadialGradient are supported.

    """
    if type(grad) is QGradient:
        if grad.type() == QGradient.LinearGradient:
            grad = sip.cast(grad, QLinearGradient)
        elif grad.type() == QGradient.RadialGradient:
            grad = sip.cast(grad, QRadialGradient)

    if isinstance(grad, QLinearGradient):
        new_grad = QLinearGradient(grad.start(), grad.finalStop())
    elif isinstance(grad, QRadialGradient):
        new_grad = QRadialGradient(grad.center(), grad.radius(),
                                   grad.focalPoint())
    else:
        raise TypeError

    new_grad.setCoordinateMode(grad.coordinateMode())

    for pos, color in grad.stops():
        new_grad.setColorAt(pos, color.darker(factor))

    return new_grad
Exemplo n.º 5
0
 def drawLineSection(self, painter, firstP, secondP, firstCorner, secondCorner):
     direction = self.getPointToPointDirection(firstP, secondP)
     
     thickness = self.CONNECTION_THICKNESS * self.zoomFactor()
     halfthick = thickness / 2
     cornerRoundness = halfthick ** 0.5
     cornerOffset = halfthick * cornerRoundness * (4 * self.zoomFactor()**2)
     innerCorner = halfthick * (cornerRoundness + 1)
     outerCorner = halfthick * (cornerRoundness - 1)
     
     rect = self.getRectBetweenTwoPoints(firstP, secondP, firstCorner, secondCorner)
         # Paint witch color gradient (PyQt4)
     if direction == self.ConnectionDirection.LEFT:     # horizontal, negative
         brush = QLinearGradient(rect.x(), rect.y(), rect.x(), rect.y() + halfthick)
     elif direction == self.ConnectionDirection.RIGHT:  # horizontal, positive
         brush = QLinearGradient(rect.x(), rect.y(), rect.x(), rect.y() + halfthick)
     elif direction == self.ConnectionDirection.UP:     # vertical, negative
         brush = QLinearGradient(rect.x(), rect.y(), rect.x() + halfthick, rect.y())
     elif direction == self.ConnectionDirection.DOWN:   # vertical, positive
         brush = QLinearGradient(rect.x(), rect.y(), rect.x() + halfthick, rect.y())
     
     brush.setSpread(QLinearGradient.ReflectSpread)
     brush.setColorAt(0, self.FILL_COLOR1)
     brush.setColorAt(1, self.FILL_COLOR2)
     painter.setBrush(brush)
     
     painter.drawRect(rect)
Exemplo n.º 6
0
    def drawSpan(self, painter, rect):
        opt = QStyleOptionSlider()
        QSlider.initStyleOption(self, opt)

        # area
        groove = self.style().subControlRect(QStyle.CC_Slider, opt,
                                             QStyle.SC_SliderGroove, self)
        if opt.orientation == QtCore.Qt.Horizontal:
            groove.adjust(0, 0, -1, 0)
        else:
            groove.adjust(0, 0, 0, -1)

        # pen & brush
        painter.setPen(QPen(self.gradientLeftColor, 0))
        if opt.orientation == QtCore.Qt.Horizontal:
            self.setupPainter(painter, opt.orientation,
                              groove.center().x(), groove.top(),
                              groove.center().x(), groove.bottom())
        else:
            self.setupPainter(painter, opt.orientation, groove.left(),
                              groove.center().y(), groove.right(),
                              groove.center().y())

        # draw groove
        intersected = QtCore.QRectF(rect.intersected(groove))
        gradient = QLinearGradient(intersected.topLeft(),
                                   intersected.topRight())
        gradient.setColorAt(0, self.gradientLeft)
        gradient.setColorAt(1, self.gradientRight)
        painter.fillRect(intersected, gradient)
Exemplo n.º 7
0
 def createLinearGradient(self, itemRect, startColor, endColor):
     start = QPointF(itemRect.left(), itemRect.top())
     stop = QPointF(itemRect.right(), itemRect.bottom())
     linearGradient = QLinearGradient(start, stop)
     linearGradient.setColorAt(0, startColor)
     linearGradient.setColorAt(1, endColor)
     return linearGradient
Exemplo n.º 8
0
    def paintEvent(self, e):
        """
        Paint the horizontal handle as a gradient, paint
        the vertical handle as a line.
        """
        painter = QPainter(self)

        topColor = QColor(145, 145, 145)
        bottomColor = QColor(142, 142, 142)
        gradientStart = QColor(252, 252, 252)
        gradientStop = QColor(223, 223, 223)

        if self.orientation() == Qt.Vertical:
            painter.setPen(topColor)
            painter.drawLine(0, 0, self.width(), 0)
            painter.setPen(bottomColor)
            painter.drawLine(0, self.height() - 1, self.width(), self.height() - 1)

            linearGrad = QLinearGradient(QPointF(0, 0), QPointF(0, height() - 3))
            linearGrad.setColorAt(0, gradientStart)
            linearGrad.setColorAt(1, gradientStop)
            painter.fillRect(QRect(QPoint(0, 1), self.size() - QSize(0, 2)), QBrush(linearGrad))
        else:
            painter.setPen(topColor)
            painter.drawLine(0, 0, 0, self.height())
Exemplo n.º 9
0
def gradient_darker(grad, factor):
    """Return a copy of the QGradient darkened by factor.

    .. note:: Only QLinearGradeint and QRadialGradient are supported.

    """
    if type(grad) is QGradient:
        if grad.type() == QGradient.LinearGradient:
            grad = sip.cast(grad, QLinearGradient)
        elif grad.type() == QGradient.RadialGradient:
            grad = sip.cast(grad, QRadialGradient)

    if isinstance(grad, QLinearGradient):
        new_grad = QLinearGradient(grad.start(), grad.finalStop())
    elif isinstance(grad, QRadialGradient):
        new_grad = QRadialGradient(grad.center(), grad.radius(),
                                   grad.focalPoint())
    else:
        raise TypeError

    new_grad.setCoordinateMode(grad.coordinateMode())

    for pos, color in grad.stops():
        new_grad.setColorAt(pos, color.darker(factor))

    return new_grad
Exemplo n.º 10
0
    def initialize(self, points, show_fresnel, frequency):
        self.pts = {
            PT1: points[0],
            PT2: points[-1]
        }
        self.fresnel_visible = show_fresnel
        self.frequency = frequency

        # Construct static geometry to be included in the scene
        path = self.path_for(points)

        height = path.boundingRect().height()
        gradient = QLinearGradient(QPointF(0., height), QPointF(0., 0.))
        gradient.setColorAt(0, QColor(0x00b300))
        gradient.setColorAt(1, QColor(0x331a00))

        # Create the scene
        self.scene = QGraphicsScene(self.dialog)

        # Add geometries to the scene, keeping a reference to each
        self.path = self.scene.addPath(path, QPen(Qt.blue, 1), QBrush(gradient))

        # Update the scene; i.e. correct pen-colours etc.
        self.update_scene(add_geometries=True)

        # Set up the view with the constructed scene
        self.view.setScene(self.scene)
        self.view.ensureVisible(self.scene.sceneRect())
        self.view.scale(1., -1.)
Exemplo n.º 11
0
class ReflectivityFrame(QFrame):
    SIZE_X = 400
    SIZE_Y = 100

    def __init__(self, parent=None):
        QFrame.__init__(self, parent)
        self.reflectivity = 0
        self.setMinimumSize(self.SIZE_X, self.SIZE_Y)
        self.setMaximumSize(self.SIZE_X, self.SIZE_Y)

        self.gradient = QLinearGradient(0.0, 0.0, 0.0, self.SIZE_Y)
        self.gradient.setColorAt(0, Qt.white)
        self.gradient.setColorAt(1, Qt.black)

    def set_reflectivity(self, r):
        self.reflectivity = self.SIZE_Y - r*self.SIZE_Y/4095.0
        self.repaint()

    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        qp.setBrush(self.gradient)
        qp.setPen(Qt.transparent)
        qp.drawRect(0, 0, self.SIZE_X, self.SIZE_Y)
        qp.setBrush(QBrush(Qt.red))
        qp.setPen(Qt.red)
        qp.drawLine(0, self.reflectivity, self.SIZE_X, self.reflectivity)
        qp.end()
Exemplo n.º 12
0
    def drawIcon(self, colorRamp):
        # input color ramp object: QgsVectorColorRampV2 object.
        # QgsVectorColorRampV2 is a virtual object, the real object name in
        # this case is QgsVectorGradientColorRampV2 object.
        mStops = colorRamp.stops()
        linearGradient = QLinearGradient(0.0, 50.0, 200.0, 50.0)
        for item in mStops:
            linearGradient.setColorAt(item.offset, item.color)
        linearGradient.setSpread(QGradient.PadSpread)

        svgName = os.path.join(os.path.dirname(__file__), self.text() + '.svg')
        pix = QSvgGenerator()
        pix.setFileName(svgName)
        pix.setSize(QSize(200, 100))
        painter = QPainter()
        painter.begin(pix)
        br = QBrush(linearGradient)
        painter.setBrush(br)
        painter.drawRect(QRect(0, 0, 200, 100))
        painter.end()

        pixmap = QPixmap(svgName)
        icon = QIcon(pixmap)
        self.svgName = svgName

        return icon
Exemplo n.º 13
0
    def drawSpan(self, painter, rect):
        opt = QStyleOptionSlider()
        QSlider.initStyleOption(self, opt)

        # area
        groove = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderGroove, self)
        if opt.orientation == QtCore.Qt.Horizontal:
            groove.adjust(0, 0, -1, 0)
        else:
            groove.adjust(0, 0, 0, -1)

        # pen & brush
        painter.setPen(QPen(self.gradientLeftColor, 0))
        if opt.orientation == QtCore.Qt.Horizontal:
            self.setupPainter(painter, opt.orientation, groove.center().x(),
                              groove.top(), groove.center().x(),
                              groove.bottom())
        else:
            self.setupPainter(painter, opt.orientation, groove.left(),
                              groove.center().y(), groove.right(),
                              groove.center().y())

        # draw groove
        intersected = QtCore.QRectF(rect.intersected(groove))
        gradient = QLinearGradient(intersected.topLeft(), intersected.topRight())
        gradient.setColorAt(0, self.gradientLeft)
        gradient.setColorAt(1, self.gradientRight)
        painter.fillRect(intersected, gradient)
Exemplo n.º 14
0
    def paintEvent(self, event):
        """This function create gradient background"""

        painter = QPainter(self)
        gradient = QLinearGradient(QPointF(100, 0), QPointF(100, 100))
        gradient.setColorAt(1, QColor(COLOR_SCHEME['server_widget_bg1']))
        gradient.setColorAt(0, QColor(COLOR_SCHEME['server_widget_bg2']))
        painter.fillRect(self.rect(), gradient)
Exemplo n.º 15
0
    def paintEvent(self,event):
        titleHeight = 40
        bottomHeight = 50
        
        #画标题背景
        painter = QPainter(self)
        painter.save()
        linearGradient = QLinearGradient(0, 0,0,titleHeight)
        linearGradient.setColorAt(0, QColor(60,150,255))
        linearGradient.setColorAt(0.1, QColor(6,88,200)) 
        linearGradient.setColorAt(1, QColor(80,150,255))
        painter.setBrush(QBrush(linearGradient))
        contenRect = QRect(0, 0, self.width(), titleHeight)
        painter.fillRect(contenRect, QBrush(linearGradient))
        painter.restore()
        
        #画标题内容
        painter.save()
        painter.setPen(QPen(QColor(255, 255, 255),1))
        font = painter.font()
        font.setPointSize(12)
        painter.setFont(font)
        painter.drawText(QPoint(10,25), self.title)
        painter.restore()
        
        #画中间白色背景
        painter.save()
        painter.setPen(QPen(QColor(255, 255, 255),1))
        brush = QBrush(QColor(242,242,242))
        painter.setBrush(brush)
        contenRect = QRect(0, titleHeight, self.width()-1, self.height() - titleHeight - bottomHeight)
#         painter.fillRect(contenRect, brush)
        painter.drawRect(contenRect)
        painter.restore()
        
        #画提示信息内容
        painter.save()
        painter.setPen(QPen(QColor(1, 1, 1),1))
        font = painter.font()
        font.setPointSize(15)
        painter.setFont(font)
        fm = QFontMetrics(font)
        infoWidth = fm.width(self.hintInfo)
        painter.drawText(QPoint((self.width() - infoWidth - 10)/2, 150), self.hintInfo)
        painter.restore()
        
        #画底层背景
        painter.save()
        brush = QBrush(QColor(219,234,255))
        painter.setBrush(brush)
        contenRect = QRect(0, self.height() - bottomHeight, self.width(), bottomHeight)
        painter.fillRect(contenRect, brush)
        painter.restore()
        
        
        
        
        
Exemplo n.º 16
0
 def __gradient(self):
     left = QPointF(self.contentsRect().topLeft())
     right = QPointF(self.contentsRect().topRight())
     gradient = QLinearGradient(left, right)
     gradient.setColorAt(0.9, self.palette().color(QPalette.WindowText))
     gradient.setColorAt(1.0, self.palette().color(QPalette.Window))
     pen = QPen()
     pen.setBrush(QBrush(gradient))
     return pen
Exemplo n.º 17
0
 def __gradient(self):
     left = QPointF(self.contentsRect().topLeft())
     right = QPointF(self.contentsRect().topRight())
     gradient = QLinearGradient(left, right)
     gradient.setColorAt(0.9, self.palette().color(QPalette.WindowText))
     gradient.setColorAt(1.0, self.palette().color(QPalette.Window))
     pen = QPen()
     pen.setBrush(QBrush(gradient))
     return pen
Exemplo n.º 18
0
 def paintEvent(self, _):
     p = QPainter(self)
     points = [QPoint(self.width(), -1), QPoint(self.width(), self.height()),
               QPoint(0, self.height() / 2), QPoint(0, self.height() / 2 - 1)]
     grad = QLinearGradient(0, 0, 0, self.height())
     grad.setColorAt(0, self.color1)
     grad.setColorAt(1, self.color2)
     p.setBrush(grad)
     p.setPen(QPen(Qt.NoPen))
     p.drawPolygon(QPolygon(points))
Exemplo n.º 19
0
 def paintEvent(self, event):
     painter = QPainter(self)
     font_metrics = QFontMetrics(self.font())
     if font_metrics.width(self.text()) > self.contentsRect().width():
         label_width = self.size().width()
         gradient = QLinearGradient(0, 0, label_width, 0)
         gradient.setColorAt(1-50.0/label_width, self.palette().color(self.foregroundRole()))
         gradient.setColorAt(1.0, Qt.transparent)
         painter.setPen(QPen(QBrush(gradient), 1.0))
     painter.drawText(self.contentsRect(), Qt.TextSingleLine | int(self.alignment()), self.text())
Exemplo n.º 20
0
 def createLinearGradient(self, itemRect, startColor, endColor):
     '''
     Creates linear gradient starting from top left to bottom right
     '''
     start = QPointF(itemRect.left(), itemRect.top())
     stop = QPointF(itemRect.right(), itemRect.bottom())
     linearGradient = QLinearGradient(start, stop)
     linearGradient.setColorAt(0, startColor)
     linearGradient.setColorAt(1, endColor)
     return linearGradient
Exemplo n.º 21
0
 def get_coloured_root_item(filepath, color, colorr):
     root = QStandardItem(filepath)
     gradient = QLinearGradient(-100, -100, 100, 100)
     gradient.setColorAt(0.7, colorr)
     gradient.setColorAt(1, color)
     root.setBackground(QBrush(gradient))
     root.setEditable(False)
     root.setCheckState(Qt.Checked)
     root.setCheckable(True)
     return root
Exemplo n.º 22
0
 def drawForeground( self, painter, rect ):
     """
     Draws the foreground for this scene.
     
     :param      painter | <QPainter>
                 rect    | <QRect>
     """
     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
     y           = rect.top()
     
     # create the gradient
     gradient = QLinearGradient()
     gradient.setStart(0, y)
     gradient.setFinalStop(0, y + height)
     gradient.setColorAt(0, color)
     gradient.setColorAt(1, color.darker(120))
     
     painter.setBrush(QBrush(gradient))
     painter.drawRect(0, y, width, height)
     
     # add top labels
     for rect, label in self._topLabels:
         rx = rect.x()
         ry = rect.y() + y
         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)
     
     # add bottom labels
     for rect, label in self._labels:
         rx = rect.x()
         ry = rect.y() + y
         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)
Exemplo n.º 23
0
    def drawForeground(self, painter, rect):
        """
        Draws the foreground for this scene.
        
        :param      painter | <QPainter>
                    rect    | <QRect>
        """
        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
        y = rect.top()

        # create the gradient
        gradient = QLinearGradient()
        gradient.setStart(0, y)
        gradient.setFinalStop(0, y + height)
        gradient.setColorAt(0, color)
        gradient.setColorAt(1, color.darker(120))

        painter.setBrush(QBrush(gradient))
        painter.drawRect(0, y, width, height)

        # add top labels
        for rect, label in self._topLabels:
            rx = rect.x()
            ry = rect.y() + y
            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)

        # add bottom labels
        for rect, label in self._labels:
            rx = rect.x()
            ry = rect.y() + y
            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)
Exemplo n.º 24
0
 def statusBarGradient(cls, statusBarRect):
     """
     :type statusBarRect: QRect
     :return: QLinearGradient
     """
     grad = QLinearGradient(statusBarRect.topLeft(), QPoint(statusBarRect.center().x(), statusBarRect.bottom()))
     startColor = cls.shadowColor().darker(164)
     endColor = cls.baseColor().darker(130)
     grad.setColorAt(0, startColor)
     grad.setColorAt(1, endColor)
     return grad
Exemplo n.º 25
0
    def setupPainter(self, painter, orientation, x1, y1, x2, y2):
        highlight = self.palette().color(QPalette.Highlight)
        gradient = QLinearGradient(x1, y1, x2, y2)
        gradient.setColorAt(0, highlight.dark(120))
        gradient.setColorAt(1, highlight.light(108))
        painter.setBrush(gradient)

        if orientation == QtCore.Qt.Horizontal:
            painter.setPen(QPen(highlight.dark(130), 0))
        else:
            painter.setPen(QPen(highlight.dark(150), 0))
Exemplo n.º 26
0
    def setupPainter(self, painter, orientation, x1, y1, x2, y2):
        highlight = self.palette().color(QPalette.Highlight)
        gradient = QLinearGradient(x1, y1, x2, y2)
        gradient.setColorAt(0, highlight.dark(120))
        gradient.setColorAt(1, highlight.light(108))
        painter.setBrush(gradient)

        if orientation == QtCore.Qt.Horizontal:
            painter.setPen(QPen(highlight.dark(130), 0))
        else:
            painter.setPen(QPen(highlight.dark(150), 0))
Exemplo n.º 27
0
    def paintEvent(self, event):
        qp = QPainter(self)

        g = QLinearGradient(0.0, 0.0, 0.0, self.height())
        g.setColorAt(0, Qt.white)
        g.setColorAt(1, Qt.black)

        y = self.height() - self.reflectivity * self.height() / 4095.0

        qp.fillRect(0, 0, self.width(), self.height(), g)
        qp.setPen(Qt.red)
        qp.drawLine(0, y, self.width(), y)
Exemplo n.º 28
0
    def paintEvent(self, event):
        qp = QPainter(self)

        g = QLinearGradient(0.0, 0.0, 0.0, self.height())
        g.setColorAt(0, Qt.white)
        g.setColorAt(1, Qt.black)

        y = self.height() - self.reflectivity * self.height() / 4095.0

        qp.fillRect(0, 0, self.width(), self.height(), g)
        qp.setPen(Qt.red)
        qp.drawLine(0, y, self.width(), y)
Exemplo n.º 29
0
 def getColouredRootItem(sample):
     """stable, may be subdivised in sub routines """
     root = QStandardItem(sample.shortName())
     #root.setIcon(QIcon(QPixmap(os.path.normpath('gui/icons/formula.png'))))
     color =QColor.fromRgbF(sample.color[0],sample.color[1], sample.color[2],1.)
     colorr=QColor.fromRgbF(sample.color[0],sample.color[1], sample.color[2],.5)
     gradient=QLinearGradient(-100, -100, 100, 100)
     gradient.setColorAt(0.7, colorr);gradient.setColorAt(1, color)
     root.setBackground(QBrush(gradient))
     root.setEditable(False)
     root.setCheckState(Qt.Checked)
     root.setCheckable(True)
     return root
Exemplo n.º 30
0
 def paintEvent(self, event):
     painter = QPainter(self)
     font_metrics = QFontMetrics(self.font())
     if font_metrics.width(self.text()) > self.contentsRect().width():
         label_width = self.size().width()
         gradient = QLinearGradient(0, 0, label_width, 0)
         gradient.setColorAt(1 - 50.0 / label_width,
                             self.palette().color(self.foregroundRole()))
         gradient.setColorAt(1.0, Qt.transparent)
         painter.setPen(QPen(QBrush(gradient), 1.0))
     painter.drawText(self.contentsRect(),
                      Qt.TextSingleLine | int(self.alignment()),
                      self.text())
Exemplo n.º 31
0
    def drawToolButtonMenuIndicator(self, option, painter, widget=None):
        arrow_rect = self.proxy().subControlRect(QStyle.CC_ToolButton, option, QStyle.SC_ToolButtonMenu, widget)

        text_color = option.palette.color(QPalette.WindowText if option.state & QStyle.State_AutoRaise else QPalette.ButtonText)
        button_color = option.palette.color(QPalette.Button)
        background_color = self.background_color(button_color, 0.5)

        painter.save()

        # draw separating vertical line
        if option.state & (QStyle.State_On|QStyle.State_Sunken):
            top_offset, bottom_offset = 4, 3
        else:
            top_offset, bottom_offset = 2, 2

        if option.direction == Qt.LeftToRight:
            separator_line = QLineF(arrow_rect.x()-3, arrow_rect.top()+top_offset, arrow_rect.x()-3, arrow_rect.bottom()-bottom_offset)
        else:
            separator_line = QLineF(arrow_rect.right()+3, arrow_rect.top()+top_offset, arrow_rect.right()+3, arrow_rect.bottom()-bottom_offset)

        light_gradient = QLinearGradient(separator_line.p1(), separator_line.p2())
        light_gradient.setColorAt(0.0, ColorScheme.shade(self.background_top_color(button_color), ColorScheme.LightShade, 0.0))
        light_gradient.setColorAt(1.0, ColorScheme.shade(self.background_bottom_color(button_color), ColorScheme.MidlightShade, 0.5))
        separator_color = ColorScheme.shade(self.background_bottom_color(button_color), ColorScheme.MidShade, 0.0)

        painter.setRenderHint(QPainter.Antialiasing, False)
        painter.setPen(QPen(light_gradient, 1))
        painter.drawLine(separator_line.translated(-1, 0))
        painter.drawLine(separator_line.translated(+1, 0))
        painter.setPen(QPen(separator_color, 1))
        painter.drawLine(separator_line)

        # draw arrow
        arrow = QPolygonF([QPointF(-3, -1.5), QPointF(0.5, 2.5), QPointF(4, -1.5)])
        if option.direction == Qt.LeftToRight:
            arrow.translate(-2, 1)
        else:
            arrow.translate(+2, 1)
        pen_thickness = 1.6

        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.translate(arrow_rect.center())

        painter.translate(0, +1)
        painter.setPen(QPen(self.calc_light_color(background_color), pen_thickness, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawPolyline(arrow)
        painter.translate(0, -1)
        painter.setPen(QPen(self.deco_color(background_color, text_color), pen_thickness, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawPolyline(arrow)

        painter.restore()
Exemplo n.º 32
0
    def update_items(self):
        rect_cls = QGraphicsRectItem
        nobrush = QBrush(Qt.NoBrush)
        nopen = QPen(QColor('#FFFFFF'))
        grad = Qt.NoBrush
        self.item = rect_cls()

        for codon in self.codons.keys():
            rectitem = rect_cls(self.width, self.margin,
                                self.w, self.h, parent=self.item)
            total_rea = len(self.aa_list[codon])
            if total_rea > 0:

                grad = QLinearGradient(QPointF(0, 0.5), QPointF(1, 0.5))
                grad.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
                pointpos = 1.0 / total_rea
                starting = -0.001
                for reqcol, aa in enumerate(self.aa_list[codon]):
                    curcol = self.bgcolor[aa]
                    # use the same color twice to mark start and end
                    grad.setColorAt(starting + 0.001, curcol)
                    starting += pointpos
                    grad.setColorAt(starting, curcol)

                    # grad.setColorAt(starting, QColor(curcol))
            # put small rec in big rec
            # Comment award of the year !
            brush = QBrush(QColor('#CCCCCC'))
            pen = QPen(QColor('#BBBBBB'))
            if self.codons[codon]:
                brush = QBrush(grad)
                pen = QPen(QColor('#000000'))

            rectitem.setBrush(brush)
            rectitem.setPen(pen)
            # Center text according to rectitem size
            text = QGraphicsSimpleTextItem(self.codons[codon], parent=rectitem)
            text.setFont(self.font)
            text.setBrush(self.fgcolor)
            center = rectitem.boundingRect().center()
            txtw = text.boundingRect().width()
            txth = text.boundingRect().height()
            text.setPos(center.x() - txtw / 2, center.y() - txth / 2)

            self.width += self.w + self.margin

        # now plot the big rect (with margin)
        self.item.setPen(nopen)
        self.item.setBrush(nobrush)
        self.item.setRect(0, 0, self.width, self.h + (2 * self.margin))
Exemplo n.º 33
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(QColor(255, 255, 255, 127)))
        painter.setPen(QPen(Qt.NoPen))

        for i in range(6):
            x_pos = self.width() / 2 + 30 * \
                math.cos(2 * math.pi * i / 6.0) - 10
            y_pos = self.height() / 2 + 30 * \
                math.sin(2 * math.pi * i / 6.0) - 10
            if (self.counter / 5) % 6 == i:
                linear_gradient = QLinearGradient(x_pos + 10, x_pos,
                                                  y_pos + 10, y_pos)
                linear_gradient.setColorAt(0, QColor(135, 206, 250))
                linear_gradient.setColorAt(1, QColor(0, 0, 128))
                painter.setBrush(QBrush(linear_gradient))
            else:
                linear_gradient = QLinearGradient(x_pos - 10, x_pos,
                                                  y_pos + 10, y_pos)
                linear_gradient.setColorAt(0, QColor(105, 105, 105))
                linear_gradient.setColorAt(1, QColor(0, 0, 0))
                painter.setBrush(QBrush(linear_gradient))
            painter.drawEllipse(x_pos, y_pos, 20, 20)

        painter.end()
Exemplo n.º 34
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(QColor(255, 255, 255, 127)))
        painter.setPen(QPen(Qt.NoPen))

        for i in xrange(6):
            x_pos = self.width() / 2 + 30 * \
                math.cos(2 * math.pi * i / 6.0) - 10
            y_pos = self.height() / 2 + 30 * \
                math.sin(2 * math.pi * i / 6.0) - 10
            if (self.counter / 5) % 6 == i:
                linear_gradient = QLinearGradient(
                    x_pos + 10, x_pos, y_pos + 10, y_pos)
                linear_gradient.setColorAt(0, QColor(135, 206, 250))
                linear_gradient.setColorAt(1, QColor(0, 0, 128))
                painter.setBrush(QBrush(linear_gradient))
            else:
                linear_gradient = QLinearGradient(
                    x_pos - 10, x_pos, y_pos + 10, y_pos)
                linear_gradient.setColorAt(0, QColor(105, 105, 105))
                linear_gradient.setColorAt(1, QColor(0, 0, 0))
                painter.setBrush(QBrush(linear_gradient))
            painter.drawEllipse(
                x_pos,
                y_pos,
                20, 20)

        painter.end()
Exemplo n.º 35
0
    def new_anim(self):
        image = None
        painter_id = random.randint(0, 2**32)
        self.active_painer = painter_id
        index = 0
        every = self.ui.repaint.value()

        self.scene.clear()

        tree_count = self.ui.tree_count.value()
        need_spacing = 65
        used_locations = []
        for tree_index in range(tree_count):
            z_range = 80
            base_z = random.uniform(-z_range, z_range)

            def make_base():
                return complex(10 + random.uniform(-350 + 150*tree_count, 350 + 150*tree_count), base_z)
            def closest_distance_to_used(base):
                return min([np.abs(np.real(base - item)) for item in used_locations])
            base_location = make_base()
            while not len(used_locations) == 0 and closest_distance_to_used(base_location) < need_spacing:
                base_location = make_base()

            used_locations.append(base_location)
            scale = 1.0 + 0.75 * ((z_range - base_z) / (2*z_range)) ** 2
            self.tree = Tree(self.get_params(), base_location=base_location, scale=scale)
            for iteration in self.tree.grow_iterations(self.ui.generations.value(), yield_every=every):
                self.tree.draw(self.scene, incremental=True)
                self.ui.progress.setText("Working ... displayed frame: {0}".format(index))

                gradient = QLinearGradient(self.scene.itemsBoundingRect().topLeft(),
                                           self.scene.itemsBoundingRect().bottomLeft())
                gradient.setColorAt(0.4, QColor(0, 0, 0))
                gradient.setColorAt(0, QColor(25, 25, 25))
                self.scene.setBackgroundBrush(QBrush(gradient))

                self.ui.image.repaint()
                QApplication.processEvents()
                index += every
                if self.active_painer != painter_id:
                    return

        self.ui.image.fitInView(self.scene.itemsBoundingRect(), 1)
        d = GrassDrawer(self.ui.image)
        d.draw_some_grass(150 + 75*tree_count)
        #self.ui.image.fitInView(self.scene.itemsBoundingRect(), 1)
        self.ui.progress.setText("Done. Displayed frame: {0}".format(index))
Exemplo n.º 36
0
 def paintEvent(self, _):
     p = QPainter(self)
     points = [
         QPoint(self.width(), -1),
         QPoint(self.width(), self.height()),
         QPoint(0,
                self.height() / 2),
         QPoint(0,
                self.height() / 2 - 1)
     ]
     grad = QLinearGradient(0, 0, 0, self.height())
     grad.setColorAt(0, self.color1)
     grad.setColorAt(1, self.color2)
     p.setBrush(grad)
     p.setPen(QPen(Qt.NoPen))
     p.drawPolygon(QPolygon(points))
Exemplo n.º 37
0
 def getColouredRootItem(sample):
     """stable, may be subdivised in sub routines """
     root = QStandardItem(sample.shortName())
     #root.setIcon(QIcon(QPixmap(os.path.normpath('gui/icons/formula.png'))))
     color = QColor.fromRgbF(sample.color[0], sample.color[1],
                             sample.color[2], 1.)
     colorr = QColor.fromRgbF(sample.color[0], sample.color[1],
                              sample.color[2], .5)
     gradient = QLinearGradient(-100, -100, 100, 100)
     gradient.setColorAt(0.7, colorr)
     gradient.setColorAt(1, color)
     root.setBackground(QBrush(gradient))
     root.setEditable(False)
     root.setCheckState(Qt.Checked)
     root.setCheckable(True)
     return root
Exemplo n.º 38
0
 def paintEvent(self,event):
     painter = QPainter(self)
     painter.save()
     linearGradient = QLinearGradient(0,0,0,self.geometry().width())
     linearGradient.setColorAt(0, QColor(60,150,255))
     linearGradient.setColorAt(0.1, QColor(6,88,200))
     linearGradient.setColorAt(1, QColor(80,150,255))
     painter.setBrush(QBrush(linearGradient))
     contenRect = QRect(0, 0, self.width(), self.topLine-10)
     painter.fillRect(contenRect, QBrush(linearGradient))
     painter.restore()
     
     painterBack = QPainter(self)
     backBrush = QBrush(QColor(200,200,250))
     painterBack.setBrush(backBrush)
     backRect = QRect(0,self.topLine-10,self.width(),self.height())
     painterBack.fillRect(backRect, backBrush)
Exemplo n.º 39
0
    def __init__(self, *args):
        QWidget.__init__(self, *args)

        self.thermo = Qwt.QwtThermo(self)
        self.thermo.setOrientation(Qt.Horizontal, Qwt.QwtThermo.NoScale)
        self.thermo.setRange(0, 3200)
        
        gradient = QLinearGradient(0, 0, 300, 0)
        gradient.setColorAt(0, Qt.green)
        gradient.setColorAt(1, Qt.red)
        
        self.thermo.setFillBrush(QBrush(gradient))
        
        self.setFixedWidth(300)

        layout = QVBoxLayout(self)
        layout.setMargin(0)
        layout.addWidget(self.thermo)
Exemplo n.º 40
0
    def paintSection(self, painter, rect, logicalIndex):
        gradient = QLinearGradient(0, 0, 0, rect.height())
        if self._mouse_over:
            gradient.setColorAt(0.0, QColor("#808080"))
            gradient.setColorAt(1.0, QColor("#474747"))
        else:
            gradient.setColorAt(0.0, QColor("#727272"))
            gradient.setColorAt(1.0, QColor("#363636"))
        painter.fillRect(rect, QBrush(gradient))

        if self._is_current_project:
            painter.setPen(QColor(0, 204, 82))
        else:
            painter.setPen(QColor(Qt.white))
        font = painter.font()
        font.setBold(True)
        painter.setFont(font)
        font_metrics = QFontMetrics(painter.font())
        ypos = (rect.height() / 2) + (font_metrics.height() / 3)
        painter.drawText(10, ypos, self.title)
Exemplo n.º 41
0
    def paintSection(self, painter, rect, logicalIndex):
        gradient = QLinearGradient(0, 0, 0, rect.height())
        if self._mouse_over:
            gradient.setColorAt(0.0, QColor("#808080"))
            gradient.setColorAt(1.0, QColor("#474747"))
        else:
            gradient.setColorAt(0.0, QColor("#727272"))
            gradient.setColorAt(1.0, QColor("#363636"))
        painter.fillRect(rect, QBrush(gradient))

        if self._is_current_project:
            painter.setPen(QColor(0, 204, 82))
        else:
            painter.setPen(QColor(Qt.white))
        font = painter.font()
        font.setBold(True)
        painter.setFont(font)
        font_metrics = QFontMetrics(painter.font())
        ypos = (rect.height() / 2) + (font_metrics.height() / 3)
        painter.drawText(10, ypos, self.title)
Exemplo n.º 42
0
    def _verticalGradientHelper(cls, painter: QPainter, spanRect: QRect, rect: QRect, lightColored):
        """
        :type painter: QPainter
        :type spanRect: QRect
        :type rect: QRect
        :type lightColored: bool
        """
        highlight = StyleHelper.highlightColor(lightColored)
        shadow = StyleHelper.shadowColor(lightColored)
        grad = QLinearGradient(spanRect.topRight(), spanRect.topLeft())
        grad.setColorAt(0, highlight.lighter(117))
        grad.setColorAt(1, shadow.darker(109))
        painter.fillRect(rect, grad)

        light = QColor(255, 255, 255, 80)
        painter.setPen(light)
        painter.drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0))
        dark = QColor(0, 0, 0, 90)
        painter.setPen(dark)
        painter.drawLine(rect.topLeft(), rect.bottomLeft())
Exemplo n.º 43
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(QColor(255, 255, 255, 127)))
        painter.setPen(QPen(Qt.NoPen))

        for i in range(3):
            x = self.width() / 2.3 + (30 * i)
            y = self.height() / 2
            # Gradiente
            gradient = QLinearGradient(x + 10, x, y + 10, y)
            gradient.setColorAt(0, QColor("black"))
            gradient.setColorAt(1, QColor("gray"))
            painter.setBrush(QBrush(gradient))
            if self.counter / 2 % 3 == i:
                painter.drawEllipse(x, y, 25, 25)
            else:
                painter.drawEllipse(x, y, 20, 20)
        painter.end()
Exemplo n.º 44
0
class TuningThermo(QWidget):
    def __init__(self, *args):
        QWidget.__init__(self, *args)

        self.bar_width = 200  # px
        self.bar_height = 10  # px
        self.border = 3  # px
        self.value = 0
        self.max_value = 1000
        self.min_value = 300

        self.setFixedWidth(self.border + self.bar_width + self.border)
        self.setFixedHeight(self.border + self.bar_height + self.border)
        self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)

        self.gradient = QLinearGradient(0, 0, self.bar_width, 0)
        self.gradient.setColorAt(0, Qt.green)
        self.gradient.setColorAt(1, Qt.red)

    def paintEvent(self, event):
        painter = QPainter(self)
        width = self.width()
        height = self.height()

        painter.fillRect(0, 0, width, height, QColor(245, 245, 245))

        painter.setPen(QColor(190, 190, 190))
        painter.drawRect(0, 0, width - 1, height - 1)

        filled_bar_width = round(
            float(width - self.border * 2 - 1) * self.value / self.max_value +
            1)

        painter.fillRect(self.border, self.border, filled_bar_width,
                         height - self.border * 2, self.gradient)

    def set_value(self, value):
        value = value - self.min_value
        self.value = min(max(value, 0), self.max_value - self.min_value)

        self.update()
Exemplo n.º 45
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()
Exemplo n.º 46
0
 def verticalGradient(self, painter, spanRect, clipRect):
     key = 'fancy vertical gradient %d %d %d %d %d'%(spanRect.width(), spanRect.height(), clipRect.width(),
                                          clipRect.height(), self.baseColor.rgb())
     pixmap = QPixmap()
     p = painter
     rect = QRect(clipRect)
     
     if self._usePixmapCache and not QPixmapCache.find(key, pixmap):
         pixmap = QPixmap(clipRect.size())
         p = QPainter(pixmap)
         rect = QRect(0, 0, clipRect.width(), clipRect.height())
     
     base = self.baseColor
     grad = QLinearGradient(QPointF(spanRect.topRight()), QPointF(spanRect.topLeft()))
     grad.setColorAt(0, self.highlightColor)
     grad.setColorAt(0.301, base)
     grad.setColorAt(1, self.shadowColor)
     p.fillRect(rect, grad)
     
     light = QColor(255, 255, 255, 80)
     p.setPen(light)
     p.drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0))
     
     if self._usePixmapCache and not QPixmapCache.find(key, pixmap):
         painter.drawPixmap(clipRect.topLeft(), pixmap)
         p.end()
         del p
         QPixmapCache.insert(key, pixmap)
Exemplo n.º 47
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()
Exemplo n.º 48
0
class MainWindow(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.frmTuner = TunerFrame( self )
        #self.frmTuner.setFrameStyle( QFrame.Panel | QFrame.Raised )

        self.frmAmp = AmpFrame( self )
        self.frmAmp.setFrameStyle( QFrame.Panel | QFrame.Raised )

        self.layout = QVBoxLayout( self )
        #self.layout.setMargin( 0 )
        self.layout.setSpacing( 0 )
        self.layout.addWidget( self.frmTuner )
        self.layout.addWidget( self.frmAmp )

        self.frmTuner.fieldChanged['double'].connect(self.frmAmp.setMaster)

        self.frmTuner.setFreq( 90.0 )

        self.setPalette( QPalette( QColor( 192, 192, 192 ) ) )
        self.updateGradient()

    def resizeEvent(self, QResizeEvent  ):
        # Qt 4.7.1: QGradient.StretchToDeviceMode is buggy on X11
        self.updateGradient()

    def updateGradient(self):
        self.pal = QPalette()

        self.buttonColor = self.pal.color( QPalette.Button )
        self.midLightColor = self.pal.color( QPalette.Midlight )

        #self.gradient = QLinearGradient( rect().topLeft(), rect().topRight() ) FIXME
        self.gradient = QLinearGradient(  )
        self.gradient.setColorAt( 0.0, self.midLightColor )
        self.gradient.setColorAt( 0.7, self.buttonColor )
        self.gradient.setColorAt( 1.0, self.buttonColor )

        self.pal.setBrush( QPalette.Window, self.gradient )
        self.setPalette( self.pal )
Exemplo n.º 49
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()
Exemplo n.º 50
0
    def updateColor(self):
        """
        Update the color on the sampleModel
        modify to fit to the actual view
        
        """
        if not self.view.sampleTableView.selectedIndexes(
        ):  #not self.acTree.selectedIndexes():
            return

        idx = self.view.sampleTableView.selectedIndexes()[0]
        sample = self.model.sample(idx.data().toString(), fullNameEntry=False)

        if sample is None:
            self.view.showErrorMessage('Error',
                                       'Please choose only one file...')
            return

        color = QColorDialog.getColor()
        if not color.isValid():
            return

        sample.color = color.getRgbF()[:-1]

        #make the gradient color here to
        color = QColor.fromRgbF(*(sample.color + (1., )))
        colorr = QColor.fromRgbF(*(sample.color + (.5, )))
        gradient = QLinearGradient(-100, -100, 100, 100)
        gradient.setColorAt(0.7, colorr)
        gradient.setColorAt(1, color)

        #for m in (self.view.sampleModel, self.view.spectraModel, self.view.peakModel,
        #          self.view.clusterModel):#self.view.chromaModel,
        for i in xrange(self.view.sampleModel.rowCount()):
            item = self.view.sampleModel.item(i, 0)
            if item.text() == sample.shortName():
                item.setBackground(QBrush(gradient))
Exemplo n.º 51
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)
Exemplo n.º 52
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)
Exemplo n.º 53
0
 def paintEvent(self, event):
     color = self.state_colors[self.state]
     painter = QPainter(self)
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
     gradient = QLinearGradient(0, 0, self.width(), 0)
     gradient.setColorAt(0.0, Qt.transparent)
     gradient.setColorAt(1.0, color)
     painter.setBrush(QBrush(gradient))
     gradient.setColorAt(1.0, color.stroke)
     painter.setPen(QPen(QBrush(gradient), 1))
     painter.drawRoundedRect(-4, 0,
                             self.width() + 4, self.height(), 3.7, 3.7)
Exemplo n.º 54
0
 def paintEvent(self, ev):
     """
     IceAndFire = Colormap("IceAndFire",
                   (0.00, (0.0, 0.0, 1.0)),
                   (0.25, (0.0, 0.5, 1.0)),
                   (0.50, (1.0, 1.0, 1.0)),
                   (0.75, (1.0, 1.0, 0.0)),
                   (1.00, (1.0, 0.0, 0.0)))
     """
     painter = QPainter()
     painter.begin(self)
     g = QLinearGradient(0, 0, self.width(), self.height())
     g.setColorAt(0., QColor.fromRgbF(0.0, 0.0, 1.0))
     g.setColorAt(0.25, QColor.fromRgbF(0.0, 0.5, 1.0))
     g.setColorAt(0.5, QColor.fromRgbF(1.0, 1., 1.0))
     g.setColorAt(0.75, QColor.fromRgbF(1.0, 1., 0.))
     g.setColorAt(1., QColor.fromRgbF(1.0, 0., 0.))
     painter.setBrush(QBrush(g))
     painter.fillRect(0, 0, self.width(), self.height(), g)
     painter.end()
Exemplo n.º 55
0
    def __init__(self, x=None, y=None, w=None, h=None):
        super(PipeItem, self).__init__()
        self.rect = QRectF(x, y, w, h)

        gradient = QLinearGradient(0, 0, w, 0)
        gradient.setColorAt(0.0, QColor(56, 180, 74))
        gradient.setColorAt(0.5, QColor(151, 180, 56, 225))
        gradient.setColorAt(1.0, QColor(56, 180, 74))

        self.brush = QBrush(gradient)

        p = QPen(QColor(0, 0, 0))
        p.setWidth(2)
        self.pen = p
Exemplo n.º 56
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()