예제 #1
0
 def paintEvent(self, e):
     QGraphicsView.paintEvent(self, e)
     g = QPainter(self.viewport())
     g.setRenderHints(self.renderHints())
     try:
         self._info_font
     except AttributeError:
         self._info_font = g.font()
         multiply_font_size(self._info_font, 3)
     
     try:
         txt = ('{r} ({m})' if self.scene.mistakes else '{r}').format(r=self.scene.remaining, m=self.scene.mistakes)
         g.setFont(self._info_font)
         g.drawText(self.viewport().rect().adjusted(5, 2, -5, -2), qt.AlignTop|qt.AlignRight, txt)
     except AttributeError:
         pass
예제 #2
0
 def paintEvent(self, e):
     QGraphicsView.paintEvent(self, e)
     g = QPainter(self.viewport())
     g.setRenderHints(self.renderHints())
     try:
         self._info_font
     except AttributeError:
         self._info_font = g.font()
         multiply_font_size(self._info_font, 3)
     
     try:
         txt = ('{r} ({m})' if self.scene.mistakes else '{r}').format(r=self.scene.remaining, m=self.scene.mistakes)
         g.setFont(self._info_font)
         g.drawText(self.viewport().rect().adjusted(5, 2, -5, -2), qt.AlignTop|qt.AlignRight, txt)
     except AttributeError:
         pass
예제 #3
0
 def paintEvent(self, e):
     common.View.paintEvent(self, e)
     g = QPainter(self.viewport())
     g.setRenderHints(self.renderHints())
     area = self.viewport().rect().adjusted(5, 2, -5, -2)
     
     if self.progress_loaded_timer.isActive():
         g.setPen(QPen(Color.dark_text))
         g.drawText(area, qt.AlignTop | qt.AlignLeft, "Progress loaded")
     
     try:
         self._info_font
     except AttributeError:
         self._info_font = g.font()
         multiply_font_size(self._info_font, 3)
     
     try:
         txt = ('{r} ({m})' if self.scene.mistakes else '{r}').format(r=self.scene.remaining, m=self.scene.mistakes)
         g.setFont(self._info_font)
         g.setPen(QPen(Color.dark_text))
         g.drawText(area, qt.AlignTop | qt.AlignRight, txt)
     except AttributeError: pass
예제 #4
0
def generate_icon(size, n):
    w, h = size.width(), size.height()

    img = QImage(size, QImage.Format_ARGB32_Premultiplied)
    img.fill(qt.transparent)
    
    g = QPainter(img)
    
    d = 0 if qt.major <= 4 else 0.5
    
    if n:
        g.fillRect(0, 0, w, h, QColor(92, 126, 16))

        sz = h*0.88 if n < 10 else w*0.7
        icon_font.setPixelSize(sz)
        
        g.setFont(icon_font)
        g.setPen(qt.white)
        g.drawText(QRectF(1, 1, w-1, h-1+sz*0.0025-d), qt.AlignCenter|qt.AlignVCenter, str(n))
    else:
        (_, empty) = max((k, v) for k, v in empty_images.items() if k <= min(w, h))

        g.drawPixmap(int(w/2-empty.width()/2), int(h/2-empty.height()/2), empty)
    
    del g
    
    return QIcon(QPixmap.fromImage(img))