loader uses generic status delegate

This commit is contained in:
Jakub Trllo 2024-05-29 15:18:11 +02:00
parent daadddf8a4
commit 5fdc433c22
3 changed files with 24 additions and 69 deletions

View file

@ -6,9 +6,6 @@ from ayon_core.tools.utils.lib import format_version
from .products_model import (
PRODUCT_ID_ROLE,
VERSION_NAME_EDIT_ROLE,
VERSION_STATUS_NAME_ROLE,
VERSION_STATUS_SHORT_ROLE,
VERSION_STATUS_COLOR_ROLE,
VERSION_ID_ROLE,
PRODUCT_IN_SCENE_ROLE,
ACTIVE_SITE_ICON_ROLE,
@ -205,57 +202,6 @@ class LoadedInSceneDelegate(QtWidgets.QStyledItemDelegate):
option.palette.setBrush(QtGui.QPalette.Text, color)
class StatusDelegate(QtWidgets.QStyledItemDelegate):
"""Delegate showing status name and short name."""
def paint(self, painter, option, index):
if option.widget:
style = option.widget.style()
else:
style = QtWidgets.QApplication.style()
style.drawControl(
QtWidgets.QCommonStyle.CE_ItemViewItem,
option,
painter,
option.widget
)
painter.save()
text_rect = style.subElementRect(
QtWidgets.QCommonStyle.SE_ItemViewItemText,
option
)
text_margin = style.proxy().pixelMetric(
QtWidgets.QCommonStyle.PM_FocusFrameHMargin,
option,
option.widget
) + 1
padded_text_rect = text_rect.adjusted(
text_margin, 0, - text_margin, 0
)
fm = QtGui.QFontMetrics(option.font)
text = index.data(VERSION_STATUS_NAME_ROLE)
if padded_text_rect.width() < fm.width(text):
text = index.data(VERSION_STATUS_SHORT_ROLE)
status_color = index.data(VERSION_STATUS_COLOR_ROLE)
fg_color = QtGui.QColor(status_color)
pen = painter.pen()
pen.setColor(fg_color)
painter.setPen(pen)
painter.drawText(
padded_text_rect,
option.displayAlignment,
text
)
painter.restore()
class SiteSyncDelegate(QtWidgets.QStyledItemDelegate):
"""Paints icons and downloaded representation ration for both sites."""

View file

@ -25,18 +25,19 @@ VERSION_PUBLISH_TIME_ROLE = QtCore.Qt.UserRole + 14
VERSION_STATUS_NAME_ROLE = QtCore.Qt.UserRole + 15
VERSION_STATUS_SHORT_ROLE = QtCore.Qt.UserRole + 16
VERSION_STATUS_COLOR_ROLE = QtCore.Qt.UserRole + 17
VERSION_AUTHOR_ROLE = QtCore.Qt.UserRole + 18
VERSION_FRAME_RANGE_ROLE = QtCore.Qt.UserRole + 19
VERSION_DURATION_ROLE = QtCore.Qt.UserRole + 20
VERSION_HANDLES_ROLE = QtCore.Qt.UserRole + 21
VERSION_STEP_ROLE = QtCore.Qt.UserRole + 22
VERSION_AVAILABLE_ROLE = QtCore.Qt.UserRole + 23
VERSION_THUMBNAIL_ID_ROLE = QtCore.Qt.UserRole + 24
ACTIVE_SITE_ICON_ROLE = QtCore.Qt.UserRole + 25
REMOTE_SITE_ICON_ROLE = QtCore.Qt.UserRole + 26
REPRESENTATIONS_COUNT_ROLE = QtCore.Qt.UserRole + 27
SYNC_ACTIVE_SITE_AVAILABILITY = QtCore.Qt.UserRole + 28
SYNC_REMOTE_SITE_AVAILABILITY = QtCore.Qt.UserRole + 29
VERSION_STATUS_ICON_ROLE = QtCore.Qt.UserRole + 18
VERSION_AUTHOR_ROLE = QtCore.Qt.UserRole + 19
VERSION_FRAME_RANGE_ROLE = QtCore.Qt.UserRole + 20
VERSION_DURATION_ROLE = QtCore.Qt.UserRole + 21
VERSION_HANDLES_ROLE = QtCore.Qt.UserRole + 22
VERSION_STEP_ROLE = QtCore.Qt.UserRole + 23
VERSION_AVAILABLE_ROLE = QtCore.Qt.UserRole + 24
VERSION_THUMBNAIL_ID_ROLE = QtCore.Qt.UserRole + 25
ACTIVE_SITE_ICON_ROLE = QtCore.Qt.UserRole + 26
REMOTE_SITE_ICON_ROLE = QtCore.Qt.UserRole + 27
REPRESENTATIONS_COUNT_ROLE = QtCore.Qt.UserRole + 28
SYNC_ACTIVE_SITE_AVAILABILITY = QtCore.Qt.UserRole + 29
SYNC_REMOTE_SITE_AVAILABILITY = QtCore.Qt.UserRole + 30
class ProductsModel(QtGui.QStandardItemModel):

View file

@ -6,7 +6,7 @@ from ayon_core.tools.utils import (
RecursiveSortFilterProxyModel,
DeselectableTreeView,
)
from ayon_core.tools.utils.delegates import PrettyTimeDelegate
from ayon_core.tools.utils.delegates import PrettyTimeDelegate, StatusDelegate
from .products_model import (
ProductsModel,
@ -17,12 +17,15 @@ from .products_model import (
FOLDER_ID_ROLE,
PRODUCT_ID_ROLE,
VERSION_ID_ROLE,
VERSION_STATUS_NAME_ROLE,
VERSION_STATUS_SHORT_ROLE,
VERSION_STATUS_COLOR_ROLE,
VERSION_STATUS_ICON_ROLE,
VERSION_THUMBNAIL_ID_ROLE,
)
from .products_delegates import (
VersionDelegate,
LoadedInSceneDelegate,
StatusDelegate,
SiteSyncDelegate,
)
from .actions_utils import show_actions_menu
@ -131,7 +134,12 @@ class ProductsWidget(QtWidgets.QWidget):
version_delegate = VersionDelegate()
time_delegate = PrettyTimeDelegate()
status_delegate = StatusDelegate()
status_delegate = StatusDelegate(
VERSION_STATUS_NAME_ROLE,
VERSION_STATUS_SHORT_ROLE,
VERSION_STATUS_COLOR_ROLE,
VERSION_STATUS_ICON_ROLE,
)
in_scene_delegate = LoadedInSceneDelegate()
sitesync_delegate = SiteSyncDelegate()