Esempio n. 1
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     pen = painter.pen()
     pen.setColor(QColor('darkgrey'))
     painter.setPen(pen)
     w = self.width
     h = self.height
     painter.drawLine(w//2, h*3//4, w*13//14, h*3//12)
Esempio n. 2
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     pen = painter.pen()
     pen.setColor(QColor('darkgrey'))
     painter.setPen(pen)
     w = self.width
     h = self.height
     x = int(w * 0.71)
     painter.drawLine(x, int(h * 0.48), x, int(h * 0.7))
Esempio n. 3
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     pen = painter.pen()
     pen.setColor(QColor('darkgrey'))
     painter.setPen(pen)
     w = self.width
     h = self.height
     length = int(w * 0.2)
     x = int(w * 0.4)
     y = int(h * 0.58)
     painter.drawLine(x, y, x + length, y - length)
Esempio n. 4
0
 def draw(self, painter: QPainter):
     super().draw(painter)
     pen = painter.pen()
     pen.setColor(QColor('darkgrey'))
     painter.setPen(pen)
     w = self.width
     h = self.height
     size = int(w * 0.06)
     x = int(w * 0.49)
     y = int(h * 0.47)
     painter.drawLine(x, y - size, x, y + size)
     painter.drawLine(x - size, y, x + size, y)
     x = int(w * 0.6)
     y = int(h * 0.37)
     painter.drawLine(x, y - size, x, y + size)
     painter.drawLine(x - size, y, x + size, y)
Esempio n. 5
0
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              index: QModelIndex) -> None:
        itemOption = QStyleOptionViewItem(option)

        # disable focus outline
        if itemOption.state & QStyle.State_HasFocus:
            itemOption.state ^= QStyle.State_HasFocus
        # hover whole row
        if index.row() == option.styleObject.hoverIndexRow:
            itemOption.state |= QStyle.State_MouseOver

        super().paint(painter, itemOption, index)

        # draw lines around numeric columns
        if index.column() in (5, 12):
            oldpen = painter.pen()
            painter.setPen(self.linepen)
            painter.drawLine(itemOption.rect.topRight() + QPoint(0, 0),
                             itemOption.rect.bottomRight() + QPoint(0, 0))
            painter.setPen(oldpen)
Esempio n. 6
0
File: Radio.py Progetto: skpzk/Sharm
    def paintEvent(self, ev):
        # print("Radio paintEventCalled")
        # print("size =", self.paintSize)

        opt = QStyleOption()
        opt.initFrom(self)
        painter = QPainter(self)

        # print("minimum size : ", self.minimumSize())
        # print("radio: hasHforW : ", self.hasHeightForWidth())
        # print("radio: size : ", self.size())
        # print("radio : minimumSizeHint() :", self.minimumSizeHint())

        # s = self.style()

        # s.drawPrimitive(QStyle.PE_Widget, opt, painter, self)

        # self.computeSize()
        size = self.paintSize
        # size = np.min([1/8 * self.width(), self.height()/4])

        fontsizefactor = self.fontsizefactor

        linewidth = 1

        painter.setRenderHint(QPainter.Antialiasing)

        pointColor = QColor(painter.pen().color())
        bgColor = QColor(painter.background().color())
        # bgColor = QColor("white")

        painter.setBrush(QBrush(QColor("transparent")))
        painter.setPen(QPen(QColor(pointColor), linewidth))
        # painter.setBackgroundMode(Qt.TransparentMode)

        center = QtCore.QPoint(int(self.width() / 2), int(self.height() / 2))
        self.center = center
        self.radius = size

        painter.drawEllipse(center, size, size)

        margin = .4 * size

        # painter.drawRect(text_rect)
        # self.text()

        fontsize = size * fontsizefactor
        # self.fontsize = fontsize

        f = painter.font()
        f.setPointSizeF(fontsize)
        painter.setFont(f)

        text_rect = QRectF(center.x() + size + margin,
                           center.y() - fontsize, 100, 2 * fontsize)
        # painter.drawRect(text_rect)
        painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter,
                         self.text())

        self.textRect = text_rect

        if self.isChecked():
            painter.setBrush(QBrush(QColor(int(colors[self._ID], 0))))
            # painter.setPen(QPen(Qt.NoPen))
            painter.drawEllipse(center, size, size)

        # painter.drawLine(QtCore.QPointF(self.width()/2, 0), QtCore.QPointF(self.width()/2, self.height()))

        pass
Esempio n. 7
0
    def paintEvent(self, pe) -> None:
        if not self.inhibit_paint:

            extent = 1.5 * np.pi
            offset = 1.25 * np.pi

            painter = QPainter(self)

            # So that we can use the background color
            painter.setBackgroundMode(Qt.OpaqueMode)

            # Smooth out the circle
            painter.setRenderHint(QPainter.Antialiasing)

            # Use background color
            bgColor = painter.background().color()
            painter.setBrush(painter.background())
            if self._text not in implementedKnobs:
                painter.setBrush(QtGui.QBrush(QtGui.QColor(int("0xcccccc",
                                                               0))))

            # Store color from stylesheet, pen will be overridden
            pointColor = QColor(painter.pen().color())

            # print(QDial.width(self), QDial.height(self))

            # draw widget borders
            pen = QPen(QColor(self._ringColor), 1)
            pen.setCapStyle(Qt.SquareCap)
            painter.setPen(pen)
            # uncomment the following line to draw outer rect
            # painter.drawRect(0, 0, np.floor(QDial.width(self)), QDial.height(self))

            # No border
            painter.setPen(QPen(Qt.NoPen))

            # the heignt of the widget is 2*radius + 2*fontsize1 + 2*fontsize2
            # where fontsize1 = .4radius and fontsize2 = .9*.4*radius
            # so QDial.height = radius * (2+.4*2+.4*.9*2)
            #

            fontsize1factor = .4
            fontsize2reduction = .9
            fontsize2factor = fontsize1factor * fontsize2reduction

            center_x = QDial.width(self) / 2.0
            center_y = QDial.height(self) / 2.0

            if not self._hasFixedSize:
                if not self._hasFixedFontSize:
                    radius = np.min(
                        (QDial.width(self) / 2. - self._knobMargin,
                         QDial.height(self) /
                         (2. + 2 * fontsize1factor + 2 * fontsize2factor) -
                         self._knobMargin))
                    radius = np.max((radius, 1))
                    # print("Radius = ", radius, ", height = ", QDial.height(self), ", width = ", QDial.width(self))
                    center_y = center_y - radius * (fontsize1factor +
                                                    fontsize2factor)
                else:
                    radius = np.min(
                        (QDial.width(self) / 2. - self._knobMargin,
                         (QDial.height(self) - 4 * self._fixedFontSize) / 2. -
                         self._knobMargin))
                    radius = np.max((radius, 1))
                    center_y = center_y - (self._fixedFontSize *
                                           (1 + fontsize2reduction))
            else:
                radius = self._fixedSize / 2.
                radius = np.max((radius, 1))
                center_y = center_y - radius * (fontsize1factor +
                                                fontsize2factor)

            self.radius = radius

            # Draw arc
            rectangle = QtCore.QRectF(center_x - radius, center_y - radius,
                                      2 * radius, 2 * radius)
            """The startAngle and spanAngle must be specified in 1/16th of a degree, 
			i.e. a full circle equals 5760 (16 * 360). 
			Positive values for the angles mean counter-clockwise 
			while negative values mean the clockwise direction. 
			Zero degrees is at the 3 o'clock position."""

            linewidth = radius / 30. * 2

            # linewidth = 1
            pen = QPen(QColor(self._ringColor), linewidth)
            pen.setCapStyle(Qt.RoundCap)
            # pen.setCapStyle(Qt.FlatCap)

            painter.setPen(pen)

            # adapt to linewidth to make it more pleasant to the eye
            capRadius = linewidth / 4
            angleCap = np.arcsin(capRadius / radius)

            start_deg = (90 - np.rad2deg(extent / 2)) + np.rad2deg(angleCap)
            start_16deg = start_deg * 16

            extent_deg = np.rad2deg(extent) - 2 * np.rad2deg(angleCap)
            extent_16deg = extent_deg * 16

            painter.drawArc(rectangle, start_16deg, extent_16deg)

            #draw inner circle
            pen = QPen(QColor(pointColor), linewidth)
            pen.setCapStyle(Qt.RoundCap)

            painter.setPen(pen)
            painter.setBrush(QtGui.QColor(bgColor))

            radius_inner = 15. / 20. * radius
            painter.drawEllipse(QtCore.QPointF(center_x, center_y),
                                radius_inner, radius_inner)

            self.center = QtCore.QPointF(center_x, center_y)
            """
			# Get ratio between current value and maximum to calculate angle
			if (param != NULL):
				if (param->value != this->value()) 
					param->setValue(this->value())
			"""
            ratio = (QDial.value(self) - QDial.minimum(self)) / (
                QDial.maximum(self) - QDial.minimum(self))

            # The maximum amount of degrees is 270, offset by 225
            angle = ratio * extent - offset

            # Draw the indicator
            painter.setBrush(QBrush(pointColor))

            a_y = center_y + np.sin(angle) * (radius - .1)
            a_x = center_x + np.cos(angle) * (radius - .1)

            pen = QPen(pointColor, linewidth)
            pen.setCapStyle(Qt.RoundCap)
            painter.setPen(pen)

            painter.drawLine(a_x, a_y, np.round(center_x), center_y)

            if not self._hasFixedFontSize:
                fontsize1 = radius * fontsize1factor
                if self.sizeType == 1 and fontsize1 != Knob.fontsize1:
                    Knob.fontsize1 = fontsize1
                else:
                    fontsize1 = Knob.fontsize1
                fontsize2 = fontsize1 * fontsize2reduction
            else:
                fontsize1 = self._fixedFontSize
                fontsize2 = fontsize1 * fontsize2reduction

            self.fontsize1 = fontsize1

            textRect_ = QtCore.QRectF(0, center_y + radius, QDial.width(self),
                                      2 * fontsize1)

            if self.coloredTitle:
                painter.setPen(QColor(int(titleColor, 0)))

            f = painter.font()
            f.setPointSizeF(fontsize1)
            painter.setFont(f)
            # painter.drawRect(textRect_)
            painter.drawText(textRect_, Qt.AlignHCenter | Qt.AlignTop,
                             self._text)
            # painter.drawText(textRect_, Qt.AlignHCenter | Qt.AlignTop, str(fontsize1))

            textRect_ = QtCore.QRectF(0, center_y + radius + fontsize1 * 2,
                                      QDial.width(self), 2 * fontsize2)

            if self.hasFocus():
                painter.setPen(QtGui.QColor("red"))

            f.setPointSizeF(fontsize2)
            painter.setFont(f)
            # painter.drawRect(textRect_)
            painter.drawText(textRect_, Qt.AlignHCenter | Qt.AlignTop,
                             str(QDial.value(self)))

            painter.end()
Esempio n. 8
0
    def paintEvent(self, pe) -> None:

        mainradius, fontsizefactor, center_x, center_y_pp, width = self.computeCenter(
        )

        painter = QPainter(self)
        # So that we can use the background color
        painter.setBackgroundMode(Qt.OpaqueMode)
        # Smooth out the circle
        painter.setRenderHint(QPainter.Antialiasing)
        # Use background color
        textBgColor = QColor(painter.background().color())
        # print("bgcolor = ", bgColor)
        bgColor = QColor("transparent")
        pointColor = QColor(painter.pen().color())

        self.pointColor = pointColor
        self.bgColor = textBgColor

        alpha = 150

        if self.parent().displayPp == 'all' or self.parent(
        ).displayPp == self.io:
            pointColor.setAlpha(255)
        else:
            pointColor.setAlpha(alpha)

        # draw text
        if not self._hasFixedFontSize:
            fontsize = mainradius * fontsizefactor
        else:
            fontsize = self._fixedFontSize
        self.fontsize = fontsize
        textRect_ = QtCore.QRectF(0, center_y_pp - mainradius - 2 * fontsize,
                                  width, 2 * fontsize)
        f = painter.font()
        f.setPointSizeF(fontsize)

        # self._io = 'in'
        if self.io == 'out':
            fm = QFontMetrics(f).boundingRect(self._text)
            # print("fm = ", fm)
            painter.setBrush(pointColor)
            painter.setPen(QPen(pointColor))
            painter.drawRect(
                QtCore.QRectF(center_x - fm.width() / 2,
                              center_y_pp - mainradius - 2 * fontsize,
                              fm.width(), fm.height()))
            painter.setPen(QPen(textBgColor))

        painter.setFont(f)
        painter.setBackgroundMode(Qt.TransparentMode)
        painter.drawText(textRect_, Qt.AlignHCenter | Qt.AlignTop, self._text)

        # draw hexagon
        painter.setBrush(bgColor)
        painter.setPen(pointColor)
        painter.drawPolygon(
            self.createPoly(6, mainradius, center_x, center_y_pp))

        # draw outer circle
        radius_outer = mainradius * .8
        if self.title not in implementedPatchPoints:
            painter.setBrush(QtGui.QBrush(QtGui.QColor(int("0x999999", 0))))
        painter.drawEllipse(QtCore.QPointF(center_x, center_y_pp),
                            radius_outer, radius_outer)

        # draw inner circle
        radius_inner = mainradius * .5
        # painter.setBrush(QBrush(pointColor))
        painter.setBrush(QColor(self._ppColor))
        painter.drawEllipse(QtCore.QPointF(center_x, center_y_pp),
                            radius_inner, radius_inner)