def paint(self, painter: QPainter): brush = QBrush(QColor("#007430")) painter.setBrush(brush) painter.setPen(Qt.NoPen) painter.setRenderHint(QPainter.Antialiasing) itemSize = self.size() painter.drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10) if self.rightAligned: points = [ QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0), QPointF(itemSize.width() - 20.0, itemSize.height()), QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0), ] else: points = [ QPointF(10.0, itemSize.height() - 10.0), QPointF(20.0, itemSize.height()), QPointF(30.0, itemSize.height() - 10.0), ] painter.drawConvexPolygon(points)
def paintEvent(self, event): rect = QRect(10, 20, 80, 60) path = QPainterPath() path.moveTo(20, 80) path.lineTo(20, 30) path.cubicTo(80, 0, 50, 50, 80, 80) startAngle = 30 * 16 arcLength = 120 * 16 painter = QPainter(self) painter.setPen(self.pen) painter.setBrush(self.brush) if self.antialiased: painter.setRenderHint(QPainter.Antialiasing) for x in range(0, self.width(), 100): for y in range(0, self.height(), 100): painter.save() painter.translate(x, y) if self.transformed: painter.translate(50, 50) painter.rotate(60.0) painter.scale(0.6, 0.9) painter.translate(-50, -50) if self.shape == RenderArea.Line: painter.drawLine(rect.bottomLeft(), rect.topRight()) elif self.shape == RenderArea.Points: painter.drawPoints(RenderArea.points) elif self.shape == RenderArea.Polyline: painter.drawPolyline(RenderArea.points) elif self.shape == RenderArea.Polygon: painter.drawPolygon(RenderArea.points) elif self.shape == RenderArea.Rect: painter.drawRect(rect) elif self.shape == RenderArea.RoundedRect: painter.drawRoundedRect(rect, 25, 25, Qt.RelativeSize) elif self.shape == RenderArea.Ellipse: painter.drawEllipse(rect) elif self.shape == RenderArea.Arc: painter.drawArc(rect, startAngle, arcLength) elif self.shape == RenderArea.Chord: painter.drawChord(rect, startAngle, arcLength) elif self.shape == RenderArea.Pie: painter.drawPie(rect, startAngle, arcLength) elif self.shape == RenderArea.Path: painter.drawPath(path) elif self.shape == RenderArea.Text: painter.drawText(rect, Qt.AlignCenter, "PySide 2\nQt %s" % qVersion()) elif self.shape == RenderArea.Pixmap: painter.drawPixmap(10, 10, self.pixmap) painter.restore() painter.setPen(self.palette().dark().color()) painter.setBrush(Qt.NoBrush) painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1))
def paintEvent(self, event): size = self.size() # draw background painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(QColor(255, 255, 255, 255)) painter.setBrush(self.fill_color) painter.drawRect(0, 0, size.width(), size.height()) painter.end()
def create_icon(player_colour: QColor) -> QPixmap: size = 200 icon = QPixmap(size, size) icon.fill(Qt.transparent) painter = QPainter(icon) try: painter.setBrush(player_colour) pen = QPen() pen.setWidth(3) painter.setPen(pen) painter.drawEllipse(1, 1, size - 2, size - 2) finally: painter.end() return icon
def paintEvent(self, event): super(QtBubbleLabel, self).paintEvent(event) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # 抗锯齿 rectPath = QPainterPath() # 圆角矩形 height = self.height() - 8 # 往上偏移8 rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5) x = self.width() / 5 * 4 # 边框画笔 painter.setPen( QPen(self.BorderColor, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) # 背景画刷 painter.setBrush(self.BackgroundColor) # 绘制形状 painter.drawPath(rectPath)
def shape_to_pixelmap(item_type, pen, brush, shape) -> QPixmap: pixmap = QPixmap(50, 50) pixmap.fill(Qt.transparent) painter = QPainter(pixmap) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(pen) painter.setBrush(brush) if item_type == QGraphicsRectItem.type(QGraphicsRectItem()): painter.drawRect(QRect(10, 15, 30, 20)) elif item_type == QGraphicsEllipseItem.type(QGraphicsEllipseItem()): painter.drawEllipse(QRect(10, 10, 30, 30)) elif item_type == QGraphicsPolygonItem.type(QGraphicsPolygonItem()): if shape.polygon().size() == 3: painter.drawPolygon(QPolygon([QPoint(10, 40), QPoint(40, 40), QPoint(25, 10)])) else: painter.drawPolygon(QPolygon([QPoint(12, 40), QPoint(23, 36), QPoint(37, 24), QPoint(23, 12), QPoint(7, 16)])) elif item_type == QGraphicsLineItem.type(QGraphicsLineItem()): painter.drawLine(QLine(10, 40, 40, 10)) return pixmap
def paintEvent(self, event): painter = QPainter(self) painter.fillRect(self.rect(), Qt.black) if self.pixmap.isNull(): painter.setPen(Qt.white) painter.drawText(self.rect(), Qt.AlignCenter, "Rendering initial image, please wait...") return if self.curScale == self.pixmapScale: painter.drawPixmap(self.pixmapOffset, self.pixmap) else: scaleFactor = self.pixmapScale / self.curScale newWidth = int(self.pixmap.width() * scaleFactor) newHeight = int(self.pixmap.height() * scaleFactor) newX = self.pixmapOffset.x() + (self.pixmap.width() - newWidth) / 2 newY = self.pixmapOffset.y() + (self.pixmap.height() - newHeight) / 2 painter.save() painter.translate(newX, newY) painter.scale(scaleFactor, scaleFactor) exposed, _ = painter.transform().inverted() exposed = exposed.mapRect(self.rect()).adjusted(-1, -1, 1, 1) painter.drawPixmap(exposed, self.pixmap, exposed) painter.restore() text = "Use mouse wheel or the '+' and '-' keys to zoom. Press and " \ "hold left mouse button to scroll." metrics = painter.fontMetrics() textWidth = metrics.horizontalAdvance(text) painter.setPen(Qt.NoPen) painter.setBrush(QColor(0, 0, 0, 127)) painter.drawRect((self.width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5) painter.setPen(Qt.white) painter.drawText((self.width() - textWidth) / 2, metrics.leading() + metrics.ascent(), text)
def drawValue(self, p: QPainter, baseRect: QRectF, value: float, delta: float): if value == self.m_min: return if self.m_barStyle == self.BarStyle.EXPAND: p.setBrush(self.palette().highlight()) p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth)) radius = (baseRect.height() / 2) / delta p.drawEllipse(baseRect.center(), radius, radius) return elif self.m_barStyle == self.BarStyle.LINE: p.setPen( QPen(self.palette().highlight().color(), self.m_dataPenWidth)) p.setBrush(Qt.NoBrush) if value == self.m_max: p.drawEllipse( baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2)) else: arcLength = 360 / delta p.drawArc( baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2), int(self.m_nullPosition * 16), int(-arcLength * 16)) return dataPath = QPainterPath() dataPath.setFillRule(Qt.WindingFill) if value == self.m_max: dataPath.addEllipse(baseRect) else: arcLength = 360 / delta dataPath.moveTo(baseRect.center()) dataPath.arcTo(baseRect, self.m_nullPosition, -arcLength) dataPath.lineTo(baseRect.center()) p.setBrush(self.palette().highlight()) p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth)) p.drawPath(dataPath)
def drawBase(self, p: QPainter, baseRect: QRectF): if self.m_barStyle == self.BarStyle.DONUT: p.setPen( QPen(self.palette().shadow().color(), self.m_outlinePenWidth)) p.setBrush(self.palette().base()) p.drawEllipse(baseRect) elif self.m_barStyle == self.BarStyle.LINE: p.setPen( QPen(self.palette().base().color(), self.m_outlinePenWidth)) p.setBrush(Qt.NoBrush) p.drawEllipse( baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2)) elif self.m_barStyle in (self.BarStyle.PIE, self.BarStyle.EXPAND): p.setPen( QPen(self.palette().base().color(), self.m_outlinePenWidth)) p.setBrush(self.palette().base()) p.drawEllipse(baseRect)
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
class ScreenSelection(QtWidgets.QGroupBox): def __init__(self, parent: DisplayCalibration): QtWidgets.QGroupBox.__init__(self, 'Fullscreen selection (double click)') self.main = parent self.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Expanding) self.painter = QPainter() def mouseDoubleClickEvent(self, ev, *args, **kwargs): for screen_id, screen_coords in enumerate( self._get_widget_screen_coords()): rect = QtCore.QRectF(*screen_coords) if not rect.contains(QtCore.QPoint(ev.pos().x(), ev.pos().y())): continue print(f'Set display to fullscreen on screen {screen_id}') screen = access.application.screens()[screen_id] px_ratio = screen.devicePixelRatio() self.main.global_settings.screen_id.set_value(screen_id) self.main.global_settings.win_x_pos.set_value( screen.geometry().x()) self.main.global_settings.win_y_pos.set_value( screen.geometry().y()) self.main.global_settings.win_width.set_value( int(screen.geometry().width() * px_ratio)) self.main.global_settings.win_height.set_value( int(screen.geometry().height() * px_ratio)) access.application.processEvents() @staticmethod def _get_norm_screen_coords() -> np.ndarray: # Get connected screens avail_screens = access.application.screens() # Calculate total display area bounding box area = [[ s.geometry().width() * s.devicePixelRatio(), s.geometry().height() * s.devicePixelRatio() ] for s in avail_screens] area = np.sum(area, axis=0) xmin = np.min([s.geometry().x() for s in avail_screens]) ymin = np.min([s.geometry().y() for s in avail_screens]) # Define normalization functions xnorm = lambda x: (x - xmin) / area[0] ynorm = lambda y: (y - ymin) / area[1] # Add screen dimensions screens = [] for s in avail_screens: g = s.geometry() screens.append([ xnorm(g.x() * s.devicePixelRatio()), # x ynorm(g.y() * s.devicePixelRatio()), # y xnorm(g.width() * s.devicePixelRatio()), # width ynorm(g.height() * s.devicePixelRatio()) ]) # height return np.array(screens) def _get_widget_screen_coords(self): s = self._get_norm_screen_coords() s[:, 0] *= self.size().width() s[:, 1] *= self.size().height() s[:, 2] *= self.size().width() s[:, 3] *= self.size().height() return s.astype(int) def paintEvent(self, QPaintEvent): for i, screen in enumerate(self._get_widget_screen_coords()): rect = QtCore.QRect(*screen) self.painter.begin(self) self.painter.setBrush(QtCore.Qt.BrushStyle.Dense4Pattern) self.painter.drawRect(rect) self.painter.setPen(QColor(168, 34, 3)) self.painter.setFont(QFont('Decorative', 30)) self.painter.drawText(rect, QtCore.Qt.AlignmentFlag.AlignCenter, str(i)) self.painter.end()
def paintEvent(self, event): p = QPainter(self.viewport()) render = self.createRenderContext() render.init(p) charWidth = render.getFontWidth() charHeight = render.getFontHeight() # Compute range that needs to be updated topY = event.rect().y() botY = topY + event.rect().height() topY = (topY - 2) // charHeight botY = ((botY - 2) // charHeight) + 1 # Compute selection range selection = False selStart, selEnd = self.getSelectionOffsets() if selStart != selEnd: selection = True # Draw selection if selection: startY = None endY = None startX = None endX = None for i in range(0, len(self.lines)): if selStart >= self.lines[i].address: startY = i - self.topLine startX = selStart - self.lines[i].address if startX > self.cols: startX = self.cols if selEnd >= self.lines[i].address: endY = i - self.topLine endX = selEnd - self.lines[i].address if endX > self.cols: endX = self.cols if startY is not None and endY is not None: p.setPen(binaryninjaui.getThemeColor( ThemeColor.SelectionColor)) p.setBrush( binaryninjaui.getThemeColor(ThemeColor.SelectionColor)) if startY == endY: p.drawRect(2 + (self.addrWidth + 2 + startX) * charWidth, 2 + startY * charHeight, (endX - startX) * charWidth, charHeight + 1) else: p.drawRect(2 + (self.addrWidth + 2 + startX) * charWidth, 2 + startY * charHeight, (self.cols - startX) * charWidth, charHeight + 1) if endX > 0: p.drawRect(2 + (self.addrWidth + 2) * charWidth, 2 + endY * charHeight, endX * charWidth, charHeight + 1) if (endY - startY) > 1: p.drawRect(2 + (self.addrWidth + 2) * charWidth, 2 + (startY + 1) * charHeight, self.cols * charWidth, ((endY - startY) - 1) * charHeight + 1) # Paint each line color = self.palette().color(QPalette.WindowText) for y in range(topY, botY): if (y + self.topLine) < 0: continue if (y + self.topLine) >= len(self.lines): break if self.lines[y + self.topLine].separator: render.drawLinearDisassemblyLineBackground( p, LinearDisassemblyLineType.NonContiguousSeparatorLineType, QRect(0, 2 + y * charHeight, event.rect().width(), charHeight), 0) continue lineStartAddr = self.lines[y + self.topLine].address addrStr = "%.8x" % lineStartAddr length = self.lines[y + self.topLine].length text = self.lines[y + self.topLine].text cursorCol = None if (((self.cursorAddr >= lineStartAddr) and (self.cursorAddr < (lineStartAddr + length))) or (((y + self.topLine + 1) >= len(self.lines)) and (self.cursorAddr == (lineStartAddr + length)))): cursorCol = self.cursorAddr - lineStartAddr render.drawText( p, 2, 2 + y * charHeight, binaryninjaui.getThemeColor(ThemeColor.AddressColor), addrStr) render.drawText(p, 2 + (self.addrWidth + 2) * charWidth, 2 + y * charHeight, color, text) if self.caretVisible and self.caretBlink and not selection and cursorCol is not None: p.setPen(Qt.NoPen) p.setBrush(self.palette().color(QPalette.WindowText)) p.drawRect(2 + (self.addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, charWidth, charHeight + 1) caretTextColor = self.palette().color(QPalette.Base) byteValue = self.data.read(lineStartAddr + cursorCol, 1) if len(byteValue) == 1: byteStr = self.byte_mapping[byteValue[0]] render.drawText( p, 2 + (self.addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, caretTextColor, byteStr)
def drawInnerBackground(self, p: QPainter, innerRect: QRectF): if self.m_barStyle == self.BarStyle.DONUT: p.setBrush(self.palette().alternateBase()) p.drawEllipse(innerRect)
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()
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)
def setupMenu(self) -> None: self.setMenuBar(QMenuBar(self)) settings = QSettings() # mods menu menuMods: QMenu = self.menuBar().addMenu('&Mods') downIcon = QIcon(str(getRuntimePath('resources/icons/down.ico'))) gearIcon = QIcon(str(getRuntimePath('resources/icons/gear.ico'))) dirsIcon = QIcon(str( getRuntimePath('resources/icons/open-folder.ico'))) colrIcon = QIcon( str(getRuntimePath('resources/icons/color-circle.ico'))) smilIcon = QIcon(str(getRuntimePath('resources/icons/smile.ico'))) actionAddModFromFile = menuMods.addAction('&Add Mods') actionAddModFromFile.triggered.connect(self.showAddModFromFileDialog) actionAddModFromFolder = menuMods.addAction('Add u&npacked Mod') actionAddModFromFolder.triggered.connect( self.showAddModFromFolderDialog) actionDownloadMod = menuMods.addAction('&Download Mod') actionDownloadMod.setIcon(downIcon) actionDownloadMod.triggered.connect(self.showDownloadModDialog) menuMods.addSeparator() actionGetInfo = menuMods.addAction('Update Mod de&tails') actionGetInfo.setIcon(downIcon) actionGetInfo.triggered.connect(self.showGetInfoDialog) actionGetUpdates = menuMods.addAction('Check for Mod &updates') actionGetUpdates.setIcon(downIcon) actionGetUpdates.triggered.connect(self.showGetUpdatesDialog) menuMods.addSeparator() actionExport = menuMods.addAction('&Export Modlist') actionExport.triggered.connect(self.showExportDialog) menuMods.aboutToShow.connect(lambda: [ actionDownloadMod.setDisabled(not str(settings.value('nexusAPIKey'))), actionGetInfo.setDisabled( not str(settings.value('nexusAPIKey')) or \ not len(self.model) or \ not self.mainwidget.modlist.selectionModel().hasSelection()), actionGetUpdates.setDisabled( not str(settings.value('nexusAPIKey')) or \ not len(self.model) or \ not self.mainwidget.modlist.selectionModel().hasSelection()), actionExport.setDisabled(not len(self.model)) ]) # view menu menuView: QMenu = self.menuBar().addMenu('&View') showSummary = menuView.addAction('Show &Summary') showSummary.setCheckable(True) showSummary.setChecked(settings.value('showSummary', 'True') == 'True') showSummary.triggered.connect(lambda checked: [ settings.setValue('showSummary', str(checked)), self.mainwidget.summary.setVisible(checked) ]) menuView.addSeparator() toggleHighlightNewest = menuView.addAction('Highlight &Newest') toggleHighlightNewest.setCheckable(True) toggleHighlightNewest.setChecked( settings.value('highlightNewest', 'True') == 'True') toggleHighlightNewest.triggered.connect(lambda checked: [ settings.setValue('highlightNewest', str(checked)), self.model.updateCallbacks.fire(self.model) ]) iconHighlightNewest = QPixmap(256, 256) iconHighlightNewest.fill(Qt.transparent) painter = QPainter(iconHighlightNewest) painter.setBrush(QBrush(QColor(222, 255, 222))) painter.drawEllipse(10, 10, 236, 236) toggleHighlightNewest.setIcon(QIcon(iconHighlightNewest)) painter.end() toggleHighlightRecent = menuView.addAction('Highlight &Recent') toggleHighlightRecent.setCheckable(True) toggleHighlightRecent.setChecked( settings.value('highlightRecent', 'True') == 'True') toggleHighlightRecent.triggered.connect(lambda checked: [ settings.setValue('highlightRecent', str(checked)), self.model.updateCallbacks.fire(self.model) ]) iconHighlightRecent = QPixmap(256, 256) iconHighlightRecent.fill(Qt.transparent) painter = QPainter(iconHighlightRecent) painter.setBrush(QBrush(QColor(222, 226, 255))) painter.drawEllipse(10, 10, 236, 236) toggleHighlightRecent.setIcon(QIcon(iconHighlightRecent)) painter.end() toggleHighlightUnmanaged = menuView.addAction('Highlight &Unmanaged') toggleHighlightUnmanaged.setCheckable(True) toggleHighlightUnmanaged.setChecked( settings.value('highlightUnmanaged', 'True') == 'True') toggleHighlightUnmanaged.triggered.connect(lambda checked: [ settings.setValue('highlightUnmanaged', str(checked)), self.model.updateCallbacks.fire(self.model) ]) iconHighlightUnmanaged = QPixmap(256, 256) iconHighlightUnmanaged.fill(Qt.transparent) painter = QPainter(iconHighlightUnmanaged) painter.setBrush(QBrush(QColor(250, 220, 220))) painter.drawEllipse(10, 10, 236, 236) toggleHighlightUnmanaged.setIcon(QIcon(iconHighlightUnmanaged)) painter.end() toggleHighlightDisabled = menuView.addAction('Highlight &Disabled') toggleHighlightDisabled.setCheckable(True) toggleHighlightDisabled.setChecked( settings.value('highlightDisabled', 'True') == 'True') toggleHighlightDisabled.triggered.connect(lambda checked: [ settings.setValue('highlightDisabled', str(checked)), self.model.updateCallbacks.fire(self.model) ]) iconHighlightDisabled = QPixmap(256, 256) iconHighlightDisabled.fill(Qt.transparent) painter = QPainter(iconHighlightDisabled) painter.setBrush(QBrush(QColor(230, 230, 230))) painter.drawEllipse(10, 10, 236, 236) toggleHighlightDisabled.setIcon(QIcon(iconHighlightDisabled)) painter.end() menuView.addSeparator() toggleColors = menuView.addAction('&Colored Icons') toggleColors.setCheckable(True) toggleColors.setChecked(settings.value('iconColors', 'True') == 'True') toggleColors.triggered.connect(lambda checked: [ settings.setValue('iconColors', str(checked)), self.mainwidget.modlist.listmodel.setIcons(), self.model.updateCallbacks.fire(self.model) ]) toggleColors.setIcon(colrIcon) menuView.addSeparator() toggleCompact = menuView.addAction('Compact &Mode') toggleCompact.setCheckable(True) toggleCompact.setChecked( settings.value('compactMode', 'False') == 'True') toggleCompact.triggered.connect(lambda checked: [ settings.setValue('compactMode', str(checked)), self.mainwidget.modlist.setSectionSize(checked) ]) # settings menu menuSettings: QMenu = self.menuBar().addMenu('&Tools') actionSettings = menuSettings.addAction('&Settings') actionSettings.setIcon(gearIcon) actionSettings.triggered.connect(self.showSettingsDialog) menuSettings.addSeparator() actionOpenGameDirectory = menuSettings.addAction( 'Open &Game directory') actionOpenGameDirectory.setIcon(dirsIcon) actionOpenGameDirectory.triggered.connect( lambda: util.openDirectory(self.model.gamepath)) actionOpenConfigDirectory = menuSettings.addAction( 'Open &Config directory') actionOpenConfigDirectory.setIcon(dirsIcon) actionOpenConfigDirectory.triggered.connect( lambda: util.openDirectory(self.model.configpath)) # info menu menuInfo: QMenu = self.menuBar().addMenu('&Info') actionFeedback = menuInfo.addAction('Send &Feedback') actionFeedback.setIcon(smilIcon) actionFeedback.triggered.connect( lambda: QDesktopServices.openUrl(QUrl(w3modmanager.URL_ISSUES))) menuInfo.addSeparator() actionAbout = menuInfo.addAction('&About') actionAbout.setIcon(QIcon.fromTheme('document-open')) actionAbout.triggered.connect(self.showAboutDialog)