예제 #1
0
 def sizeHint(self):
     """Returns the widget size hint (based on the editor font size) """
     fm = QFontMetricsF(self.editor.font())
     size_hint = QSize(ceil(fm.height()), ceil(fm.height()))
     if size_hint.width() > 16:
         size_hint.setWidth(16)
     return size_hint
예제 #2
0
    def draw_scale_num(self, p):
        sin = math.sin
        cos = math.cos
        p.save()
        p.setPen(Qt.white)
        start_rad = self._start_angle * (3.14 / 180)
        step_rad = (360 - (self._start_angle - self._end_angle)) * (
            3.14 / 180) / self._scale_main_num

        fm = QFontMetricsF(p.font())
        for i in range(0, self._scale_main_num + 1):
            sina = sin(start_rad + i * step_rad)
            cosa = cos(start_rad + i * step_rad)

            tmp_val = i * ((self._max_value - self._min_value) /
                           self._scale_main_num) + self._min_value
            tmp_val = tmp_val / self._min_radio
            s = '{:.0f}'.format(tmp_val)
            w = fm.size(Qt.TextSingleLine, s).width()
            h = fm.size(Qt.TextSingleLine, s).height()
            x = 80 * cosa - w / 2
            y = 80 * sina - h / 2
            p.drawText(QRectF(x, y, w, h), s)

        p.restore()
예제 #3
0
파일: text.py 프로젝트: 1PYTHON1/PythonQwt
 def fontmetrics_f(self, font):
     fid = font.toString()
     fm = self._fm_cache_f.get(fid)
     if fm is None:
         return self._fm_cache_f.setdefault(fid, QFontMetricsF(font))
     else:
         return fm
예제 #4
0
    def paintEvent(self, event):
        """Override Qt method.

        Painting line number area
        """
        painter = QPainter(self)
        painter.fillRect(event.rect(), self.editor.sideareas_color)
        font_height = self.editor.fontMetrics().height()

        def draw_pixmap(xleft, ytop, pixmap):
            # Scale pixmap height to device independent pixels
            pixmap_height = pixmap.height() / pixmap.devicePixelRatio()
            painter.drawPixmap(
                xleft,
                ceil(ytop + (font_height-pixmap_height) / 2),
                pixmap
            )

        size = self.get_markers_margin() - 2
        icon_size = QSize(size, size)

        if self._margin:
            font = self.editor.font()
            fm = QFontMetricsF(font)
            if fm.leading() == 0:
                self.draw_linenumbers(painter)
            else:
                # The editor doesn't care about leading, so each line
                # must be drawn independently.
                self.draw_linenumbers_slow(painter)

        for top, line_number, block in self.editor.visible_blocks:
            data = block.userData()
            if self._markers_margin and data:
                if data.code_analysis:
                    errors = 0
                    warnings = 0
                    infos = 0
                    hints = 0
                    for _, _, sev, _ in data.code_analysis:
                        errors += sev == DiagnosticSeverity.ERROR
                        warnings += sev == DiagnosticSeverity.WARNING
                        infos += sev == DiagnosticSeverity.INFORMATION
                        hints += sev == DiagnosticSeverity.HINT

                    if errors:
                        draw_pixmap(1, top, self.error_icon.pixmap(icon_size))
                    elif warnings:
                        draw_pixmap(
                            1, top, self.warning_icon.pixmap(icon_size))
                    elif infos:
                        draw_pixmap(1, top, self.info_icon.pixmap(icon_size))
                    elif hints:
                        draw_pixmap(1, top, self.hint_icon.pixmap(icon_size))

                if data.todo:
                    draw_pixmap(1, top, self.todo_icon.pixmap(icon_size))
 def drawText(self, p: QPainter, innerRect: QRectF, innerRadius: float, value: float):
     if not self.m_format:
         return
     f = QFont(self.font())
     f.setPixelSize(10)
     fm = QFontMetricsF(f)
     maxWidth = fm.width(self.valueToText(self.m_max))
     delta = innerRadius / maxWidth
     fontSize = f.pixelSize() * delta * 0.75
     f.setPixelSize(int(fontSize))
     p.setFont(f)
     textRect = QRectF(innerRect)
     p.setPen(self.palette().text().color())
     p.drawText(textRect, Qt.AlignCenter, self.valueToText(value))
예제 #6
0
 def fontmetrics_f(self, font):
     fid = font.toString()
     try:
         return self._fm_cache_f[fid]
     except KeyError:
         return self._fm_cache_f.setdefault(fid, QFontMetricsF(font))