mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
initial logic for status icons
This commit is contained in:
parent
c5bc4ffc88
commit
12494d3982
2 changed files with 34 additions and 6 deletions
|
|
@ -126,6 +126,7 @@ class ProductsModel(QtGui.QStandardItemModel):
|
|||
self._last_project_name = None
|
||||
self._last_folder_ids = []
|
||||
self._last_project_statuses = {}
|
||||
self._last_status_icons_by_name = {}
|
||||
|
||||
def get_product_item_indexes(self):
|
||||
return [
|
||||
|
|
@ -181,6 +182,13 @@ class ProductsModel(QtGui.QStandardItemModel):
|
|||
return status_item.color
|
||||
|
||||
col = index.column()
|
||||
if col == self.status_col and role == QtCore.Qt.DecorationRole:
|
||||
role = VERSION_STATUS_ICON_ROLE
|
||||
|
||||
if role == VERSION_STATUS_ICON_ROLE:
|
||||
status_name = self.data(index, VERSION_STATUS_NAME_ROLE)
|
||||
return self._get_status_icon(status_name)
|
||||
|
||||
if col == 0:
|
||||
return super(ProductsModel, self).data(index, role)
|
||||
|
||||
|
|
@ -258,6 +266,24 @@ class ProductsModel(QtGui.QStandardItemModel):
|
|||
break
|
||||
yield color
|
||||
|
||||
def _get_status_icon(self, status_name):
|
||||
icon = self._last_status_icons_by_name.get(status_name)
|
||||
if icon is not None:
|
||||
return icon
|
||||
|
||||
status_item = self._last_project_statuses.get(status_name)
|
||||
if status_item is not None:
|
||||
icon = get_qt_icon({
|
||||
"type": "material-symbols",
|
||||
"name": status_item.icon,
|
||||
"color": status_item.color,
|
||||
})
|
||||
if icon is None:
|
||||
icon = QtGui.QIcon()
|
||||
|
||||
self._last_status_icons_by_name[status_name] = icon
|
||||
return icon
|
||||
|
||||
def _clear(self):
|
||||
root_item = self.invisibleRootItem()
|
||||
root_item.removeRows(0, root_item.rowCount())
|
||||
|
|
@ -331,6 +357,7 @@ class ProductsModel(QtGui.QStandardItemModel):
|
|||
)
|
||||
model_item.setData(version_item.author, VERSION_AUTHOR_ROLE)
|
||||
model_item.setData(version_item.status, VERSION_STATUS_NAME_ROLE)
|
||||
model_item.setData(version_item.status_short, VERSION_STATUS_ICON_ROLE)
|
||||
model_item.setData(version_item.frame_range, VERSION_FRAME_RANGE_ROLE)
|
||||
model_item.setData(version_item.duration, VERSION_DURATION_ROLE)
|
||||
model_item.setData(version_item.handles, VERSION_HANDLES_ROLE)
|
||||
|
|
@ -417,6 +444,7 @@ class ProductsModel(QtGui.QStandardItemModel):
|
|||
status_item.name: status_item
|
||||
for status_item in status_items
|
||||
}
|
||||
self._last_status_icons_by_name = {}
|
||||
|
||||
active_site_icon_def = self._controller.get_active_site_icon_def(
|
||||
project_name
|
||||
|
|
|
|||
|
|
@ -139,22 +139,22 @@ class StatusDelegate(QtWidgets.QStyledItemDelegate):
|
|||
|
||||
painter.save()
|
||||
|
||||
text_rect = style.subElementRect(
|
||||
content_rect = style.subElementRect(
|
||||
QtWidgets.QCommonStyle.SE_ItemViewItemText,
|
||||
option
|
||||
)
|
||||
text_margin = style.proxy().pixelMetric(
|
||||
content_margin = style.proxy().pixelMetric(
|
||||
QtWidgets.QCommonStyle.PM_FocusFrameHMargin,
|
||||
option,
|
||||
option.widget
|
||||
) + 1
|
||||
padded_text_rect = text_rect.adjusted(
|
||||
text_margin, 0, - text_margin, 0
|
||||
padded_content_rect = content_rect.adjusted(
|
||||
content_margin, 0, - content_margin, 0
|
||||
)
|
||||
|
||||
fm = QtGui.QFontMetrics(option.font)
|
||||
text = self._get_status_name(index)
|
||||
if padded_text_rect.width() < fm.width(text):
|
||||
if padded_content_rect.width() < fm.width(text):
|
||||
text = self._get_status_short_name(index)
|
||||
|
||||
fg_color = self._get_status_color(index)
|
||||
|
|
@ -163,7 +163,7 @@ class StatusDelegate(QtWidgets.QStyledItemDelegate):
|
|||
painter.setPen(pen)
|
||||
|
||||
painter.drawText(
|
||||
padded_text_rect,
|
||||
padded_content_rect,
|
||||
option.displayAlignment,
|
||||
text
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue