Exemplo n.º 1
0
    def __init__(self, *args):
        QtWidgets.QFrame.__init__(self, *args)

        self.setObjectName("statusWidget")
        self.setFrameShape(QtWidgets.QFrame.NoFrame)

        self._blocking = False
        self._timer = QtCore.QTimer(self)

        self._label = QtWidgets.QLabel("", self)
        self._label.setCursor(QtCore.Qt.IBeamCursor)
        self._label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
        self._label.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Preferred)

        self._button = QtWidgets.QPushButton(self)
        self._button.setMaximumSize(QtCore.QSize(17, 17))
        self._button.setIconSize(QtCore.QSize(17, 17))

        self._progressBar = ProgressBar(self)
        self._progressBar.hide()

        layout = QtWidgets.QHBoxLayout(self)
        layout.setContentsMargins(1, 0, 0, 0)

        layout.addWidget(self._button)
        layout.addWidget(self._label)
        layout.addWidget(self._progressBar)

        self.setLayout(layout)
        self.setFixedHeight(19)
        self.setMinimumWidth(5)

        self._timer.timeout.connect(self.reset)
Exemplo n.º 2
0
    def sizeHint(self, column=0):
        """
        Return the current size of the item.

        :type column: int
        :rtype: QtCore.QSize
        """
        if self.stretchToWidget():
            if self._size:
                size = self._size
            else:
                size = self.itemsWidget().iconSize()

            w = self.stretchToWidget().width()
            h = size.height()
            return QtCore.QSize(w - 20, h)

        if self._size:
            return self._size
        else:
            iconSize = self.itemsWidget().iconSize()

            if self.isLabelUnderItem():
                w = iconSize.width()
                h = iconSize.width() + self.textHeight()
                iconSize = QtCore.QSize(w, h)

            return iconSize
Exemplo n.º 3
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._labelDisplayOption = self.LABEL_DISPLAY_OPTION

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

        self._listView = ListView(self)
        self._listView.setTreeWidget(self._treeWidget)
        self._listView.installEventFilter(self)

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

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

        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._itemBackgroundColor = 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
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def setZoomAmount(self, value):
        """
        Set the zoom amount for the widget.

        :type value: int
        :rtype: None
        """
        if value < self.DEFAULT_MIN_LIST_SIZE:
            value = self.DEFAULT_MIN_LIST_SIZE

        self._zoomAmount = value
        size = QtCore.QSize(value * self.dpi(), value * self.dpi())
        self.setIconSize(size)

        if value >= self.DEFAULT_MIN_ICON_SIZE:
            self._setViewMode(self.IconMode)
        else:
            self._setViewMode(self.TableMode)

        columnWidth = value * self.dpi() + self.itemTextHeight()

        self._treeWidget.setIndentation(0)
        self._treeWidget.setColumnWidth(0, columnWidth)
        self.scrollToSelectedItem()

        msg = "Size: {0}%".format(value)
        self.showToastMessage(msg)
Exemplo n.º 6
0
    def sizeHint(self, column=0):
        """
        Return the size of the item.

        :rtype: QtCore.QSize
        """
        padding = self.PADDING_RIGHT * self.dpi()
        width = self.itemsWidget().width() - padding
        return QtCore.QSize(width, self.HEIGHT * self.dpi())
Exemplo n.º 7
0
    def updateThumbnailSize(self):
        """Update the thumbnail button to the size of the widget."""
        width = self.width() - 10
        if width > 250:
            width = 250

        size = QtCore.QSize(width, width)
        self.ui.thumbnailButton.setIconSize(size)
        self.ui.thumbnailButton.setMaximumSize(size)
        self.ui.thumbnailFrame.setMaximumSize(size)
Exemplo n.º 8
0
    def setIconSize(self, size):
        """
        Set the icon size for the views.

        :type size: QtCore.QSize
        :rtype: None
        """
        self._iconSize = size

        if self.labelDisplayOption() == LabelDisplayOption.Under:
            w = size.width()
            h = size.width() + self.itemTextHeight()
            self._itemSizeHint = QtCore.QSize(w, h)
        elif size.height() < self.itemTextHeight():
            self._itemSizeHint = QtCore.QSize(size.width(), self.itemTextHeight())
        else:
            self._itemSizeHint = size

        self._listView.setIconSize(size)
        self._treeWidget.setIconSize(size)
    def setSize(self, w, h):
        """
        Reimplemented so that the icon size is set at the same time.

        :type w: int
        :type h: int
        :rtype: None
        """
        self._size = QtCore.QSize(w, h)
        self.setIconSize(self._size)
        self.setFixedSize(self._size)
Exemplo n.º 10
0
    def setDpi(self, dpi):
        """
        Set the dots per inch multiplier.

        :type dpi: float
        :rtype: None
        """
        size = 24 * dpi
        self.setIndentation(14 * dpi)
        self.setMinimumWidth(22 * dpi)
        self.setIconSize(QtCore.QSize(size, size))
        self.setStyleSheet("height: {size}".format(size=size))
Exemplo n.º 11
0
    def collapse(self):
        """
        Collapse the MenuBar to the collapseHeight. 

        :rtype: None
        """
        self._isExpanded = False
        height = self.collapseHeight()
        self.setFixedHeight(height)
        self.setChildrenHeight(0)
        self.setChildrenHidden(True)
        self.setIconSize(QtCore.QSize(0, 0))
        self.setStyleSheet(self.styleSheet())
Exemplo n.º 12
0
 def expand(self):
     """
     Expand the MenuBar to the expandHeight. 
     
     :rtype: None
     """
     self._isExpanded = True
     height = self.expandHeight()
     self.setFixedHeight(height)
     self.setChildrenHidden(False)
     iconSize = self.ICON_SIZE * self.dpi()
     self.setIconSize(QtCore.QSize(iconSize, iconSize))
     self.setStyleSheet(self.styleSheet())
Exemplo n.º 13
0
    def rubberBandStartEvent(self, event):
        """
        Triggered when the user presses an empty area.

        :type event: QtWidgets.QMouseEvent
        :rtype: None
        """
        self._rubberBandStartPos = event.pos()
        rect = QtCore.QRect(self._rubberBandStartPos, QtCore.QSize())

        rubberBand = self.rubberBand()
        rubberBand.setGeometry(rect)
        rubberBand.show()
Exemplo n.º 14
0
    def setIcons(self, icons):
        """
        Set the colors for the color bar.

        :type icons: list[str] or list[studioqt.Icon]
        """
        self.deleteButtons()

        i = 0
        first = True
        last = False

        positions = [(i, j) for i in range(5) for j in range(5)]
        for position, iconPath in zip(positions, icons):
            i += 1

            if i == len(icons) - 1:
                last = True

            callback = partial(self._iconChanged, iconPath)

            button = self.BUTTON_CLASS(self)
            button.setIconPath(iconPath)
            button.setIconSize(QtCore.QSize(16, 16))

            button.setSizePolicy(
                QtWidgets.QSizePolicy.Expanding,
                QtWidgets.QSizePolicy.Preferred
            )

            button.setProperty("first", first)
            button.setProperty("last", last)

            button.clicked.connect(callback)

            self.layout().addWidget(button, *position)

            self._buttons.append(button)

            first = False

        self._menuButton = QtWidgets.QPushButton("...", self)
        self._menuButton.setObjectName('menuButton')
        self._menuButton.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Preferred
        )

        self._menuButton.clicked.connect(self.browseColor)
        self.layout().addWidget(self._menuButton)
        self.refresh()
    def updateToolBar(self):
        """Update the tool bar size depending on the number of actions."""

        self._toolBar.setIconSize(QtCore.QSize(16, 16))

        count = (len(self.actions())) - 3
        width = (26 * count)

        self._toolBar.setGeometry(0, 0, width, 25)

        x = self.rect().center().x() - (self._toolBar.width()/2)
        y = self.height() - self._toolBar.height() - 12
        width = self._toolBar.width()

        self._toolBar.setGeometry(x, y,  width,  self._toolBar.height())
    def setDpi(self, dpi):
        """
        Set the dots per inch multiplier.

        :type dpi: float
        :rtype: None
        """
        self._dpi = dpi

        width = 20 * dpi
        height = 18 * dpi

        self.setIndentation(9 * dpi)
        self.setMinimumWidth(20 * dpi)
        self.setIconSize(QtCore.QSize(width, height))
        self.setStyleSheet("height: {height}px;".format(height=height))
Exemplo n.º 17
0
    def pixmap(self, column):
        """
        Return the pixmap for the given column.

        :type column: int
        :rtype: QtWidgets.QPixmap
        """

        if not self._pixmap.get(column):

            icon = self.icon(column)
            if icon:
                size = QtCore.QSize(self.MAX_ICON_SIZE, self.MAX_ICON_SIZE)
                iconSize = icon.actualSize(size)
                self._pixmap[column] = icon.pixmap(iconSize)

        return self._pixmap.get(column)
Exemplo n.º 18
0
    def createPixmap(self, path, color):
        """
        Create a new Pixmap from the given path.

        :type path: str
        :type color: str or QtCore.QColor
        :rtype: QtCore.QPixmap
        """
        dpi = self.treeWidget().dpi()
        key = path + color + "DPI-" + str(dpi)
        pixmap = self.PIXMAP_CACHE.get(key)

        if not pixmap:

            width = 20 * dpi
            height = 18 * dpi

            if "/" not in path and "\\" not in path:
                path = studiolibrary.resource.get("icons", path)

            if not os.path.exists(path):
                path = self.defaultIconPath()

            pixmap2 = studioqt.Pixmap(path)
            pixmap2.setColor(color)
            pixmap2 = pixmap2.scaled(
                16 * dpi,
                16 * dpi,
                QtCore.Qt.KeepAspectRatio,
                QtCore.Qt.SmoothTransformation
            )

            x = (width - pixmap2.width()) / 2
            y = (height - pixmap2.height()) / 2

            pixmap = QtGui.QPixmap(QtCore.QSize(width, height))
            pixmap.fill(QtCore.Qt.transparent)

            painter = QtGui.QPainter(pixmap)
            painter.drawPixmap(x, y, pixmap2)
            painter.end()

            self.PIXMAP_CACHE[key] = pixmap

        return pixmap
Exemplo n.º 19
0
    def updateThumbnailSize(self):
        """
        Update the thumbnail button to the size of the widget.

        :rtype: None
        """
        width = self.width() - 5
        if width > 150:
            width = 150

        size = QtCore.QSize(width, width)

        self.ui.iconFrame.setMaximumSize(size)
        self.ui.iconGroup.setMaximumHeight(width)

        self.ui.sequenceWidget.setIconSize(size)
        self.ui.sequenceWidget.setMinimumSize(size)
        self.ui.sequenceWidget.setMaximumSize(size)
Exemplo n.º 20
0
    def setIconSize(self, size):
        """
        Set the icon size for the views.

        :type size: QtCore.QSize
        :rtype: None
        """
        self._iconSize = size

        if self.isItemTextVisible():
            w = size.width()
            h = size.width() + self.itemTextHeight()
            self._itemSizeHint = QtCore.QSize(w, h)
        else:
            self._itemSizeHint = size

        self._listView.setIconSize(size)
        self._treeWidget.setIconSize(size)
Exemplo n.º 21
0
    def resizeEvent(self, event):
        """
        Reimplemented so the icon maintains the same height as the widget.

        :type event:  QtWidgets.QResizeEvent
        :rtype: None
        """
        QtWidgets.QLineEdit.resizeEvent(self, event)

        self.setTextMargins(self.height(), 0, 0, 0)
        size = QtCore.QSize(self.height(), self.height())

        self._iconButton.setIconSize(size)
        self._iconButton.setFixedSize(size)

        self._clearButton.setIconSize(size)

        x = self.width() - self.height()
        self._clearButton.setGeometry(x, 0, self.height(), self.height())
Exemplo n.º 22
0
    def setColor(self, color, size=None):
        """
        :type color: QtGui.QColor
        :rtype: None
        """
        icon = self
        size = size or icon.actualSize(QtCore.QSize(256, 256))
        pixmap = icon.pixmap(size)

        if not self.isNull():
            painter = QtGui.QPainter(pixmap)
            painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceIn)
            painter.setBrush(color)
            painter.setPen(color)
            painter.drawRect(pixmap.rect())
            painter.end()

        icon = QtGui.QIcon(pixmap)
        self.swap(icon)