Exemplo n.º 1
0
 def editorEvent(self, event, model, option, index):
     if event.type() == QEvent.MouseButtonRelease and index.column(
     ) == 0 and index.flags() & Qt.ItemIsUserCheckable:
         toggled = Qt.Checked if model.data(
             index, Qt.CheckStateRole) == QVariant(
                 Qt.Unchecked) else Qt.Unchecked
         return model.setData(index, toggled, Qt.CheckStateRole)
     __event = QItemDelegate(self).editorEvent(event, model, option, index)
     animate_requested = False
     if event.type() == QEvent.MouseButtonRelease and self.animatable:
         if self.rowAnimator.row == index.row():
             epos = event.pos()
             if self.rowAnimator.hoverLinkFilter.link_rect.contains(
                     QPoint(epos.x(),
                            epos.y() + 32)):
                 url = QUrl(model.data(index, HomepageRole).toString())
                 QDesktopServices.openUrl(url)
                 return __event
             elif self.rowAnimator.hoverLinkFilter.button_rect.contains(
                     epos, True):
                 self.showPackageDetails(model, index)
                 return __event
         animate_requested = True
     elif event.type() == QEvent.KeyPress and self.animatable:
         # KeyCode 32 : Space key
         if event.key() == 32 and index.column(
         ) == index.model().columnCount() - 1:
             animate_requested = True
     if not unicode(model.data(
             index,
             DescriptionRole).toString()) == '' and animate_requested:
         self.rowAnimator.animate(index.row())
     return __event
Exemplo n.º 2
0
 def paint(self, painter, option, index):
     itype = index.data(Qt.AccessibleDescriptionRole).toString()
     if itype == "parent":
         option.state |= QStyle.State_Enabled
     elif itype == "child":
         indent = option.fontMetrics.width(QString(4, QChar(' ')))
         option.rect.adjust(indent, 0, 0, 0)
         option.textElideMode = Qt.ElideNone
     QItemDelegate().paint(painter, option, index)
Exemplo n.º 3
0
 def __init__(self, images, scales, images_path, *args):
     QDialog.__init__(self, *args)
     cache = image_cache.cache
     self.ui = Ui_EditResDlg()
     self.ui.setupUi(self)
     icons = []
     for pth in images_path:
         ico = QIcon(
             QPixmap.fromImage(
                 cache.image(pth).scaled(QSize(64, 64),
                                         Qt.KeepAspectRatio)))
         icons.append(ico)
     self.model = ScaleModel(icons, images, scales)
     self.ui.pixelSizes.setModel(self.model)
     self.ui.pixelSizes.resizeColumnToContents(0)
     self.ui.pixelSizes.resizeColumnToContents(1)
     self.ui.pixelSizes.resizeColumnToContents(2)
     self.item_delegate = QItemDelegate()
     self.item_delegate.setItemEditorFactory(ScaleEditorFactory())
     self.ui.pixelSizes.setItemDelegate(self.item_delegate)
     self.ui.width.setValidator(QDoubleValidator(0, 1e300, 100, self))
     self.ui.height.setValidator(QDoubleValidator(0, 1e300, 100, self))
     # Find smallest scale
     minx = inf
     miny = inf
     for img in scales:
         sc = scales[img]
         if sc[0] > 0 and sc[0] < minx:
             minx = sc[0]
         if sc[1] > 0 and sc[1] < miny:
             miny = sc[1]
     if minx == inf:
         minx = 1e-6
     if miny == inf:
         miny = 1e-6
     # And set the default unit
     self.ui.unit.setCurrentIndex(self.model.findUnit(min(minx, miny)))