mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 12:54:40 +01:00
draw a lock next to version if is locked
This commit is contained in:
parent
2fbb6c279b
commit
d96e8087ec
1 changed files with 31 additions and 2 deletions
|
|
@ -1,10 +1,14 @@
|
|||
from qtpy import QtWidgets, QtCore, QtGui
|
||||
|
||||
from .model import VERSION_LABEL_ROLE
|
||||
from ayon_core.tools.utils import get_qt_icon
|
||||
|
||||
from .model import VERSION_LABEL_ROLE, CONTAINER_VERSION_LOCKED_ROLE
|
||||
|
||||
|
||||
class VersionDelegate(QtWidgets.QStyledItemDelegate):
|
||||
"""A delegate that display version integer formatted as version string."""
|
||||
_locked_icon = None
|
||||
|
||||
def paint(self, painter, option, index):
|
||||
fg_color = index.data(QtCore.Qt.ForegroundRole)
|
||||
if fg_color:
|
||||
|
|
@ -45,10 +49,35 @@ class VersionDelegate(QtWidgets.QStyledItemDelegate):
|
|||
QtWidgets.QStyle.PM_FocusFrameHMargin, option, option.widget
|
||||
) + 1
|
||||
|
||||
text_rect_f = text_rect.adjusted(
|
||||
text_margin, 0, - text_margin, 0
|
||||
)
|
||||
|
||||
painter.drawText(
|
||||
text_rect.adjusted(text_margin, 0, - text_margin, 0),
|
||||
text_rect_f,
|
||||
option.displayAlignment,
|
||||
text
|
||||
)
|
||||
if index.data(CONTAINER_VERSION_LOCKED_ROLE) is True:
|
||||
icon = self._get_locked_icon()
|
||||
size = max(text_rect_f.height() // 2, 16)
|
||||
margin = (text_rect_f.height() - size) // 2
|
||||
|
||||
icon_rect = QtCore.QRect(
|
||||
text_rect_f.right() - size,
|
||||
text_rect_f.top() + margin,
|
||||
size,
|
||||
size
|
||||
)
|
||||
icon.paint(painter, icon_rect)
|
||||
|
||||
painter.restore()
|
||||
|
||||
def _get_locked_icon(cls):
|
||||
if cls._locked_icon is None:
|
||||
cls._locked_icon = get_qt_icon({
|
||||
"type": "material-symbols",
|
||||
"name": "lock",
|
||||
"color": "white",
|
||||
})
|
||||
return cls._locked_icon
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue