From 5fdc433c22a30f716062cc52315ecd5bf1316f50 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 29 May 2024 15:18:11 +0200 Subject: [PATCH] loader uses generic status delegate --- .../tools/loader/ui/products_delegates.py | 54 ------------------- .../tools/loader/ui/products_model.py | 25 ++++----- .../tools/loader/ui/products_widget.py | 14 +++-- 3 files changed, 24 insertions(+), 69 deletions(-) diff --git a/client/ayon_core/tools/loader/ui/products_delegates.py b/client/ayon_core/tools/loader/ui/products_delegates.py index 1ac19b53eb..cedac6199b 100644 --- a/client/ayon_core/tools/loader/ui/products_delegates.py +++ b/client/ayon_core/tools/loader/ui/products_delegates.py @@ -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.""" diff --git a/client/ayon_core/tools/loader/ui/products_model.py b/client/ayon_core/tools/loader/ui/products_model.py index f309473d10..8035b1f0fe 100644 --- a/client/ayon_core/tools/loader/ui/products_model.py +++ b/client/ayon_core/tools/loader/ui/products_model.py @@ -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): diff --git a/client/ayon_core/tools/loader/ui/products_widget.py b/client/ayon_core/tools/loader/ui/products_widget.py index 3a30d83d52..61ddd690e9 100644 --- a/client/ayon_core/tools/loader/ui/products_widget.py +++ b/client/ayon_core/tools/loader/ui/products_widget.py @@ -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()