コード例 #1
0
    def paintEvent(self, event):
        """
        Overloads the paint event to draw rounded edges on this widget.
        
        :param      event | <QPaintEvent>
        """
        super(XRolloutItem, self).paintEvent(event)

        painter = QPainter()
        painter.begin(self)

        w = self.width() - 3
        h = self.height() - 3

        color = self.palette().color(QPalette.Midlight)
        color = color.darker(180)
        pen = QPen(color)
        pen.setWidthF(0.5)

        painter.setPen(pen)
        painter.setBrush(self.palette().color(QPalette.Midlight))
        painter.setRenderHint(QPainter.Antialiasing)
        painter.drawRoundedRect(1, 1, w, h, 10, 10)

        painter.end()
コード例 #2
0
 def paintEvent(self, event):
     'Paint semi-transparent background, animated pattern, background text'
     QWidget.paintEvent(self, event)
     # make a painter
     p = QPainter(self)
     p.setRenderHint(QPainter.TextAntialiasing)
     p.setRenderHint(QPainter.HighQualityAntialiasing)
     # fill a rectangle with transparent painting
     p.fillRect(event.rect(), Qt.transparent)
     # animated random dots background pattern
     for i in range(4096):
         x = randint(9, self.size().width() - 9)
         y = randint(9, self.size().height() - 9)
         p.setPen(QPen(QColor(randint(200, 255), randint(200, 255), 255), 1))
         p.drawPoint(x, y)
     # set pen to use white color
     p.setPen(QPen(QColor(randint(9, 255), randint(9, 255), 255), 1))
     # Rotate painter 45 Degree
     p.rotate(35)
     # Set painter Font for text
     p.setFont(QFont('Ubuntu', 300))
     # draw the background text, with antialiasing
     p.drawText(99, 199, "Radio")
     # Rotate -45 the QPen back !
     p.rotate(-35)
     # set the pen to no pen
     p.setPen(Qt.NoPen)
     # Background Color
     p.setBrush(QColor(0, 0, 0))
     # Background Opacity
     p.setOpacity(0.75)
     # Background Rounded Borders
     p.drawRoundedRect(self.rect(), 50, 50)
     # finalize the painter
     p.end()
コード例 #3
0
    def paintEvent(self, event):
        crect = self.rect()
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.setBrush(QBrush(Qt.white))
        painter.setPen(QPen(Qt.lightGray, 1.2))
        painter.drawRoundedRect(
            QRectF(crect).adjusted(2, 2, -2, -2), 2, 2, Qt.AbsoluteSize)

        if self._selected:
            painter.setPen(QPen(QBrush(Qt.red), 2))
        if self._highlighted:
            painter.setBrush(QBrush(Qt.gray, Qt.FDiagPattern))
        else:
            painter.setBrush(Qt.NoBrush)

        painter.drawRoundedRect(
            QRectF(crect).adjusted(2, 2, -2, -2), 2, 2, Qt.AbsoluteSize)

        defsize = self.renderer().defaultSize()
        margin = 5

        bound = QSize(defsize)
        bound.scale(crect.width() - margin,
                    crect.height() - margin, Qt.KeepAspectRatio)

        svgrect = QRectF(0, 0, bound.width(), bound.height())
        svgrect.moveCenter(crect.center())
        self.renderer().render(painter, svgrect)
コード例 #4
0
ファイル: qprogressindicator.py プロジェクト: pardus-anka/pds
    def paintEvent(self, event):
        if not self.displayedWhenStopped and not self.isAnimated():
            return

        width = min(self.width(), self.height())

        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        outerRadius = (width-1) * 0.5
        innerRadius = (width-1) * 0.5 * 0.38

        capsuleHeight = outerRadius - innerRadius
        capsuleWidth  = capsuleHeight * 0.23 if width > 32 else capsuleHeight * 0.35
        capsuleRadius = capsuleWidth / 2

        for i in range(12):
            color = QColor(self.color)
            color.setAlphaF(float(1.0 - float(i / 12.0)))
            p.setPen(Qt.NoPen)
            p.setBrush(color)
            p.save()
            p.translate(self.rect().center())
            p.rotate(self.angle - float(i * 30.0))
            p.drawRoundedRect(-capsuleWidth * 0.5,\
                              -(innerRadius + capsuleHeight),\
                              capsuleWidth,\
                              capsuleHeight,\
                              capsuleRadius,\
                              capsuleRadius)
            p.restore()
コード例 #5
0
 def _paint_bg(self, p: QPainter):
     dpi = Info.dpi
     pen = self.pen()
     p.setRenderHint(QPainter.Antialiasing, True)
     p.setPen(pen)
     p.setBrush(self.bg())
     p.drawRoundedRect(OIBlock.padding * dpi, OIBlock.padding * dpi,
                       self.width() - 2 * OIBlock.padding * dpi,
                       self.height() - 2 * OIBlock.padding * dpi,
                       OIBlock.radius * dpi, OIBlock.radius * dpi)
     p.setBrush(self.title_bg())
     p.drawRoundedRect(OIBlock.padding * dpi, OIBlock.padding * dpi,
                       self.width() - 2 * OIBlock.padding * dpi,
                       .35 * dpi + OIBlock.padding * dpi,
                       OIBlock.radius * dpi, OIBlock.radius * dpi)
     p.setBrush(self.bg())
     p.setPen(QColor(0, 0, 0, 0))
     p.drawRect(0.01 * dpi + OIBlock.padding * dpi,
                0.35 * dpi + OIBlock.padding * dpi,
                self.width() - 0.02 * dpi - 2 * OIBlock.padding * dpi,
                0.10 * dpi)
     p.setPen(pen)
     if self._resizable:
         if self.__corner_path is None:
             self.__init_corner()
         p.setBrush(pen.brush())
         p.drawPath(
             self.__corner_path.translated(self.width(), self.height()))
コード例 #6
0
    def paintEvent(self, event):
        crect = self.rect()
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.setBrush(QBrush(Qt.white))
        painter.setPen(QPen(Qt.lightGray, 1.2))
        painter.drawRoundedRect(QRectF(crect).adjusted(2, 2, -2, -2), 2, 2,
                                Qt.AbsoluteSize)

        if self._selected:
            painter.setPen(QPen(QBrush(Qt.red), 2))
        if self._highlighted:
            painter.setBrush(QBrush(Qt.gray,  Qt.FDiagPattern))
        else:
            painter.setBrush(Qt.NoBrush)

        painter.drawRoundedRect(QRectF(crect).adjusted(2, 2, -2, -2), 2, 2,
                                Qt.AbsoluteSize)

        defsize = self.renderer().defaultSize()
        margin = 5

        bound = QSize(defsize)
        bound.scale(crect.width() - margin, crect.height() - margin,
                    Qt.KeepAspectRatio)

        svgrect = QRectF(0, 0, bound.width(), bound.height())
        svgrect.moveCenter(crect.center())
        self.renderer().render(painter, svgrect)
コード例 #7
0
 def paintEvent( self, event ):
     """
     Overloads the paint event to draw rounded edges on this widget.
     
     :param      event | <QPaintEvent>
     """
     super(XRolloutItem, self).paintEvent(event)
     
     painter = QPainter()
     painter.begin(self)
     
     w = self.width() - 3
     h = self.height() - 3
     
     color = self.palette().color(QPalette.Midlight)
     color = color.darker(180)
     pen = QPen(color)
     pen.setWidthF(0.5)
     
     painter.setPen(pen)
     painter.setBrush(self.palette().color(QPalette.Midlight))
     painter.setRenderHint(QPainter.Antialiasing)
     painter.drawRoundedRect(1, 1, w, h, 10, 10)
     
     painter.end()
コード例 #8
0
 def paintEvent(self, e: QPaintEvent):
     if e.isAccepted():
         p = QPainter(self)
         p.setPen(QColor(255, 255, 255))
         c = self.__node.type().color().darker()
         p.setBrush(QColor(c.red(), c.green(), c.blue(), 180))
         p.drawRoundedRect(1, 1, self.width() - 2, self.height() - 2, 5, 5)
         p.drawText(QRect(5, 5, self.width() - 10, self.height() - 10), Qt.AlignCenter, self.__name)
コード例 #9
0
ファイル: pyuic-gui.py プロジェクト: ftillouhamid/pyuic-gui
 def paintEvent(self, event):
     ' Paint semi-transparent background '
     painter = QPainter(self)
     painter.fillRect(event.rect(), Qt.transparent)
     painter.setPen(Qt.NoPen)
     painter.setBrush(QColor(0, 0, 0))
     painter.setOpacity(0.75)
     painter.drawRoundedRect(self.rect(), 75, 50)
     painter.end()
コード例 #10
0
ファイル: widgets.py プロジェクト: oaoailoveyou321/camshot
 def paintEvent(self, event):
     painter = QPainter(self)
     if self.border:
         size = self.size()
         painter.setPen(Colors.eyegrade_blue)
         painter.drawRoundedRect(0, 0, size.width() - 2, size.height() - 2,
                                 10, 10)
         painter.drawImage(5, 5, self.image)
     else:
         painter.drawImage(event.rect(), self.image)
コード例 #11
0
 def _paint_bg(self, p: QPainter):
     pen = self.pen()
     p.setRenderHint(QPainter.Antialiasing, True)
     p.setPen(pen)
     p.setBrush(self.bg())
     p.drawRoundedRect(Block.padding, Block.padding, self.width() - 2 * Block.padding,
                       self.height() - 2 * Block.padding, 8, 8)
     p.setPen(pen)
     if self._resizable:
         p.setBrush(pen.brush())
         p.drawPath(self._corner_path().translated(self.width(), self.height()))
コード例 #12
0
ファイル: blink.py プロジェクト: WedgeLeft/frescobaldi
 def paintEvent(self, ev):
     color = self._color
     if not color or color.alpha() == 0:
         return
     painter = QPainter(self)
     adj = self.lineWidth / 2
     rect = self.rect().adjusted(adj, adj, -adj, -adj)
     pen = QPen(color)
     pen.setWidth(self.lineWidth)
     painter.setPen(pen)
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.drawRoundedRect(rect, self.radius, self.radius)
コード例 #13
0
ファイル: labels.py プロジェクト: scudella/blink-qt
 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)
コード例 #14
0
 def paintEvent(self, ev):
     color = self._color
     if not color or color.alpha() == 0:
         return
     painter = QPainter(self)
     adj = self.lineWidth / 2
     rect = self.rect().adjusted(adj, adj, -adj, -adj)
     pen = QPen(color)
     pen.setWidth(self.lineWidth)
     painter.setPen(pen)
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.drawRoundedRect(rect, self.radius, self.radius)
コード例 #15
0
 def paintEvent(self, event):
     painter = QPainter()
     painter.begin(self)
     # painter.setRenderHint(QPainter.Antialiasing)
     # # painter.setPen(Qt.NoPen)
     # painter.drawPixmap(0, 0, 59, 51, QPixmap("C:\Users\user\Desktop\logo.png"))
     rect = QRect(0, 0, 799, 599)
     pen = QPen(QColor(30, 30, 30, 255 * 0.8), 1)  #定义画笔
     painter.setPen(pen)
     painter.drawLine(580, 0, 580, 600)  #划线
     painter.drawLine(0, 60, 580, 60)  # 划线
     painter.drawRoundedRect(rect, 10, 10)
     painter.end()
コード例 #16
0
 def round(self):
     bmp = QBitmap(self.size())
     p = QPainter()
     p.begin(bmp)
     p.fillRect(bmp.rect(), Qt.white)
     p.setBrush(QColor(0,0,0))
     p.drawRoundedRect(bmp.rect(), 5, 5)
     p.setPen(QColor(255,255,255,255))
     p.drawPoints(QPointF(self.width()-2,self.height()-1), QPointF(self.width()-1,self.height()-2))
     p.setPen(QColor(0,0,0))
     p.drawPoints(QPointF(0,2),QPointF(3,0),QPointF(2,0),QPointF(1,1))
     p.end()
     self.setMask(bmp)
コード例 #17
0
ファイル: labels.py プロジェクト: webodf/blink-qt
 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)
コード例 #18
0
 def round(self):
     bmp = QBitmap(self.size())
     p = QPainter()
     p.begin(bmp)
     p.fillRect(bmp.rect(), Qt.white)
     p.setBrush(QColor(0,0,0))
     p.drawRoundedRect(bmp.rect(), 5, 5)
     p.setPen(QColor(255,255,255,255))
     p.drawPoints(QPointF(self.width()-2,self.height()-1), QPointF(self.width()-1,self.height()-2))
     p.setPen(QColor(0,0,0))
     p.drawPoints(QPointF(0,2),QPointF(3,0),QPointF(2,0),QPointF(1,1))
     p.end()
     self.setMask(bmp)
コード例 #19
0
 def _dialog_paintEvent(self, d, event):
     QDialog.paintEvent(d, event)
     pen = QPen()
     pen.setWidth(2)
     pen.setColor(QColor(200, 200, 200))
     rect = d.rect()
     rect = rect.adjusted(0, 0, -1, -1)
     painter = QPainter(d)
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setPen(pen)
     painter.setOpacity(0.8)
     painter.setBrush(QBrush(QColor(Qt.white)))
     painter.drawRoundedRect(rect, 15, 15)
コード例 #20
0
ファイル: framelesswindow.py プロジェクト: AutumnLight/orange
    def paintEvent(self, event):
        if self.__isTransparencySupported:
            opt = QStyleOption()
            opt.init(self)
            rect = opt.rect

            p = QPainter(self)
            p.setRenderHint(QPainter.Antialiasing, True)
            p.setBrush(opt.palette.brush(QPalette.Window))
            p.setPen(Qt.NoPen)
            p.drawRoundedRect(rect, self.__radius, self.__radius)
            p.end()
        else:
            StyledWidget_paintEvent(self, event)
コード例 #21
0
ファイル: framelesswindow.py プロジェクト: yisuax11/orange2
    def paintEvent(self, event):
        if self.__isTransparencySupported:
            opt = QStyleOption()
            opt.init(self)
            rect = opt.rect

            p = QPainter(self)
            p.setRenderHint(QPainter.Antialiasing, True)
            p.setBrush(opt.palette.brush(QPalette.Window))
            p.setPen(Qt.NoPen)
            p.drawRoundedRect(rect, self.__radius, self.__radius)
            p.end()
        else:
            StyledWidget_paintEvent(self, event)
コード例 #22
0
ファイル: mainwindow.py プロジェクト: grengojbo/blink-qt
 def set_user_icon(self, image_file_name):
     pixmap = QPixmap(32, 32)
     pixmap.fill(QColor(Qt.transparent))
     painter = QPainter(pixmap)
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setBrush(QBrush(Qt.white))
     painter.setPen(QPen(painter.brush(), 0, Qt.NoPen))
     #painter.drawRoundedRect(0, 0, 32, 32, 6, 6)
     painter.drawRoundedRect(0, 0, 32, 32, 0, 0)
     icon = QPixmap()
     if icon.load(image_file_name):
         icon = icon.scaled(32, 32, Qt.KeepAspectRatio, Qt.SmoothTransformation)
         painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
         painter.drawPixmap(0, 0, icon)
     painter.end()
     self.image.setPixmap(pixmap)
コード例 #23
0
ファイル: framelesswindow.py プロジェクト: AutumnLight/orange
    def __updateMask(self):
        opt = QStyleOption()
        opt.init(self)
        rect = opt.rect

        size = rect.size()
        mask = QBitmap(size)

        p = QPainter(mask)
        p.setRenderHint(QPainter.Antialiasing)
        p.setBrush(Qt.black)
        p.setPen(Qt.NoPen)
        p.drawRoundedRect(rect, self.__radius, self.__radius)
        p.end()

        self.setMask(mask)
コード例 #24
0
ファイル: framelesswindow.py プロジェクト: yisuax11/orange2
    def __updateMask(self):
        opt = QStyleOption()
        opt.init(self)
        rect = opt.rect

        size = rect.size()
        mask = QBitmap(size)

        p = QPainter(mask)
        p.setRenderHint(QPainter.Antialiasing)
        p.setBrush(Qt.black)
        p.setPen(Qt.NoPen)
        p.drawRoundedRect(rect, self.__radius, self.__radius)
        p.end()

        self.setMask(mask)
コード例 #25
0
 def _paint_bg(self, p: QPainter):
     pen = Block.selected_pen if self.__selected else Block.border_pen
     p.setRenderHint(QPainter.Antialiasing, True)
     p.setPen(pen)
     p.setBrush(self.bg())
     p.drawRoundedRect(Block.padding, Block.padding, self.width() - 2 * Block.padding,
                       self.height() - 2 * Block.padding, 8, 8)
     p.setBrush(self.title_bg())
     p.drawRoundedRect(Block.padding, Block.padding, self.width() - 2 * Block.padding, 35 + Block.padding, 8, 8)
     p.setBrush(self.bg())
     p.setPen(QColor(0, 0, 0, 0))
     p.drawRect(1 + Block.padding, 35 + Block.padding, self.width() - 2 - 2 * Block.padding, 10)
     p.setPen(pen)
     if self._resizable:
         p.setBrush(pen.brush())
         p.drawPath(self.__corner_path.translated(self.width(), self.height()))
コード例 #26
0
ファイル: layout_editor.py プロジェクト: OSUser/quickpanel
 def paintEvent(self, event):
     QWidget.paintEvent(self, event)
     pen = QPen()
     pen.setWidth(2)
     pen.setColor(QColor(200, 200, 200))
     rect = self.rect()
     rect = rect.adjusted(0, 0, -1, -1)
     painter = QPainter(self)
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setPen(pen)
     painter.setOpacity(0.5)
     painter.setBrush(QBrush(QColor(Qt.white)))
     painter.drawRoundedRect(rect, 15, 15)
     painter.setOpacity(1)
     pen.setColor(Qt.black)
     painter.setPen(pen)
     text = self.name + "\n" + self.description
     painter.drawText(self.rect(), Qt.AlignHCenter | Qt.AlignVCenter, text)
コード例 #27
0
ファイル: widgetArquivo.py プロジェクト: tassio/MensageiroQt
    def paintEvent(self, event):
        QWidget.paintEvent(self, event)
        rect = QRectF(self.rect())

        painter = QPainter(self)
        painter.setBrush(self._corFundo)

        pen = QPen()
        pen.setColor(Qt.gray)
        painter.setPen(pen)

        painter.drawRoundedRect(QRectF(2, 1, rect.width()-6, rect.height()-4), 8, 2)
        if self.getPorcentagem() > 0:
            painter.setBrush(self._corBarra)
            larguraBarra = self.getPorcentagem()*((rect.width()-6)/100.)
            painter.drawRoundedRect(QRectF(2, 1, larguraBarra, rect.height()-4), 8, 2)
            
        painter.end()
コード例 #28
0
ファイル: mybutton.py プロジェクト: lange5959/qkt_code
    def paintEvent(self, event):
        painter = QPainter(self)
        btnRect = self.geometry()
        iconRect = self.iconSize()

        color = QColor(Qt.black)
        if self.hovered:
            color = self.color
        if self.pressed:
            color = self.color.darker(120)

        painter.setPen(QPen(QColor(Qt.lightGray), 2))
        outline = QPainterPath()
        outline.addRoundedRect(0, 0, btnRect.width(), btnRect.height(), 0, 0)
        painter.setOpacity(1)
        painter.drawPath(outline)

        painter.setBrush(QBrush(color))
        painter.setOpacity(self.opacity)
        painter_path = QPainterPath()
        painter_path.addRoundedRect(1, 1,
                                    btnRect.width() - 2,
                                    btnRect.height() - 2, 0, 0)
        if self.hovered:
            painter.setClipPath(painter_path)
            painter.drawRoundedRect(1, 1,
                                    btnRect.width() - 2,
                                    btnRect.height() - 2, 0, 0)

        painter.setOpacity(1)

        iconPos, textPos = self.calIconTextPos(btnRect, iconRect)
        # 重画文本
        if not self.text().isNull():
            painter.setFont(self.font())
            painter.setPen(QPen(QColor(Qt.black), 2))
            painter.drawText(textPos.x(), textPos.y(), textPos.width(),
                             textPos.height(), Qt.AlignCenter, self.text())
            # 重画图标
        if not self.icon().isNull():
            painter.drawPixmap(iconPos,
                               QPixmap(self.icon().pixmap(self.iconSize())))
コード例 #29
0
ファイル: processors.py プロジェクト: artscoop/scoop
def rounded_corners(image, radius=0, **kwargs):
    """
    Appliquer un découpage du masque de l'image en rectangle arrondi

    :param image: image PIL
    :param radius: rayon en pixels des coins arrondis
    """
    if radius == "full" or isinstance(radius, (int, float)):
        qimage = _pil_to_qt(image)
        newimage = _qt_canvas(image)
        painter = QPainter(newimage)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setBrush(QBrush(qimage))
        painter.setPen(QColor(0, 0, 0, 0))
        if radius == "full":  # découper en ellipse
            painter.drawEllipse(0, 0, qimage.width(), qimage.height())
        elif isinstance(radius, (int, float)):  # découper en rectangle arrondi
            painter.drawRoundedRect(0, 0, qimage.width(), qimage.height(),
                                    radius, radius)
        painter.end()
        return _qt_to_pil(newimage)
    return image
コード例 #30
0
ファイル: OIBlocks.py プロジェクト: Mandarancio/OpenIris
 def _paint_bg(self, p: QPainter):
     dpi = Info.dpi
     pen = self.pen()
     p.setRenderHint(QPainter.Antialiasing, True)
     p.setPen(pen)
     p.setBrush(self.bg())
     p.drawRoundedRect(OIBlock.padding * dpi, OIBlock.padding * dpi, self.width() - 2 * OIBlock.padding * dpi,
                       self.height() - 2 * OIBlock.padding * dpi, OIBlock.radius * dpi, OIBlock.radius * dpi)
     p.setBrush(self.title_bg())
     p.drawRoundedRect(OIBlock.padding * dpi, OIBlock.padding * dpi, self.width() - 2 * OIBlock.padding * dpi,
                       .35 * dpi + OIBlock.padding * dpi, OIBlock.radius * dpi,
                       OIBlock.radius * dpi)
     p.setBrush(self.bg())
     p.setPen(QColor(0, 0, 0, 0))
     p.drawRect(0.01 * dpi + OIBlock.padding * dpi, 0.35 * dpi + OIBlock.padding * dpi,
                self.width() - 0.02 * dpi - 2 * OIBlock.padding * dpi, 0.10 * dpi)
     p.setPen(pen)
     if self._resizable:
         if self.__corner_path is None:
             self.__init_corner()
         p.setBrush(pen.brush())
         p.drawPath(self.__corner_path.translated(self.width(), self.height()))
コード例 #31
0
 def paintEvent(self,event):
     painter = QPainter(self)
     btnRect = self.geometry()
     
     color = QColor(Qt.black)
     if self.hovered:
         color = self.color
     if self.pressed:
         color = self.color.darker(120)
         
     painter.setBrush(QBrush(color)) 
     painter_path = QPainterPath()
     painter_path.addRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0)
     
     if self.hovered:
         painter.setPen(QPen(color,2))
         outline = QPainterPath()
         outline.addRoundedRect(0, 0, btnRect.width(), btnRect.height(), 0, 0)
         painter.setOpacity(1)
         painter.drawPath(outline)
         painter.setClipPath(painter_path)
         painter.drawRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0)
     
     iconWidth = self.iconSize().width()*3/5
     iconHeight = self.iconSize().height()*3/5
     iconX = (btnRect.width()-iconWidth)/2
     iconY = (btnRect.height()-iconHeight)/2
     
     if self.pressed:
         iconX += 2
         iconY += 2
     
     iconPos = QRect()
     iconPos.setX(iconX)
     iconPos.setY(iconY)
     iconPos.setWidth(iconWidth)
     iconPos.setHeight(iconHeight)
     
     painter.drawPixmap(iconPos, QPixmap(self.icon().pixmap(self.iconSize())))
コード例 #32
0
    def paintEvent(self, e: QPaintEvent):
        if not e.isAccepted():
            return
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)
        p.setPen(QColor(0, 0, 0, 0))
        p.setBrush(QColor(55, 50, 47))
        p.drawRect(0, 0, 11, self.height())

        if self.__drag:
            p.setBrush(QColor(255, 255, 255, 180))
        else:
            p.setBrush(QColor(0, 0, 0, 180))
        p.setPen(QPen(QColor(255, 255, 255), 0.5))
        p.drawRoundedRect(1, 10, 20, 20, 2, 2)
        p.setBrush(QColor(205, 205, 205, 180))
        p.drawEllipse(4, 18, 4, 4)

        p.setBrush(self.palette().color(self.backgroundRole()))
        p.setPen(QColor(0, 0, 0, 0))
        p.drawRect(10, 0, self.width() - 10, self.height())
        p.setPen(QColor(0, 0, 0))
        p.drawLine(10, 0, 10, self.height())
コード例 #33
0
 def paintEvent(self,event):
     return
     painter = QPainter(self)
     btnRect = self.geometry()
     iconRect = self.iconSize()
     
     color = QColor(Qt.black)
     if self.hovered:
         color = self.color
     if self.pressed:
         color = self.color.darker(120)
     
     painter.setPen(QPen(QColor(Qt.lightGray),2))
     outline = QPainterPath()
     outline.addRoundedRect(0, 0, btnRect.width(), btnRect.height(), 0, 0)
     painter.setOpacity(1)
     painter.drawPath(outline)
    
     painter.setBrush(QBrush(color)) 
     painter.setOpacity(self.opacity)
     painter_path = QPainterPath()
     painter_path.addRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0)
     if self.hovered:
         painter.setClipPath(painter_path)
         painter.drawRoundedRect(1, 1, btnRect.width() - 2, btnRect.height() - 2, 0, 0)
     
     painter.setOpacity(1)       
     
     iconPos,textPos = self.calIconTextPos(btnRect, iconRect)
     # 重画文本
     if not self.text().isNull():
         painter.setFont(self.font())
         painter.setPen(QPen(QColor(Qt.black),2))
         painter.drawText(textPos.x(), textPos.y(), textPos.width(), textPos.height(), Qt.AlignCenter, self.text())
         # 重画图标
     if not self.icon().isNull():
         painter.drawPixmap(iconPos, QPixmap(self.icon().pixmap(self.iconSize())))
コード例 #34
0
ファイル: nuitka-gui.py プロジェクト: GaelicGrime/nuitka-gui
 def paintEvent(self, event):
     """Paint semi-transparent background,animated pattern,background text"""
     if not A11Y:
         p = QPainter(self)
         p.setRenderHint(QPainter.Antialiasing)
         p.setRenderHint(QPainter.TextAntialiasing)
         p.setRenderHint(QPainter.HighQualityAntialiasing)
         p.fillRect(event.rect(), Qt.transparent)
         # animated random dots background pattern
         for i in range(4096):
             x = randint(25, self.size().width() - 25)
             y = randint(25, self.size().height() - 25)
             # p.setPen(QPen(QColor(randint(9, 255), 255, 255), 1))
             p.drawPoint(x, y)
         p.setPen(QPen(Qt.white, 1))
         p.rotate(40)
         p.setFont(QFont('Ubuntu', 250))
         p.drawText(200, 99, "Nuitka")
         p.rotate(-40)
         p.setPen(Qt.NoPen)
         p.setBrush(QColor(0, 0, 0))
         p.setOpacity(0.8)
         p.drawRoundedRect(self.rect(), 9, 9)
         p.end()
コード例 #35
0
    def paintEvent(self, pe):
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        # p.setBrush(QColor(0xf0, 0xf0, 0xf0)) # color of the border
        # p.drawRect(-1, -1, 800, 800)

        pen = QPen()
        pen.setWidth(1)
        pen.setColor(QColor(0x58, 0x58,
                            0x58))  # color of the borders of the keys
        p.setPen(pen)

        p.setBrush(QColor(0x58, 0x58, 0x58))  # color of the keys

        p.setBackgroundMode(Qt.TransparentMode)

        rx = 3

        space = self.space
        w = self.usable_width
        kw = self.key_w

        def drawRow(row, sx, sy, last_end=False):
            x = sx
            y = sy
            keys = row
            rw = w - sx
            i = 0
            for k in keys:
                rect = QRectF(x, y, kw, kw)

                if i == len(keys) - 1 and last_end:
                    rect.setWidth(rw)

                p.drawRoundedRect(rect, rx, rx)

                rect.adjust(5, 1, 0, 0)

                p.setPen(QColor(0xff, 0xff, 0xff))
                p.setFont(self.lowerFont)
                p.drawText(rect, Qt.AlignLeft | Qt.AlignBottom,
                           self.regular_text(k))

                p.setPen(QColor(0x9e, 0xde, 0x00))
                p.setFont(self.upperFont)
                p.drawText(rect, Qt.AlignLeft | Qt.AlignTop,
                           self.shift_text(k))

                rw = rw - space - kw
                x = x + space + kw
                i = i + 1

                p.setPen(pen)
            return (x, rw)

        x = 6
        y = 6

        keys = self.kb["keys"]
        ext_return = self.kb["extended_return"]

        first_key_w = 0

        rows = 4
        remaining_x = [0, 0, 0, 0]
        remaining_widths = [0, 0, 0, 0]

        for i in range(0, rows):
            if first_key_w > 0:
                first_key_w = first_key_w * 1.375

                if self.kb == self.kb_105 and i == 3:
                    first_key_w = kw * 1.275

                rect = QRectF(6, y, first_key_w, kw)
                p.drawRoundedRect(rect, rx, rx)
                x = 6 + first_key_w + space
            else:
                first_key_w = kw

            x, rw = drawRow(keys[i], x, y, i == 1 and not ext_return)

            remaining_x[i] = x
            remaining_widths[i] = rw

            if i != 1 and i != 2:
                rect = QRectF(x, y, rw, kw)
                p.drawRoundedRect(rect, rx, rx)

            x = .5
            y = y + space + kw

        if ext_return:
            rx = rx * 2
            x1 = remaining_x[1]
            y1 = 6 + kw * 1 + space * 1
            w1 = remaining_widths[1]
            x2 = remaining_x[2]
            y2 = 6 + kw * 2 + space * 2

            # this is some serious crap... but it has to be so
            # maybe one day keyboards won't look like this...
            # one can only hope
            pp = QPainterPath()
            pp.moveTo(x1, y1 + rx)
            pp.arcTo(x1, y1, rx, rx, 180, -90)
            pp.lineTo(x1 + w1 - rx, y1)
            pp.arcTo(x1 + w1 - rx, y1, rx, rx, 90, -90)
            pp.lineTo(x1 + w1, y2 + kw - rx)
            pp.arcTo(x1 + w1 - rx, y2 + kw - rx, rx, rx, 0, -90)
            pp.lineTo(x2 + rx, y2 + kw)
            pp.arcTo(x2, y2 + kw - rx, rx, rx, -90, -90)
            pp.lineTo(x2, y1 + kw)
            pp.lineTo(x1 + rx, y1 + kw)
            pp.arcTo(x1, y1 + kw - rx, rx, rx, -90, -90)
            pp.closeSubpath()

            p.drawPath(pp)
        else:
            x = remaining_x[2]
            y = .5 + kw * 2 + space * 2
            rect = QRectF(x, y, remaining_widths[2], kw)
            p.drawRoundedRect(rect, rx, rx)

        QWidget.paintEvent(self, pe)
コード例 #36
0
ファイル: Keyboard.py プロジェクト: isek/ubiquity
    def paintEvent(self, pe):
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        pen = QPen()
        pen.setWidth(1)
        pen.setColor(QColor(0x8C, 0xA3, 0xB0))
        p.setPen(pen)

        p.setBrush(QColor(0xE4, 0xEC, 0xF4))

        rx = 6

        space = self.space
        w = self.usable_width
        kw = self.key_w

        def drawRow(row, sx, sy, last_end=False):
            x = sx
            y = sy
            keys = row
            rw = w - sx
            i = 0
            for k in keys:
                rect = QRectF(x, y, kw, kw)

                if i == len(keys) - 1 and last_end:
                    rect.setWidth(rw)

                p.drawRoundedRect(rect, rx, rx)
                p.setPen(Qt.black)

                rect.adjust(5, 1, 0, 0)

                p.setFont(self.lowerFont)
                p.drawText(rect, Qt.AlignLeft | Qt.AlignBottom, self.regular_text(k))

                p.setFont(self.upperFont)
                p.drawText(rect, Qt.AlignLeft | Qt.AlignTop, self.shift_text(k))

                rw = rw - space - kw
                x = x + space + kw
                i = i + 1

                p.setPen(pen)
            return (x, rw)

        x = 0.5
        y = 0.5

        keys = self.kb["keys"]
        ext_return = self.kb["extended_return"]

        first_key_w = 0

        rows = 4
        remaining_x = [0, 0, 0, 0]
        remaining_widths = [0, 0, 0, 0]

        for i in range(0, rows):
            if first_key_w > 0:
                first_key_w = first_key_w * 1.375

                if self.kb == self.kb_105 and i == 3:
                    first_key_w = kw * 1.275

                rect = QRectF(x, y, first_key_w, kw)
                p.drawRoundedRect(rect, rx, rx)
                x = x + first_key_w + space
            else:
                first_key_w = kw

            x, rw = drawRow(keys[i], x, y, i == 1 and not ext_return)

            remaining_x[i] = x
            remaining_widths[i] = rw

            if i != 1 and i != 2:
                rect = QRectF(x, y, rw, kw)
                p.drawRoundedRect(rect, rx, rx)

            x = 0.5
            y = y + space + kw

        if ext_return:
            rx = rx * 2
            x1 = remaining_x[1]
            y1 = 0.5 + kw * 1 + space * 1
            w1 = remaining_widths[1]
            x2 = remaining_x[2]
            y2 = 0.5 + kw * 2 + space * 2
            w2 = remaining_widths[2]

            # this is some serious crap... but it has to be so
            # maybe one day keyboards won't look like this...
            # one can only hope
            pp = QPainterPath()
            pp.moveTo(x1, y1 + rx)
            pp.arcTo(x1, y1, rx, rx, 180, -90)
            pp.lineTo(x1 + w1 - rx, y1)
            pp.arcTo(x1 + w1 - rx, y1, rx, rx, 90, -90)
            pp.lineTo(x1 + w1, y2 + kw - rx)
            pp.arcTo(x1 + w1 - rx, y2 + kw - rx, rx, rx, 0, -90)
            pp.lineTo(x2 + rx, y2 + kw)
            pp.arcTo(x2, y2 + kw - rx, rx, rx, -90, -90)
            pp.lineTo(x2, y1 + kw)
            pp.lineTo(x1 + rx, y1 + kw)
            pp.arcTo(x1, y1 + kw - rx, rx, rx, -90, -90)
            pp.closeSubpath()

            p.drawPath(pp)
        else:
            x = remaining_x[2]
            y = 0.5 + kw * 2 + space * 2
            rect = QRectF(x, y, remaining_widths[2], kw)
            p.drawRoundedRect(rect, rx, rx)

        QWidget.paintEvent(self, pe)
コード例 #37
0
    def paintEvent(self, event):

        page_bottom = self.edit.viewport().height()

        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(
            self.edit.textCursor().position())

        if self._firstPaintEvent is True:
            self.jumpedUP = False
            self.strings = self.edit.toPlainText().split('\n')
            self._originalTotalLine = len(self.strings)
            self.edit.jump_to_line(len(self.strings) - 2)
        elif self.jumpedUP is False:
            self.edit.jump_to_line(1)
            self.edit.verticalScrollBar().setValue(0)
            self.jumpedUP = True
            return

        pattern = self.pat if self.edit.lang == "python" else self.patNotPython

        painter = QPainter(self)
        background = resources.CUSTOM_SCHEME.get(
            'sidebar-background', resources.COLOR_SCHEME['sidebar-background'])
        foreground = resources.CUSTOM_SCHEME.get(
            'sidebar-foreground', resources.COLOR_SCHEME['sidebar-foreground'])
        pep8color = resources.CUSTOM_SCHEME.get(
            'pep8-underline', resources.COLOR_SCHEME['pep8-underline'])
        errorcolor = resources.CUSTOM_SCHEME.get(
            'error-underline', resources.COLOR_SCHEME['error-underline'])
        migrationcolor = resources.CUSTOM_SCHEME.get(
            'migration-underline',
            resources.COLOR_SCHEME['migration-underline'])
        painter.fillRect(self.rect(), QColor(background))
        '''
        if self._firstPaintEvent is True:
            block = self.edit.document().findBlock(0)
        else:
            block = self.edit.firstVisibleBlock()
        '''
        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())

        pat = re.compile('\s*#.*AppObject:')
        patAlexaAppImage = re.compile('\s*#.*AppImage:')
        patAlexaAppText = re.compile('\s*#.*AppText:')
        patAlexaLog = re.compile('\s*##.*Alexa Log')

        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + \
                viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            error = False
            if settings.CHECK_STYLE and \
               ((line_count - 1) in self._pep8Lines):
                painter.setPen(QColor(pep8color))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.FIND_ERRORS and \
                 ((line_count - 1) in self._errorsLines):
                painter.setPen(QColor(errorcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.SHOW_MIGRATION_TIPS and \
                 ((line_count - 1) in self._migrationLines):
                painter.setPen(QColor(migrationcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            else:
                painter.setPen(QColor(foreground))

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(
                    self.width() - self.foldArea -
                    font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() +
                    font_metrics.descent() - 1, str(line_count))

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        #Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(
            xofs, 0, self.foldArea, self.height(),
            QColor(
                resources.CUSTOM_SCHEME.get(
                    'fold-area', resources.COLOR_SCHEME['fold-area'])))
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(
                QColor(
                    resources.CUSTOM_SCHEME.get(
                        'fold-arrow', resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(
                QColor(
                    resources.CUSTOM_SCHEME.get(
                        'fold-arrow', resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

        if self._firstPaintEvent is True:
            block = self.edit.document().findBlock(0)
        else:
            block = self.edit.firstVisibleBlock()
        #block = self.edit.firstVisibleBlock()
        line_count = block.blockNumber()
        while block.isValid():
            #while line_count < 5000:
            line_count += 1
            position = self.edit.blockBoundingGeometry(
                block).topLeft() + viewport_offset
            #Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            #block.isVisible() and
            if block.isVisible() and pat.match(
                    block.text()) and block not in self._foldedAlexaObject:
                self._fold(line_count)
                self._foldedAlexaObject.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaAppImage.match(
                    block.text()) and block not in self._foldedAlexaImage:
                self._fold(line_count)
                self._foldedAlexaImage.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaAppText.match(
                    block.text()) and block not in self._foldedAlexaText:
                self._fold(line_count)
                self._foldedAlexaText.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaLog.match(
                    block.text()) and block not in self._foldedAlexaLog:
                self._fold(line_count)
                self._foldedAlexaLog.append(block)
                self._alexaObjectsPresent = True
            elif pattern.match(block.text()) and block.isVisible():
                if block.blockNumber() in self._foldedBlocks:
                    painter.drawPixmap(xofs, round(position.y()),
                                       self.rightArrowIcon)
                else:
                    #block.setVisible(True)
                    painter.drawPixmap(xofs, round(position.y()),
                                       self.downArrowIcon)
            #Add Bookmarks and Breakpoint
            elif block.blockNumber() in self._breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()), xofs + self.foldArea,
                    round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(xofs + 1,
                                    round(position.y()) + 6, self.foldArea - 1,
                                    self.foldArea - 1)
            elif block.blockNumber() in self._bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()), xofs + self.foldArea,
                    round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(xofs + 1,
                                        round(position.y()) + 6,
                                        self.foldArea - 2, self.foldArea - 1,
                                        3, 3)

            block = block.next()

        block = self.edit.document().findBlock(0)
        line_count = 0
        line_hidden = 0
        while block.isValid():
            line_count += 1
            if not block.isVisible():
                line_hidden += 1
            block = block.next()
        endScrollBar = line_count - line_hidden
        self.edit.verticalScrollBar().setRange(0, endScrollBar)

        if self._firstPaintEvent is True:
            self._firstPaintEvent = False

        #self.updateAlexaAppObjCoords()
        #self.updateAlexaLogCoords()
        painter.end()
        '''
        #self.edit.update()
        if self.edit.verticalScrollBar().value() != self._oldVerticalScrollbarPosition and self._alexaObjectsPresent is True:
            self._oldVerticalScrollbarPosition = self.edit.verticalScrollBar().value()
            self.updateAlexaCoords()
            self.edit.update()  # in this way we can refresh alexa icon position

        if self.edit.horizontalScrollBar().value() != self._oldHorizontalScrollbarPosition and self._alexaObjectsPresent is True:
            self._oldHorizontalScrollbarPosition = self.edit.horizontalScrollBar().value()
            self.updateAlexaCoords()
            self.edit.update()  # in this way we can refresh alexa icon position
        '''

        self.strings = self.edit.toPlainText().split('\n')
        self._currentTotalLine = len(self.strings)

        if self._currentTotalLine != self._originalTotalLine:
            self._originalTotalLine = self._currentTotalLine
            self.updateAlexaCoords()
            self.edit.update()
        '''
        if self._returnPressed is True:
            self._returnPressed = False
            self.updateAlexaAppObjCoords()
            self.updateAlexaLogCoords()
            self.edit.update()

        if self._backspacePressed is True:
            self._backspacePressed = False
            self.strings = self.edit.toPlainText().split('\n')
            self._currentTotalLine = len(self.strings)
            if self._currentTotalLine != self._originalTotalLine:
                self.updateAlexaAppObjCoords()
                self.updateAlexaLogCoords()
                self.edit.update()
        '''

        if self.edit._alexaAppObjIconsCoords != self._oldAlexaAppObjIconsCoords:
            self._oldAlexaAppObjIconsCoords = copy.deepcopy(
                self.edit._alexaAppObjIconsCoords)
            self.edit.update()

        if self.edit._alexaAppImgIconsCoords != self._oldAlexaAppImgIconsCoords:
            self._oldAlexaAppImgIconsCoords = copy.deepcopy(
                self.edit._alexaAppImgIconsCoords)
            self.edit.update()

        if self.edit._alexaAppTextIconsCoords != self._oldAlexaAppTextIconsCoords:
            self._oldAlexaAppTextIconsCoords = copy.deepcopy(
                self.edit._alexaAppTextIconsCoords)
            self.edit.update()

        if self.edit._alexaLogIconsCoords != self._oldAlexaLogIconsCoords:
            self._oldAlexaLogIconsCoords = copy.deepcopy(
                self.edit._alexaLogIconsCoords)
            self.edit.update()

        selectedLine = self.edit.textCursor().selectedText()
        textAtCursorPos = self.edit.textCursor().block().text()

        try:
            #tmp = selectedLine.index("#   AppObject")
            if (pat.match(selectedLine) or patAlexaLog.match(selectedLine) or \
            pat.match(textAtCursorPos) or patAlexaLog.match(textAtCursorPos) or \
            patAlexaAppImage.match(selectedLine) or patAlexaAppImage.match(textAtCursorPos) or\
            patAlexaAppText.match(selectedLine) or patAlexaAppText.match(textAtCursorPos)) and \
            self._keypress is True:
                self._keypress = False
                self.updateAlexaCoords()
        except:
            pass

        QWidget.paintEvent(self, event)
        '''
コード例 #38
0
ファイル: sidebar_widget.py プロジェクト: a2call/Alexa2
    def paintEvent(self, event):

        page_bottom = self.edit.viewport().height()

        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(self.edit.textCursor().position())

        if self._firstPaintEvent is True:
            self.jumpedUP = False
            self.strings = self.edit.toPlainText().split("\n")
            self._originalTotalLine = len(self.strings)
            self.edit.jump_to_line(len(self.strings) - 2)
        elif self.jumpedUP is False:
            self.edit.jump_to_line(1)
            self.edit.verticalScrollBar().setValue(0)
            self.jumpedUP = True
            return

        pattern = self.pat if self.edit.lang == "python" else self.patNotPython

        painter = QPainter(self)
        background = resources.CUSTOM_SCHEME.get("sidebar-background", resources.COLOR_SCHEME["sidebar-background"])
        foreground = resources.CUSTOM_SCHEME.get("sidebar-foreground", resources.COLOR_SCHEME["sidebar-foreground"])
        pep8color = resources.CUSTOM_SCHEME.get("pep8-underline", resources.COLOR_SCHEME["pep8-underline"])
        errorcolor = resources.CUSTOM_SCHEME.get("error-underline", resources.COLOR_SCHEME["error-underline"])
        migrationcolor = resources.CUSTOM_SCHEME.get(
            "migration-underline", resources.COLOR_SCHEME["migration-underline"]
        )
        painter.fillRect(self.rect(), QColor(background))

        """
        if self._firstPaintEvent is True:
            block = self.edit.document().findBlock(0)
        else:
            block = self.edit.firstVisibleBlock()
        """
        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())

        pat = re.compile("\s*#AppObject:")
        patAlexaAppImage = re.compile("\s*#AppImage:")
        patAlexaAppText = re.compile("\s*#AppText:")
        patAlexaLog = re.compile("\s*#Alexa Log")

        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            error = False
            if settings.CHECK_STYLE and ((line_count - 1) in self._pep8Lines):
                painter.setPen(QColor(pep8color))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.FIND_ERRORS and ((line_count - 1) in self._errorsLines):
                painter.setPen(QColor(errorcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.SHOW_MIGRATION_TIPS and ((line_count - 1) in self._migrationLines):
                painter.setPen(QColor(migrationcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            else:
                painter.setPen(QColor(foreground))

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(
                    self.width() - self.foldArea - font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() + font_metrics.descent() - 1,
                    str(line_count),
                )

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        # Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(
            xofs,
            0,
            self.foldArea,
            self.height(),
            QColor(resources.CUSTOM_SCHEME.get("fold-area", resources.COLOR_SCHEME["fold-area"])),
        )
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(
                QColor(resources.CUSTOM_SCHEME.get("fold-arrow", resources.COLOR_SCHEME["fold-arrow"]))
            )
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(
                QColor(resources.CUSTOM_SCHEME.get("fold-arrow", resources.COLOR_SCHEME["fold-arrow"]))
            )
            iconPainter.drawPolygon(polygon)

        if self._firstPaintEvent is True:
            block = self.edit.document().findBlock(0)
        else:
            block = self.edit.firstVisibleBlock()
        # block = self.edit.firstVisibleBlock()
        line_count = block.blockNumber()
        while block.isValid():
            # while line_count < 5000:
            line_count += 1
            position = self.edit.blockBoundingGeometry(block).topLeft() + viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # block.isVisible() and
            if block.isVisible() and pat.match(block.text()) and block not in self._foldedAlexaObject:
                self._fold(line_count)
                self._foldedAlexaObject.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaAppImage.match(block.text()) and block not in self._foldedAlexaImage:
                self._fold(line_count)
                self._foldedAlexaImage.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaAppText.match(block.text()) and block not in self._foldedAlexaText:
                self._fold(line_count)
                self._foldedAlexaText.append(block)
                self._alexaObjectsPresent = True
            elif block.isVisible() and patAlexaLog.match(block.text()) and block not in self._foldedAlexaLog:
                self._fold(line_count)
                self._foldedAlexaLog.append(block)
                self._alexaObjectsPresent = True
            elif pattern.match(block.text()) and block.isVisible():
                if block.blockNumber() in self._foldedBlocks:
                    painter.drawPixmap(xofs, round(position.y()), self.rightArrowIcon)
                else:
                    # block.setVisible(True)
                    painter.drawPixmap(xofs, round(position.y()), self.downArrowIcon)
            # Add Bookmarks and Breakpoint
            elif block.blockNumber() in self._breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()), xofs + self.foldArea, round(position.y()) + self.foldArea
                )
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(xofs + 1, round(position.y()) + 6, self.foldArea - 1, self.foldArea - 1)
            elif block.blockNumber() in self._bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()), xofs + self.foldArea, round(position.y()) + self.foldArea
                )
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(xofs + 1, round(position.y()) + 6, self.foldArea - 2, self.foldArea - 1, 3, 3)

            block = block.next()

        block = self.edit.document().findBlock(0)
        line_count = 0
        line_hidden = 0
        while block.isValid():
            line_count += 1
            if not block.isVisible():
                line_hidden += 1
            block = block.next()
        endScrollBar = line_count - line_hidden
        self.edit.verticalScrollBar().setRange(0, endScrollBar)

        if self._firstPaintEvent is True:
            self._firstPaintEvent = False

        # self.updateAlexaAppObjCoords()
        # self.updateAlexaLogCoords()
        painter.end()

        """
        #self.edit.update()
        if self.edit.verticalScrollBar().value() != self._oldVerticalScrollbarPosition and self._alexaObjectsPresent is True:
            self._oldVerticalScrollbarPosition = self.edit.verticalScrollBar().value()
            self.updateAlexaCoords()
            self.edit.update()  # in this way we can refresh alexa icon position

        if self.edit.horizontalScrollBar().value() != self._oldHorizontalScrollbarPosition and self._alexaObjectsPresent is True:
            self._oldHorizontalScrollbarPosition = self.edit.horizontalScrollBar().value()
            self.updateAlexaCoords()
            self.edit.update()  # in this way we can refresh alexa icon position
        """

        self.strings = self.edit.toPlainText().split("\n")
        self._currentTotalLine = len(self.strings)

        if self._currentTotalLine != self._originalTotalLine:
            self._originalTotalLine = self._currentTotalLine
            self.updateAlexaCoords()
            self.edit.update()

        """
        if self._returnPressed is True:
            self._returnPressed = False
            self.updateAlexaAppObjCoords()
            self.updateAlexaLogCoords()
            self.edit.update()

        if self._backspacePressed is True:
            self._backspacePressed = False
            self.strings = self.edit.toPlainText().split('\n')
            self._currentTotalLine = len(self.strings)
            if self._currentTotalLine != self._originalTotalLine:
                self.updateAlexaAppObjCoords()
                self.updateAlexaLogCoords()
                self.edit.update()
        """

        if self.edit._alexaAppObjIconsCoords != self._oldAlexaAppObjIconsCoords:
            self._oldAlexaAppObjIconsCoords = copy.deepcopy(self.edit._alexaAppObjIconsCoords)
            self.edit.update()

        if self.edit._alexaAppImgIconsCoords != self._oldAlexaAppImgIconsCoords:
            self._oldAlexaAppImgIconsCoords = copy.deepcopy(self.edit._alexaAppImgIconsCoords)
            self.edit.update()

        if self.edit._alexaAppTextIconsCoords != self._oldAlexaAppTextIconsCoords:
            self._oldAlexaAppTextIconsCoords = copy.deepcopy(self.edit._alexaAppTextIconsCoords)
            self.edit.update()

        if self.edit._alexaLogIconsCoords != self._oldAlexaLogIconsCoords:
            self._oldAlexaLogIconsCoords = copy.deepcopy(self.edit._alexaLogIconsCoords)
            self.edit.update()

        selectedLine = self.edit.textCursor().selectedText()
        textAtCursorPos = self.edit.textCursor().block().text()

        try:
            # tmp = selectedLine.index("#   AppObject")
            if (
                pat.match(selectedLine)
                or patAlexaLog.match(selectedLine)
                or pat.match(textAtCursorPos)
                or patAlexaLog.match(textAtCursorPos)
                or patAlexaAppImage.match(selectedLine)
                or patAlexaAppImage.match(textAtCursorPos)
                or patAlexaAppText.match(selectedLine)
                or patAlexaAppText.match(textAtCursorPos)
            ) and self._keypress is True:
                self._keypress = False
                self.updateAlexaCoords()
        except:
            pass

        QWidget.paintEvent(self, event)

        """
コード例 #39
0
ファイル: RoundWindow.py プロジェクト: esrever10/openQPA
 def paintEvent(self, event):
     p = QPainter(self)
     p.setBrush(QColor(0xf9f9f9))
     p.setPen(QColor(0x49585f))
     p.drawRoundedRect(0, 0, self.width() - 1, self.height() - 1, 3, 3)
コード例 #40
0
ファイル: main.py プロジェクト: clarkhillm/GavinTools
class CommandDialog(QtGui.QDialog):
    def __init__(self):
        super(CommandDialog, self).__init__()

        self.setFocusPolicy(Qt.TabFocus)

        self.mask = None
        self.p = None

        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

        self.textEdit = QtGui.QComboBox(self)
        # self.textEdit.addItem("")
        self.textEdit.setMinimumWidth(500)
        self.textEdit.setStyleSheet(
            """
            QComboBox {
                 border:2px groove gray;
                 border-radius:10px;
                 padding:2px 4px;
             }
             QComboBox::drop-down {
                border:0px;
                left:100px;
             }
             """)
        self.textEdit.setAutoCompletion(True)
        self.connect(self.textEdit, SIGNAL('editTextChanged(QString)'),
                     self.text_change)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.textEdit)
        self.setLayout(layout)

    def text_change(self, value):
        if State.currentHotKey == 'command' and value == 'C':
            self.textEdit.setEditText(value.rstrip('C'))

    def mask_round_corner(self):
        self.mask = QBitmap(self.size())
        self.mask.clear()
        self.p = QPainter(self.mask)
        self.p.fillRect(self.rect(), Qt.white)
        self.p.setBrush(Qt.black)
        self.p.drawRoundedRect(0, 0, self.width() - 1,
                               self.height() - 1, 20, 20)
        self.setMask(self.mask)

    def resizeEvent(self, event):
        self.mask_round_corner()

    def keyPressEvent(self, event):
        logging.debug('Q key id %s ', event.key())

        if event.key() == 16777216:
            self.hide()

        if event.key() == 16777220 or event.key() == 16777221:
            commnd = self.textEdit.currentText()
            logging.info('command %s', command)

            self.textEdit.setEditText('')

            if command == 'proxy':
                from commands import proxy

                proxy.execute()
コード例 #41
0
ファイル: sidebar_widget.py プロジェクト: pdorrell/ninja-ide
    def paintEvent(self, event):
        page_bottom = self.edit.viewport().height()
        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(
            self.edit.textCursor().position())
        pattern = self.pat if self.edit.lang == "python" else self.patNotPython

        painter = QPainter(self)
        background = resources.CUSTOM_SCHEME.get('sidebar-background',
            resources.COLOR_SCHEME['sidebar-background'])
        foreground = resources.CUSTOM_SCHEME.get('sidebar-foreground',
            resources.COLOR_SCHEME['sidebar-foreground'])
        painter.fillRect(self.rect(), QColor(background))

        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())
        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + \
                viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            painter.setPen(QColor(foreground))
            error = False
            checkers = sorted(self._neditable.registered_checkers,
                key=lambda x: x[2], reverse=True)
            for items in checkers:
                checker, color, _ = items
                if (line_count - 1) in checker.checks:
                    painter.setPen(QColor(color))
                    font = painter.font()
                    font.setItalic(True)
                    font.setUnderline(True)
                    painter.setFont(font)
                    error = True
                    break

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(self.width() - self.foldArea -
                    font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() +
                    font_metrics.descent() - 1,
                    str(line_count))

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        #Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(xofs, 0, self.foldArea, self.height(),
                QColor(resources.CUSTOM_SCHEME.get('fold-area',
                resources.COLOR_SCHEME['fold-area'])))
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            self.calculate_docstring_block_fold()

        block = self.edit.firstVisibleBlock()
        while block.isValid():
            position = self.edit.blockBoundingGeometry(
                block).topLeft() + viewport_offset
            #Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            if pattern.match(block.text()) and block.isVisible():
                can_fold = True
                if self.patComment.match(block.text()) and \
                   (block.blockNumber() in self._endDocstringBlocks):
                    can_fold = False

                if can_fold:
                    if block.blockNumber() in self.foldedBlocks:
                        painter.drawPixmap(xofs, round(position.y()),
                            self.rightArrowIcon)
                    else:
                        painter.drawPixmap(xofs, round(position.y()),
                            self.downArrowIcon)
            #Add Bookmarks and Breakpoint
            if block.blockNumber() in self.breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 1, self.foldArea - 1)
            elif block.blockNumber() in self.bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 2, self.foldArea - 1,
                    3, 3)

            block = block.next()

        painter.end()
        QWidget.paintEvent(self, event)
コード例 #42
0
    def paintEvent(self, event):
        page_bottom = self.edit.viewport().height()
        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(
            self.edit.textCursor().position())
        pattern = self.pat if self.edit.lang == "python" else self.patNotPython

        painter = QPainter(self)
        background = resources.CUSTOM_SCHEME.get('sidebar-background',
            resources.COLOR_SCHEME['sidebar-background'])
        foreground = resources.CUSTOM_SCHEME.get('sidebar-foreground',
            resources.COLOR_SCHEME['sidebar-foreground'])
        pep8color = resources.CUSTOM_SCHEME.get('pep8-underline',
            resources.COLOR_SCHEME['pep8-underline'])
        errorcolor = resources.CUSTOM_SCHEME.get('error-underline',
            resources.COLOR_SCHEME['error-underline'])
        painter.fillRect(self.rect(), QColor(background))

        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())
        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + \
                viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            error = False
            if settings.CHECK_STYLE and \
               ((line_count - 1) in self._pep8Lines):
                painter.setPen(QColor(pep8color))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.FIND_ERRORS and \
                 ((line_count - 1) in self._errorsLines):
                painter.setPen(QColor(errorcolor))
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            else:
                painter.setPen(QColor(foreground))

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(self.width() - self.foldArea -
                    font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() +
                    font_metrics.descent() - 1,
                    str(line_count))

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        #Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(xofs, 0, self.foldArea, self.height(),
                QColor(resources.CUSTOM_SCHEME.get('fold-area',
                resources.COLOR_SCHEME['fold-area'])))
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

        block = self.edit.firstVisibleBlock()
        while block.isValid():
            position = self.edit.blockBoundingGeometry(
                block).topLeft() + viewport_offset
            #Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            if pattern.match(block.text()) and block.isVisible():
                if block.blockNumber() in self._foldedBlocks:
                    painter.drawPixmap(xofs, round(position.y()),
                        self.rightArrowIcon)
                else:
                    painter.drawPixmap(xofs, round(position.y()),
                        self.downArrowIcon)
            #Add Bookmarks and Breakpoint
            elif block.blockNumber() in self._breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 1, self.foldArea - 1)
            elif block.blockNumber() in self._bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 2, self.foldArea - 1,
                    3, 3)

            block = block.next()

        painter.end()
        QWidget.paintEvent(self, event)
コード例 #43
0
 def paintEvent(self,event):
     p = QPainter(self)
     p.setBrush(QColor(0xf9f9f9))
     p.setPen(QColor(0x49585f))
     p.drawRoundedRect(0, 0, self.width()-1, self.height()-1, 3, 3)
コード例 #44
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(painter.Antialiasing)
        font = painter.font()
        font.setBold(True)
        painter.setFont(font)

        x = self.rect().x()
        y = self.rect().y()
        w = self.rect().width() - 1
        h = self.rect().height() - 1
        r = 8

        # draw a rounded style
        if self._rolloutStyle == 2:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop,
                             self.title())

            # draw the triangle
            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRoundedRect(x, y, w - 1, h - 1, r, r)

        # draw a square style
        if self._rolloutStyle == 3:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop,
                             self.title())

            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRect(x + 1, y + 1, w - 1, h - 1)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRect(x, y, w - 1, h - 1)

        # draw a Maya style
        if self._rolloutStyle == 4:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop,
                             self.title())

            painter.setRenderHint(QPainter.Antialiasing, False)

            self.__drawTriangle(painter, x, y)

            # draw the borders - top
            headerHeight = 20

            headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
            headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)

            # Highlight
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.4)
            painter.setPen(pen)

            painter.drawRect(headerRect)
            painter.fillRect(headerRect, QColor(255, 255, 255, 18))

            # Shadow
            pen.setColor(self.palette().color(QPalette.Dark))
            painter.setPen(pen)
            painter.drawRect(headerRectShadow)

            if not self.isCollapsed():
                # draw the lover border
                pen = QPen(self.palette().color(QPalette.Dark))
                pen.setWidthF(0.8)
                painter.setPen(pen)

                offSet = headerHeight + 3
                bodyRect = QRect(x, y + offSet, w, h - offSet)
                bodyRectShadow = QRect(x + 1, y + offSet, w + 1,
                                       h - offSet + 1)
                painter.drawRect(bodyRect)

                pen.setColor(self.palette().color(QPalette.Light))
                pen.setWidthF(0.4)
                painter.setPen(pen)

                painter.drawRect(bodyRectShadow)

        # draw a boxed style
        elif self._rolloutStyle == 1:
            if self.isCollapsed():
                arect = QRect(x + 1, y + 9, w - 1, 4)
                brect = QRect(x, y + 8, w - 1, 4)
                text = '+'
            else:
                arect = QRect(x + 1, y + 9, w - 1, h - 9)
                brect = QRect(x, y + 8, w - 1, h - 9)
                text = '-'

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRect(arect)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRect(brect)

            painter.setRenderHint(painter.Antialiasing, False)
            painter.setBrush(self.palette().color(QPalette.Window).darker(120))
            painter.drawRect(x + 10, y + 1, w - 20, 16)
            painter.drawText(x + 16, y + 1, w - 32, 16,
                             Qt.AlignLeft | Qt.AlignVCenter, text)
            painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter,
                             self.title())

        if self.dragDropMode():
            rect = self.dragDropRect()

            # draw the lines
            l = rect.left()
            r = rect.right()
            cy = rect.center().y()

            for y in (cy - 3, cy, cy + 3):
                painter.drawLine(l, y, r, y)

        painter.end()
コード例 #45
0
ファイル: accordian_window.py プロジェクト: yunpoyue/Python
    def paintEvent( self, event ):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(painter.Antialiasing)
        font = painter.font()
        font.setBold(True)
        painter.setFont(font)

        x = self.rect().x()
        y = self.rect().y()
        w = self.rect().width() - 1
        h = self.rect().height() - 1
        r = 8

        # draw a rounded style
        if self._rolloutStyle == 2:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            # draw the triangle
            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRoundedRect(x, y, w - 1, h - 1, r, r)

        # draw a square style
        if self._rolloutStyle == 3:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            self.__drawTriangle(painter, x, y)

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRect(x + 1, y + 1, w - 1, h - 1)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRect(x, y, w - 1, h - 1)

        # draw a Maya style
        if self._rolloutStyle == 4:
            # draw the text
            painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())

            painter.setRenderHint(QPainter.Antialiasing, False)

            self.__drawTriangle(painter, x, y)

            # draw the borders - top
            headerHeight = 20

            headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
            headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)

            # Highlight
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.4)
            painter.setPen(pen)

            painter.drawRect(headerRect)
            painter.fillRect(headerRect, QColor(255, 255, 255, 18))

            # Shadow
            pen.setColor(self.palette().color(QPalette.Dark))
            painter.setPen(pen)
            painter.drawRect(headerRectShadow)

            if not self.isCollapsed():
                # draw the lover border
                pen = QPen(self.palette().color(QPalette.Dark))
                pen.setWidthF(0.8)
                painter.setPen(pen)

                offSet = headerHeight + 3
                bodyRect = QRect(x, y + offSet, w, h - offSet)
                bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
                painter.drawRect(bodyRect)

                pen.setColor(self.palette().color(QPalette.Light))
                pen.setWidthF(0.4)
                painter.setPen(pen)

                painter.drawRect(bodyRectShadow)

        # draw a boxed style
        elif self._rolloutStyle == 1:
            if self.isCollapsed():
                arect = QRect(x + 1, y + 9, w - 1, 4)
                brect = QRect(x, y + 8, w - 1, 4)
                text = '+'
            else:
                arect = QRect(x + 1, y + 9, w - 1, h - 9)
                brect = QRect(x, y + 8, w - 1, h - 9)
                text = '-'

            # draw the borders
            pen = QPen(self.palette().color(QPalette.Light))
            pen.setWidthF(0.6)
            painter.setPen(pen)

            painter.drawRect(arect)

            pen.setColor(self.palette().color(QPalette.Shadow))
            painter.setPen(pen)

            painter.drawRect(brect)

            painter.setRenderHint(painter.Antialiasing, False)
            painter.setBrush(self.palette().color(QPalette.Window).darker(120))
            painter.drawRect(x + 10, y + 1, w - 20, 16)
            painter.drawText(x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text)
            painter.drawText(x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title())

        if self.dragDropMode():
            rect = self.dragDropRect()

            # draw the lines
            l = rect.left()
            r = rect.right()
            cy = rect.center().y()

            for y in (cy - 3, cy, cy + 3):
                painter.drawLine(l, y, r, y)

        painter.end()
コード例 #46
0
ファイル: collapsable_groupbox.py プロジェクト: skarone/PipeL
	def paintEvent( self, event ):
		from PyQt4.QtCore 	import Qt
		from PyQt4.QtGui	import QPainter, QPainterPath, QPalette, QPixmap, QPen

		painter = QPainter()
		painter.begin( self )
		painter.setRenderHint( painter.Antialiasing )

		x = self.rect().x()
		y = self.rect().y()
		w = self.rect().width() - 1
		h = self.rect().height() - 1
		r = 8

		# draw a rounded style
		if ( self._rolloutStyle == 2 ):

			# draw the text
			painter.drawText( x + 22, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title() )

			# draw the triangle
			pixmap = self._pixmap
			if ( not self.isCollapsed() ):
				from PyQt4.QtGui import QMatrix
				pixmap = pixmap.transformed( QMatrix().rotate(90) )

			painter.drawPixmap( x + 7, y + 4, pixmap )

			# draw the borders
			pen = QPen( self.palette().color( QPalette.Light ) )
			pen.setWidthF( 0.6 )
			painter.setPen( pen )

			painter.drawRoundedRect( x + 1, y + 1, w - 1, h - 1, r, r )

			pen.setColor( self.palette().color( QPalette.Shadow ) )
			painter.setPen( pen )

			painter.drawRoundedRect( x, y, w - 1, h - 1, r, r )

		# draw a boxed style
		elif ( self._rolloutStyle == 1 ):
			from PyQt4.QtCore import QRect
			if ( self.isCollapsed() ):
				arect 	= QRect( x + 1, y + 9, w - 1, 4 )
				brect 	= QRect( x, y + 8, w - 1, 4 )
				text 	= '+'
			else:
				arect	= QRect( x + 1, y + 9, w - 1, h - 9 )
				brect 	= QRect( x, y + 8, w - 1, h - 9 )
				text	= '-'

			# draw the borders
			pen = QPen( self.palette().color( QPalette.Light ) )
			pen.setWidthF( 0.6 )
			painter.setPen( pen )

			painter.drawRect( arect )

			pen.setColor( self.palette().color( QPalette.Shadow ) )
			painter.setPen( pen )

			painter.drawRect( brect )

			painter.setRenderHint( painter.Antialiasing, False )
			painter.setBrush( self.palette().color( QPalette.Window ).darker( 120 ) )
			painter.drawRect( x + 10, y + 1, w - 20, 16 )
			painter.drawText( x + 16, y + 1, w - 32, 16, Qt.AlignLeft | Qt.AlignVCenter, text )
			painter.drawText( x + 10, y + 1, w - 20, 16, Qt.AlignCenter, self.title() )

		if ( self.dragDropMode() ):
			rect 	= self.dragDropRect()

			# draw the lines
			l		= rect.left()
			r		= rect.right()
			cy		= rect.center().y()

			for y in (cy - 3, cy, cy + 3):
				painter.drawLine( l, y, r, y )

		painter.end()
コード例 #47
0
ファイル: sidebar_widget.py プロジェクト: b250783/ninja-ide
    def paintEvent(self, event):
        page_bottom = self.edit.viewport().height()
        font_metrics = QFontMetrics(self.edit.document().defaultFont())
        current_block = self.edit.document().findBlock(
            self.edit.textCursor().position())

        painter = QPainter(self)
        painter.fillRect(self.rect(), Qt.lightGray)

        block = self.edit.firstVisibleBlock()
        viewport_offset = self.edit.contentOffset()
        line_count = block.blockNumber()
        painter.setFont(self.edit.document().defaultFont())
        while block.isValid():
            line_count += 1
            # The top left position of the block in the document
            position = self.edit.blockBoundingGeometry(block).topLeft() + \
                viewport_offset
            # Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            # Set the Painter Pen depending on special lines
            error = False
            if settings.CHECK_STYLE and \
               ((line_count - 1) in self._pep8Lines):
                painter.setPen(Qt.darkYellow)
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            elif settings.FIND_ERRORS and \
                 ((line_count - 1) in self._errorsLines):
                painter.setPen(Qt.red)
                font = painter.font()
                font.setItalic(True)
                font.setUnderline(True)
                painter.setFont(font)
                error = True
            else:
                painter.setPen(Qt.black)

            # We want the line number for the selected line to be bold.
            bold = False
            if block == current_block:
                bold = True
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)

            # Draw the line number right justified at the y position of the
            # line. 3 is a magic padding number. drawText(x, y, text).
            if block.isVisible():
                painter.drawText(self.width() - self.foldArea - \
                    font_metrics.width(str(line_count)) - 3,
                    round(position.y()) + font_metrics.ascent() + \
                    font_metrics.descent() - 1,
                    str(line_count))

            # Remove the bold style if it was set previously.
            if bold:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
            if error:
                font = painter.font()
                font.setItalic(False)
                font.setUnderline(False)
                painter.setFont(font)

            block = block.next()

        self.highest_line = line_count

        #Code Folding
        xofs = self.width() - self.foldArea
        painter.fillRect(xofs, 0, self.foldArea, self.height(),
                QColor(resources.CUSTOM_SCHEME.get('fold-area',
                resources.COLOR_SCHEME['fold-area'])))
        if self.foldArea != self.rightArrowIcon.width():
            polygon = QPolygonF()

            self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.rightArrowIcon.fill(Qt.transparent)
            self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
            self.downArrowIcon.fill(Qt.transparent)

            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
            polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
            polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
            iconPainter = QPainter(self.rightArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

            polygon.clear()
            polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
            polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
            iconPainter = QPainter(self.downArrowIcon)
            iconPainter.setRenderHint(QPainter.Antialiasing)
            iconPainter.setPen(Qt.NoPen)
            iconPainter.setBrush(QColor(
                resources.CUSTOM_SCHEME.get('fold-arrow',
                resources.COLOR_SCHEME['fold-arrow'])))
            iconPainter.drawPolygon(polygon)

        block = self.edit.firstVisibleBlock()
        while block.isValid():
            position = self.edit.blockBoundingGeometry(
                block).topLeft() + viewport_offset
            #Check if the position of the block is outside of the visible area
            if position.y() > page_bottom:
                break

            if self.pat.match(unicode(block.text())) and block.isVisible():
                if block.blockNumber() in self._foldedBlocks:
                    painter.drawPixmap(xofs, round(position.y()),
                        self.rightArrowIcon)
                else:
                    painter.drawPixmap(xofs, round(position.y()),
                        self.downArrowIcon)
            #Add Bookmarks and Breakpoint
            elif block.blockNumber() in self._breakpoints:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(255, 11, 11))
                linear_gradient.setColorAt(1, QColor(147, 9, 9))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawEllipse(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 1, self.foldArea - 1)
            elif block.blockNumber() in self._bookmarks:
                linear_gradient = QLinearGradient(
                    xofs, round(position.y()),
                    xofs + self.foldArea, round(position.y()) + self.foldArea)
                linear_gradient.setColorAt(0, QColor(13, 62, 243))
                linear_gradient.setColorAt(1, QColor(5, 27, 106))
                painter.setRenderHints(QPainter.Antialiasing, True)
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(linear_gradient))
                painter.drawRoundedRect(
                    xofs + 1,
                    round(position.y()) + 6,
                    self.foldArea - 2, self.foldArea - 1,
                    3, 3)

            block = block.next()

        painter.end()
        QWidget.paintEvent(self, event)