예제 #1
0
    def setBadge(self, x, y, w, h, color=None):
        """
        Set a for the icon.
        
        :type x: int 
        :type y: int 
        :type w: int
        :type h: int 
        :type color: QtGui.QColor or None
        """
        color = color or QtGui.QColor(240, 100, 100)

        size = self.actualSize(QtCore.QSize(256, 256))
        pixmap = self.pixmap(size)

        painter = QtGui.QPainter(pixmap)

        pen = QtGui.QPen(color)
        pen.setWidth(0)
        painter.setPen(pen)

        painter.setBrush(color)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        painter.drawEllipse(x, y, w, h)
        painter.end()

        icon = QtGui.QIcon(pixmap)
        self.swap(icon)
예제 #2
0
    def __init__(self, *args, **kwargs):
        """
        :type args: list
        :type kwargs: dict
        """
        mayabaseplugin.CreateWidget.__init__(self, *args, **kwargs)

        self._sequencePath = None
        start, end = mutils.currentFrameRange()

        self.ui.sequenceWidget = studioqt.ImageSequenceWidget(self)

        icon = studiolibraryplugins.resource().icon("thumbnail")
        self.ui.sequenceWidget.setIcon(icon)

        self.ui.layout().insertWidget(1, self.ui.sequenceWidget)
        self.ui.snapshotButton.parent().hide()
        self.ui.sequenceWidget.setStyleSheet(
            self.ui.snapshotButton.styleSheet())

        validator = QtGui.QIntValidator(-50000000, 50000000, self)
        self.ui.endFrameEdit.setValidator(validator)
        self.ui.startFrameEdit.setValidator(validator)

        self.ui.endFrameEdit.setText(str(int(end)))
        self.ui.startFrameEdit.setText(str(int(start)))

        self.ui.byFrameEdit.setValidator(QtGui.QIntValidator(1, 1000, self))
        self.ui.byFrameEdit.setText(str(self.settings().get("byFrame")))

        self.ui.sequenceWidget.clicked.connect(self.snapshot)
        self.ui.setEndFrameButton.clicked.connect(self.setEndFrame)
        self.ui.setStartFrameButton.clicked.connect(self.setStartFrame)
예제 #3
0
    def paintBackground(self, painter, option, index):
        """
        Draw the background for the item.

        :type painter: QtWidgets.QPainter
        :type option: QtWidgets.QStyleOptionViewItem
        :type index: QtCore.QModelIndex
        :rtype: None
        """
        super(GroupItem, self).paintBackground(painter, option, index)

        painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
        visualRect = self.visualRect(option)

        text = self.name()
        metrics = QtGui.QFontMetricsF(self._font)
        textWidth = metrics.width(text)

        padding = (25 * self.dpi())

        visualRect.setX(textWidth + padding)
        visualRect.setY(visualRect.y() + (visualRect.height() / 2))
        visualRect.setHeight(2 * self.dpi())
        visualRect.setWidth(visualRect.width() - padding)

        color = QtGui.QColor(self.textColor().red(),
                             self.textColor().green(),
                             self.textColor().blue(), 10)
        painter.setBrush(QtGui.QBrush(color))

        painter.drawRect(visualRect)
    def browseColor(self):
        """
        Show the color dialog.

        :rtype: None
        """
        color = self.currentColor()

        d = QtWidgets.QColorDialog(self)
        d.setCurrentColor(color)

        standardColors = self.browserColors()

        if standardColors:
            index = -1
            for standardColor in standardColors:
                index += 1

                try:
                    # Support for new qt5 signature
                    standardColor = QtGui.QColor(standardColor)
                    d.setStandardColor(index, standardColor)
                except:
                    # Support for new qt4 signature
                    standardColor = QtGui.QColor(standardColor).rgba()
                    d.setStandardColor(index, standardColor)

        d.currentColorChanged.connect(self._colorChanged)

        if d.exec_():
            self._colorChanged(d.selectedColor())
        else:
            self._colorChanged(color)
예제 #5
0
    def paintBackground(self, painter, option, index):
        """
        Draw the background for the item.

        :type painter: QtWidgets.QPainter
        :type option: QtWidgets.QStyleOptionViewItem
        :type index: QtCore.QModelIndex
        :rtype: None
        """
        studioqt.CombinedWidgetItem.paintBackground(self, painter, option,
                                                    index)

        painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
        visualRect = self.visualRect(option)

        textWidth = self.textWidth(0)

        padding = (20 * self.dpi())

        visualRect.setX(textWidth + padding)
        visualRect.setY(visualRect.y() + (visualRect.height() / 2))
        visualRect.setHeight(2 * self.dpi())
        visualRect.setWidth(visualRect.width() - padding)

        color = QtGui.QColor(250, 250, 250, 20)
        painter.setBrush(QtGui.QBrush(color))

        painter.drawRect(visualRect)
예제 #6
0
 def dragPixmap(self, item, items):
     """
     Show the drag pixmap for the given item.
     
     :type item: recordwidgetitem.RecordWidgetItem
     :rtype: QtGui.QPixmap
     """
     rect = self.visualRect(self.indexFromItem(item))
     pixmap = QtGui.QPixmap()
     pixmap = pixmap.grabWidget(self, rect)
     if len(items) > 1:
         cWidth = 35
         cPadding = 5
         cText = str(len(items))
         cX = pixmap.rect().center().x() - float(cWidth / 2)
         cY = pixmap.rect().top() + cPadding
         cRect = QtCore.QRect(cX, cY, cWidth, cWidth)
         painter = QtGui.QPainter(pixmap)
         painter.setRenderHint(QtGui.QPainter.Antialiasing)
         painter.setPen(QtCore.Qt.NoPen)
         painter.setBrush(self.combinedWidget().backgroundSelectedColor())
         painter.drawEllipse(cRect.center(), float(cWidth / 2), float(cWidth / 2))
         font = QtGui.QFont('Serif', 12, QtGui.QFont.Light)
         painter.setFont(font)
         painter.setPen(self.combinedWidget().textSelectedColor())
         painter.drawText(cRect, QtCore.Qt.AlignCenter, str(cText))
     return pixmap
예제 #7
0
 def _paintText(self, painter, option, column):
     text = self.displayText(column)
     isSelected = option.state & QtWidgets.QStyle.State_Selected
     if isSelected:
         color = self.textSelectedColor()
     else:
         color = self.textColor()
     visualRect = self.visualRect(option)
     width = visualRect.width()
     height = visualRect.height()
     padding = self.padding()
     x = padding / 2
     y = padding / 2
     visualRect.translate(x, y)
     visualRect.setWidth(width - padding)
     visualRect.setHeight(height - padding)
     align = QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter
     font = self.font(column)
     metrics = QtGui.QFontMetricsF(font)
     textWidth = metrics.width(text)
     if textWidth > visualRect.width() - padding:
         text = metrics.elidedText(text, QtCore.Qt.ElideRight,
                                   visualRect.width())
         if self.textAlignment(column) == QtCore.Qt.AlignLeft:
             align = self.textAlignment(column)
         else:
             align = QtCore.Qt.AlignLeft | self.textAlignment(column)
     else:
         align = self.textAlignment(column)
     pen = QtGui.QPen(color)
     painter.setPen(pen)
     painter.setFont(font)
     painter.drawText(visualRect, align, text)
예제 #8
0
 def data(self, index, role):
     """
     :type index: QtCore.QModelIndex
     :type role:
     :rtype: QtWidgets.QVariant
     """
     if role == QtCore.Qt.DecorationRole:
         if index.column() == 0:
             dirname = str(self.filePath(index))
             folder = self.foldersWidget().folderFromPath(dirname)
             pixmap = QtGui.QIcon(folder.pixmap())
             if pixmap:
                 pixmap = pixmap.pixmap(self.foldersWidget().iconSize(), transformMode=QtCore.Qt.SmoothTransformation)
                 return QtGui.QIcon(pixmap)
             else:
                 return None
     if role == QtCore.Qt.FontRole:
         if index.column() == 0:
             dirname = str(self.filePath(index))
             folder = self.foldersWidget().folderFromPath(dirname)
             if folder.exists():
                 if folder.isBold():
                     font = QtGui.QFont()
                     font.setBold(True)
                     return font
     if role == QtCore.Qt.DisplayRole:
         text = QtWidgets.QFileSystemModel.data(self, index, role)
         return text
     return QtWidgets.QFileSystemModel.data(self, index, role)
예제 #9
0
    def paintBackground(self, painter, option, index):
        """
        Draw the background for the item.

        :type painter: QtWidgets.QPainter
        :type option: QtWidgets.QStyleOptionViewItem
        :type index: QtCore.QModelIndex
        :rtype: None
        """
        isSelected = option.state & QtWidgets.QStyle.State_Selected
        isMouseOver = option.state & QtWidgets.QStyle.State_MouseOver
        painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))

        visualRect = self.visualRect(option)

        if isSelected:
            color = self.backgroundSelectedColor()
            painter.setBrush(QtGui.QBrush(color))
        elif isMouseOver:
            color = self.backgroundHoverColor()
            painter.setBrush(QtGui.QBrush(color))
        else:
            color = self.backgroundColor()
            painter.setBrush(QtGui.QBrush(color))

        painter.drawRect(visualRect)
예제 #10
0
    def paintEvent(self, event):
        """
        Triggered on frame changed.

        :type event: QtCore.QEvent
        :rtype: None
        """
        QtWidgets.QToolButton.paintEvent(self, event)

        painter = QtGui.QPainter()
        painter.begin(self)

        if self.currentFilename():

            r = event.rect()

            playheadHeight = self.playheadHeight()
            playheadPosition = self._imageSequence.percent() * r.width() - 1

            x = r.x()
            y = self.height() - playheadHeight

            painter.setPen(QtCore.Qt.NoPen)
            painter.setBrush(QtGui.QBrush(self.DEFAULT_PLAYHEAD_COLOR))
            painter.drawRect(x, y, playheadPosition, playheadHeight)

        painter.end()
예제 #11
0
    def browseBackgroundColor(self):
        """
        :rtype: None
        """
        color = self.backgroundColor()
        d = QtWidgets.QColorDialog(self)
        d.setCurrentColor(color)
        colors = [(0, 0, 0), (20, 20, 30), (0, 30, 60), (0, 60, 60),
                  (0, 60, 30), (60, 0, 10), (60, 0, 40), (40, 15, 5)]
        index = -1
        for colorR, colorG, colorB in colors:
            for i in range(0, 6):
                index += 1
                try:
                    standardColor = QtGui.QColor(colorR, colorG, colorB)
                    d.setStandardColor(index, standardColor)
                except:
                    standardColor = QtGui.QColor(colorR, colorG, colorB).rgba()
                    d.setStandardColor(index, standardColor)

                colorR += 20
                colorB += 20
                colorG += 20

        d.currentColorChanged.connect(self.setBackgroundColor)
        d.open(self, QtCore.SLOT('blankSlot()'))
        if d.exec_():
            self.setBackgroundColor(d.selectedColor())
        else:
            self.setBackgroundColor(color)
예제 #12
0
 def setIconPath(self, path):
     """
     :type path: str
     :rtype: None
     """
     self._iconPath = path
     icon = QtGui.QIcon(QtGui.QPixmap(path))
     self.setIcon(icon)
예제 #13
0
    def __init__(self, *args):
        QtWidgets.QWidget.__init__(self, *args)

        self._dpi = 1
        self._padding = self.DEFAULT_PADDING

        w, h = self.DEFAULT_ZOOM_AMOUNT, self.DEFAULT_ZOOM_AMOUNT

        self._iconSize = QtCore.QSize(w, h)
        self._itemSizeHint = QtCore.QSize(w, h)

        self._zoomAmount = self.DEFAULT_ZOOM_AMOUNT
        self._isItemTextVisible = True

        self._dataset = None
        self._treeWidget = TreeWidget(self)

        self._support_drag = self.DEFAULT_SUPPORT_DRAG
        self._listView = ListView(self._support_drag, self)
        self._listView.setTreeWidget(self._treeWidget)

        self._delegate = ItemDelegate()
        self._delegate.setItemsWidget(self)

        self._listView.setItemDelegate(self._delegate)
        self._treeWidget.setItemDelegate(self._delegate)

        self._toastWidget = ToastWidget(self)
        self._toastWidget.hide()
        self._toastEnabled = True

        self._textColor = QtGui.QColor(255, 255, 255, 200)
        self._textSelectedColor = QtGui.QColor(255, 255, 255, 200)
        self._backgroundColor = QtGui.QColor(255, 255, 255, 30)
        self._backgroundHoverColor = QtGui.QColor(255, 255, 255, 35)
        self._backgroundSelectedColor = QtGui.QColor(30, 150, 255)

        layout = QtWidgets.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._treeWidget)
        layout.addWidget(self._listView)

        header = self.treeWidget().header()
        header.sortIndicatorChanged.connect(self._sortIndicatorChanged)

        self.setLayout(layout)

        self.listView().itemClicked.connect(self._itemClicked)
        self.listView().itemDoubleClicked.connect(self._itemDoubleClicked)

        self.treeWidget().itemClicked.connect(self._itemClicked)
        self.treeWidget().itemDoubleClicked.connect(self._itemDoubleClicked)

        self.itemMoved = self._listView.itemMoved
        self.itemDropped = self._listView.itemDropped
        self.itemSelectionChanged = self._treeWidget.itemSelectionChanged
예제 #14
0
    def setIconPath(self, path):
        """
        Set the icon path to be used for the thumbnail.

        :type path: str
        :rtype: None
        """
        self._iconPath = path
        icon = QtGui.QIcon(QtGui.QPixmap(path))
        self.setIcon(icon)
        self.updateThumbnailSize()
예제 #15
0
 def createRubberBand(self):
     """
     Create a new instance of the selection rubber band.
     
     :rtype: QtWidgets.QRubberBand
     """
     rubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle, self)
     palette = QtGui.QPalette()
     color = self.rubberBandColor()
     palette.setBrush(QtGui.QPalette.Highlight, QtGui.QBrush(color))
     rubberBand.setPalette(palette)
     return rubberBand
예제 #16
0
    def _paintText(self, painter, option, column):

        if self.itemsWidget().isIconView():
            text = self.name()
        else:
            label = self.labelFromColumn(column)
            text = self.displayText(label)

        isSelected = option.state & QtWidgets.QStyle.State_Selected

        if isSelected:
            color = self.textSelectedColor()
        else:
            color = self.textColor()

        visualRect = self.visualRect(option)

        width = visualRect.width()
        height = visualRect.height()

        padding = self.padding()
        x = padding / 2
        y = padding / 2

        visualRect.translate(x, y)
        visualRect.setWidth(width - padding)
        visualRect.setHeight(height - padding)

        font = self.font(column)
        align = self.textAlignment(column)
        metrics = QtGui.QFontMetricsF(font)

        if text:
            textWidth = metrics.width(text)
        else:
            textWidth = 1

        # # Check if the current text fits within the rect.
        if textWidth > visualRect.width() - padding:
            visualWidth = visualRect.width()
            text = metrics.elidedText(text, QtCore.Qt.ElideRight, visualWidth)
            align = QtCore.Qt.AlignLeft

        if self.itemsWidget().isIconView():
            align = align | QtCore.Qt.AlignBottom
        else:
            align = align | QtCore.Qt.AlignVCenter

        pen = QtGui.QPen(color)
        painter.setPen(pen)
        painter.setFont(font)
        painter.drawText(visualRect, align, text)
예제 #17
0
    def _thumbnailFromImage(self, image):
        """
        Called after the given image object has finished loading.

        :type image: QtGui.QImage
        :rtype: None  
        """
        pixmap = QtGui.QPixmap()
        pixmap.convertFromImage(image)
        icon = QtGui.QIcon(pixmap)

        self._thumbnailIcon = icon
        self.combinedWidget().update()
예제 #18
0
class AnimCreateWidget(transferitem.CreateWidget):
    def __init__(self, item=None, parent=None):
        """
        :type args: list
        :type kwargs: dict
        """
        item = item or AnimItem()
        transferitem.CreateWidget.__init__(self, item, parent=parent)

        self._sequencePath = None

        try:
            start, end = (1, 100)
            start, end = mutils.currentFrameRange()
        except NameError, e:
            logger.exception(e)

        self.ui.sequenceWidget = studioqt.ImageSequenceWidget(self)
        self.ui.sequenceWidget.setStyleSheet(
            self.ui.thumbnailButton.styleSheet())
        self.ui.sequenceWidget.setToolTip(self.ui.thumbnailButton.toolTip())

        icon = studiolibraryitems.resource().icon("thumbnail2")
        self.ui.sequenceWidget.setIcon(icon)

        self.ui.thumbnailFrame.layout().insertWidget(0, self.ui.sequenceWidget)
        self.ui.thumbnailButton.hide()
        self.ui.thumbnailButton = self.ui.sequenceWidget

        validator = QtGui.QIntValidator(-50000000, 50000000, self)
        self.ui.endFrameEdit.setValidator(validator)
        self.ui.startFrameEdit.setValidator(validator)

        self.ui.endFrameEdit.setText(str(int(end)))
        self.ui.startFrameEdit.setText(str(int(start)))

        self.ui.byFrameEdit.setValidator(QtGui.QIntValidator(1, 1000, self))

        self.ui.sequenceWidget.clicked.connect(self.thumbnailCapture)
        self.ui.frameRangeButton.clicked.connect(self.showFrameRangeMenu)

        settings = animSettings()

        byFrame = settings.get("byFrame")
        self.setByFrame(byFrame)

        fileType = settings.get("fileType")
        self.setFileType(fileType)

        self.ui.byFrameEdit.textChanged.connect(self.stateChanged)
        self.ui.fileTypeComboBox.currentIndexChanged.connect(self.stateChanged)
예제 #19
0
 def defaultThumbnailIcon(self):
     """
     Get the default thumbnail icon.
     
     :rtype: QtGui.QIcon 
     """
     return QtGui.QIcon(self.defaultThumbnailPath())
예제 #20
0
    def setIcon(self, column, icon, color=None):
        """
        Set the icon to be displayed in the given column.

        :type column: int or str
        :type icon: QtGui.QIcon
        :type color: QtGui.QColor or None
        :rtype: None
        """
        # Safe guard for when the class is being used without the gui.
        isAppRunning = bool(QtWidgets.QApplication.instance())
        if not isAppRunning:
            return

        if isinstance(icon, basestring):
            if not os.path.exists(icon):
                color = color or studioqt.Color(255, 255, 255, 20)
                icon = studiolibrary.resource().icon("image", color=color)
            else:
                icon = QtGui.QIcon(icon)

        if isinstance(column, basestring):
            self._icon[column] = icon
        else:
            self._pixmap[column] = None
            QtWidgets.QTreeWidgetItem.setIcon(self, column, icon)

        self.updateIcon()
예제 #21
0
    def textWidth(self, column):
        text = self.text(column)

        font = self.font(column)
        metrics = QtGui.QFontMetricsF(font)
        textWidth = metrics.width(text)
        return textWidth
예제 #22
0
 def icon(self, column):
     icon = QtWidgets.QTreeWidgetItem.icon(self, column)
     if not icon and column == 0:
         iconPath = self.thumbnailPath()
         if iconPath:
             icon = QtGui.QIcon(iconPath)
     return icon
예제 #23
0
    def setItem(self, item):
        """
        Set the item for the preview widget.

        :type item: BaseItem
        """
        self._item = item

        if hasattr(self.ui, "titleLabel"):
            self.ui.titleLabel.setText(item.MenuName)

        if hasattr(self.ui, "iconLabel"):
            self.ui.iconLabel.setPixmap(QtGui.QPixmap(item.TypeIconPath))

        if hasattr(self.ui, "infoFrame"):
            infoWidget = studiolibrary.widgets.FormWidget(self)
            infoWidget.setSchema(item.info())
            self.ui.infoFrame.layout().addWidget(infoWidget)

        if hasattr(self.ui, "optionsFrame"):

            options = item.loadSchema()
            if options:
                optionsWidget = studiolibrary.widgets.FormWidget(self)
                optionsWidget.setSchema(item.loadSchema())
                optionsWidget.setValidator(item.loadValidator)
                optionsWidget.setStateFromOptions(
                    self.item().optionsFromSettings())
                optionsWidget.stateChanged.connect(self.optionsChanged)
                self.ui.optionsFrame.layout().addWidget(optionsWidget)
                self._optionsWidget = optionsWidget
                optionsWidget.validate()
            else:
                self.ui.optionsToggleBox.setVisible(False)
예제 #24
0
    def setItem(self, item):
        """
        Set the base item to be created.

        :type item: studiolibrarymaya.BaseItem
        """
        self._item = item

        self.ui.titleLabel.setText(item.MenuName)
        self.ui.iconLabel.setPixmap(QtGui.QPixmap(item.TypeIconPath))

        schema = item.saveSchema()

        if schema:
            optionsWidget = studiolibrary.widgets.FormWidget(self)
            optionsWidget.setSchema(schema)
            optionsWidget.setValidator(item.saveValidator)

            self.ui.optionsFrame.layout().addWidget(optionsWidget)
            self._optionsWidget = optionsWidget
            self.loadSettings()

            optionsWidget.stateChanged.connect(self._optionsChanged)
            optionsWidget.validate()
        else:
            self.ui.optionsFrame.setVisible(False)
예제 #25
0
 def currentIcon(self):
     """
     Return a icon object from the current icon path.
     
     :rtype: QtGui.QIcon
     """
     return QtGui.QIcon(self._imageSequence.currentFilename())
예제 #26
0
    def backgroundSelectedColor(self):
        """
        Return the background color when the item is selected.

        :rtype: QtWidgets.QtColor
        """
        return QtGui.QColor(0, 0, 0, 0)
예제 #27
0
    def backgroundHoverColor(self):
        """
        Return the background color when the mouse is over the item.

        :rtype: QtWidgets.QtColor
        """
        return QtGui.QColor(0, 0, 0, 0)
예제 #28
0
    def backgroundColor(self):
        """
        Return the background color for the item.

        :rtype: QtWidgets.QtColor
        """
        return QtGui.QColor(0, 0, 0, 0)
예제 #29
0
 def wrapped(*args, **kwargs):
     cursor = QtGui.QCursor(QtCore.Qt.ArrowCursor)
     QtWidgets.QApplication.setOverrideCursor(cursor)
     try:
         return fn(*args, **kwargs)
     finally:
         QtWidgets.QApplication.restoreOverrideCursor()
예제 #30
0
    def setItem(self, item):
        """
        Set the base item to be created.

        :type item: studiolibrarymaya.BaseItem
        """
        self._item = item

        self.ui.titleLabel.setText(item.MenuName)
        self.ui.iconLabel.setPixmap(QtGui.QPixmap(item.TypeIconPath))

        schema = item.saveSchema()

        if not item.isDefaultThumbnailPath():
            self.setThumbnail(item.thumbnailPath())

        if schema:
            formWidget = studiolibrary.widgets.FormWidget(self)
            formWidget.setSchema(schema)
            formWidget.setValidator(item.saveValidator)
            formWidget.setValues({"name": item.name()})

            self.ui.optionsFrame.layout().addWidget(formWidget)
            self._formWidget = formWidget

            formWidget.validate()
        else:
            self.ui.optionsFrame.setVisible(False)