Exemplo n.º 1
0
 def paint(self, painter, option, index):
     model = index.model()
     row = index.row()
     parent = index.parent()
     mute_index = model.index(row, LayerModel.MUTE_COLUMN, parent)
     self.muted = model.data(mute_index, role=QtCore.Qt.EditRole)
     solo_index = model.index(row, LayerModel.SOLO_COLUMN, parent)
     self.soloed = model.data(solo_index, role=QtCore.Qt.EditRole)
     lock_index = model.index(row, LayerModel.LOCK_COLUMN, parent)
     self.locked = model.data(lock_index, role=QtCore.Qt.EditRole)
     tgt_index = model.index(row, LayerModel.TARGET_COLUMN, parent)
     self.is_tgt = model.data(tgt_index, role=QtCore.Qt.EditRole)
     sel_idx = model.index(row, LayerModel.HAS_SELECTED_COLUMN, parent)
     self.has_selected = model.data(sel_idx, role=QtCore.Qt.EditRole)
     effected_idx = model.index(row, LayerModel.UNSAVED, parent)
     self.unsaved = model.data(effected_idx, role=QtCore.Qt.EditRole)
     # Global drawing info
     self.initStyleOption(option, index)
     inner_rect = QtCore.QRect().united(option.rect)
     inner_rect = inner_rect.marginsRemoved(QtCore.QMargins(1, 1, 1, 1))
     # Swatch
     painter.setPen(QtCore.Qt.NoPen)
     painter.setBrush(QtCore.Qt.NoBrush)
     self.paint_swatch(painter, option.backgroundBrush, inner_rect)
     # BG
     painter.setPen(QtCore.Qt.NoPen)
     painter.setBrush(QtCore.Qt.NoBrush)
     self.paint_bg(painter, option.backgroundBrush, inner_rect)
     # Text
     painter.setPen(QtCore.Qt.NoPen)
     painter.setBrush(QtCore.Qt.NoBrush)
     text_rect = inner_rect.adjusted(inner_rect.height() + 4, 0, 0, 0)
     pre_text_font = painter.font()
     self.paint_text(painter, option.text, text_rect)
     painter.setFont(pre_text_font)
Exemplo n.º 2
0
 def paint(self, painter, option, index):
     self.initStyleOption(option, index)
     painter.setPen(QtCore.Qt.NoPen)
     if option.checkState == QtCore.Qt.CheckState.Checked:
         painter.setBrush(option.backgroundBrush)
         inner_rect = QtCore.QRect().united(option.rect)
         inner_rect = inner_rect.marginsRemoved(QtCore.QMargins(1, 1, 1, 1))
         painter.drawRoundedRect(inner_rect, 2, 2)
         inner_rect = inner_rect.marginsRemoved(QtCore.QMargins(2, 2, 2, 2))
         scaled = self.pixmap.size().scaled(inner_rect.size(),
                                            QtCore.Qt.KeepAspectRatio)
         painter.drawPixmap(inner_rect.x(), inner_rect.y(),
                            scaled.width(), scaled.height(), self.pixmap)
     else:
         painter.setBrush(QtCore.Qt.gray)
         center = option.rect.center()
         painter.drawEllipse(center, self.height/8, self.height/8)
Exemplo n.º 3
0
 def shape(self):
     rect = self.boundingRect().marginsRemoved(
         QtCore.QMargins(10, 10, 60, 10))
     path = QtGui.QPainterPath()
     path.setFillRule(QtCore.Qt.WindingFill)
     path.addEllipse(rect)
     path.addRect(rect.x(), rect.center().y() - 5, rect.width() + 50, 10)
     return path
Exemplo n.º 4
0
 def paint(self, painter, option, widget):
     painter.setPen(self.pen)
     rect = self.boundingRect().marginsRemoved(
         QtCore.QMargins(10, 10, 60, 10))
     path = QtGui.QPainterPath()
     path.addEllipse(rect)
     path.addRect(rect.center().x(), rect.y(), 0, rect.height())
     path.addRect(rect.x(), rect.center().y(), rect.width() + 50, 0)
     painter.drawPath(path)
Exemplo n.º 5
0
 def paint(self, painter, option, index):
     self.initStyleOption(option, index)
     inner_rect = QtCore.QRect().united(option.rect)
     inner_rect = inner_rect.marginsRemoved(QtCore.QMargins(1, 1, 1, 1))
     painter.setPen(QtCore.Qt.NoPen)
     painter.setBrush(option.backgroundBrush)
     if option.checkState == QtCore.Qt.CheckState.Checked:
         painter.drawRoundedRect(inner_rect, 2, 2)
         painter.setPen(QtCore.Qt.white)
     else:
         painter.setPen(QtCore.Qt.gray)
     painter.drawText(inner_rect, QtCore.Qt.AlignCenter, self.letter)
    def frameRect(self, rect):
        if rect is None:
            return
        windowRect = self.mapToScene(self.rect()).boundingRect()

        # pan to center of window
        delta = windowRect.center() - rect.center()
        delta *= self.currentViewScale()
        self.pan(delta)

        # zoom to fit content
        ws = windowRect.size()
        rect += QtCore.QMargins(40, 40, 40, 40)
        rs = rect.size()
        widthRef = ws.width()
        heightRef = ws.height()
        sx = widthRef / rect.width()
        sy = heightRef / rect.height()
        scale = sx if sy > sx else sy
        self.zoom(scale)

        return scale