def paintTown(self, painter, town, x, y, radius): degree_per_person = QT_FULL_CRICLE_DEGREE / town.population rectangle = QRectF(x - radius, y - radius, 2 * radius, 2 * radius) current_angle = 0.0 for population, color in reversed( list( zip(town.infection_state.vaccinated_population, GRAPHICS_VACCINATED_COLORS))): span_angle = degree_per_person * population painter.setBrush(color) painter.drawPie(rectangle, current_angle, span_angle) current_angle += span_angle for population, color in zip(town.infection_state.ill_population, GRAPHICS_ILL_COLORS): span_angle = degree_per_person * population painter.setBrush(color) painter.drawPie(rectangle, current_angle, span_angle) current_angle += span_angle if radius > BIG_FOR_CAPTION_RADIUS: painter.setBrush(Qt.white) painter.drawEllipse(QPointF(x, y), radius / 2, radius / 2) painter.drawText(rectangle, town.name, QTextOption(Qt.AlignHCenter | Qt.AlignVCenter)) else: painter.drawText( QRectF(x - radius, y + radius, 2 * radius, radius), town.name, QTextOption(Qt.AlignHCenter | Qt.AlignTop))
def __init__(self, parent, project=None): QPlainTextEdit.__init__(self) EditorGeneric.__init__(self) BaseCentralWidget.__init__(self) self.parent = parent self.completer = Completer(self, project) self.setWordWrapMode(QTextOption.NoWrap) doc = self.document() option = QTextOption() option.setFlags(QTextOption.ShowTabsAndSpaces) doc.setDefaultTextOption(option) self.setDocument(doc) self.set_default_font() #file modification time POSIX self._mtime = None #Flag to dont bug the user when answer 'dont show the modification dialog' self.ask_if_externally_modified = True self.lineNumberArea = self.LineNumberArea(self) self.viewport().installEventFilter(self) self.highlighter = None styles.set_style(self, 'editor') self.connect(self, SIGNAL("cursorPositionChanged()"), self.highlight_current_line) self.connect(self, SIGNAL("modificationChanged(bool)"), self.modif_changed) self.highlight_current_line()
def togglewhiteSpace(self, state=True): """ Show or hide whitespace and line ending markers """ option = QTextOption() if state: option.setFlags(QTextOption.ShowTabsAndSpaces | QTextOption.ShowLineAndParagraphSeparators) else: option.setFlags(option.flags() & ~option.ShowTabsAndSpaces & ~option.ShowLineAndParagraphSeparators) self.document().setDefaultTextOption(option) settings.set('editor:whiteSpace', state)
def set_flags(self): if settings.ALLOW_WORD_WRAP: self.setWordWrapMode(QTextOption.WrapAtWordBoundaryOrAnywhere) else: self.setWordWrapMode(QTextOption.NoWrap) self.setMouseTracking(True) doc = self.document() option = QTextOption() if settings.SHOW_TABS_AND_SPACES: option.setFlags(QTextOption.ShowTabsAndSpaces) doc.setDefaultTextOption(option) self.setDocument(doc) self.setCenterOnScroll(settings.CENTER_ON_SCROLL)
def paint(self, painter, option, widget): if self.isSelected(): pen = QPen(Qt.DashLine) pen.setColor(QColor(0xccff33)) pen.setWidth(2) painter.setPen(pen) else: pen = QPen(Qt.SolidLine) pen.setColor(Qt.black) painter.setPen(pen) painter.setBrush(QBrush(self.color)) painter.drawRoundedRect(self.rect, 5, 5) painter.setPen(Qt.SolidLine | Qt.black) painter.drawText(self.rect, str(self.model.id()), option=QTextOption(Qt.AlignCenter))
def paint(self, painter, option, widget): drawingRect = self.model.rect.adjusted(2, 2, -2, -2) painter.save() painter.setRenderHint(QPainter.Antialiasing, True) if self.isSelected(): pen = QPen(Qt.DashLine) pen.setWidth(2) pen.setColor(Qt.blue) else: pen = QPen(Qt.SolidLine) pen.setWidth(1) pen.setColor(Qt.gray) painter.setPen(pen) color = QColor(self.model.color) color.setAlphaF(self.model.accu) painter.setBrush(QBrush(color)) painter.drawRoundedRect(drawingRect, 5, 5) painter.setPen(Qt.SolidLine) painter.drawText(drawingRect, str(self.model.classid), QTextOption(Qt.AlignCenter)) painter.restore()
def _paint_usage_text(self, painter): '''Draws the user notification on how to use the selector''' font = QFont("Helvetica [Cronyx]", 26, QFont.Bold) painter.setFont(font) painter.setPen(QColor(255, 255, 255, 255)) # Figure out text x-coordinates screen_width = self.screen_geometry.width() text_width = 800 text_start_x = screen_width / 2 - text_width / 2 # Figure out text y-coordinates screen_height = self.screen_geometry.height() text_height = 200 text_start_y = screen_height / 2 - text_height / 2 textoption = QTextOption(Qt.AlignCenter) textbox = QRectF(text_start_x, text_start_y, text_width, text_height) painter.drawText( textbox, "Click & Drag to select an area\n" "ENTER to confirm or ESC to cancel", textoption) painter.drawRoundedRect(textbox, 20, 20)
def _drawitem(pixmap, text, itempostion): painter.drawPixmap(itempostion, pixmap) textrect = QRectF(pixmap.width() + currentx + 10, itempostion.y(), event.rect().width() - pixmap.width() - OFFSET_X, pixmap.height()) painter.drawText(textrect, text, QTextOption(Qt.AlignVCenter))