mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
variants are working now
This commit is contained in:
parent
0bda8c0d2f
commit
33ea814c89
3 changed files with 59 additions and 41 deletions
|
|
@ -6,13 +6,17 @@ class ActionDelegate(QtWidgets.QStyledItemDelegate):
|
|||
extender_bg_brush = QtGui.QBrush(QtGui.QColor(100, 100, 100, 160))
|
||||
extender_fg = QtGui.QColor(255, 255, 255, 160)
|
||||
|
||||
def __init__(self, group_role, *args, **kwargs):
|
||||
def __init__(self, group_roles, *args, **kwargs):
|
||||
super(ActionDelegate, self).__init__(*args, **kwargs)
|
||||
self.group_role = group_role
|
||||
self.group_roles = group_roles
|
||||
|
||||
def paint(self, painter, option, index):
|
||||
super(ActionDelegate, self).paint(painter, option, index)
|
||||
is_group = index.data(self.group_role)
|
||||
is_group = False
|
||||
for group_role in self.group_roles:
|
||||
is_group = index.data(group_role)
|
||||
if is_group:
|
||||
break
|
||||
if not is_group:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ class TaskModel(QtGui.QStandardItemModel):
|
|||
class ActionModel(QtGui.QStandardItemModel):
|
||||
ACTION_ROLE = QtCore.Qt.UserRole
|
||||
GROUP_ROLE = QtCore.Qt.UserRole + 1
|
||||
VARIANT_GROUP_ROLE = QtCore.Qt.UserRole + 2
|
||||
|
||||
def __init__(self, dbcon, parent=None):
|
||||
super(ActionModel, self).__init__(parent=parent)
|
||||
|
|
@ -200,7 +201,7 @@ class ActionModel(QtGui.QStandardItemModel):
|
|||
|
||||
item = QtGui.QStandardItem(icon, action.label)
|
||||
item.setData(actions, self.ACTION_ROLE)
|
||||
item.setData(True, self.GROUP_ROLE)
|
||||
item.setData(True, self.VARIANT_GROUP_ROLE)
|
||||
items_by_order[order].append(item)
|
||||
|
||||
for action in single_actions:
|
||||
|
|
|
|||
|
|
@ -95,7 +95,10 @@ class ActionBar(QtWidgets.QWidget):
|
|||
view.setModel(model)
|
||||
|
||||
# TODO better group delegate
|
||||
delegate = ActionDelegate(model.GROUP_ROLE, self)
|
||||
delegate = ActionDelegate(
|
||||
[model.GROUP_ROLE, model.VARIANT_GROUP_ROLE],
|
||||
self
|
||||
)
|
||||
view.setItemDelegate(delegate)
|
||||
|
||||
layout.addWidget(view)
|
||||
|
|
@ -119,58 +122,68 @@ class ActionBar(QtWidgets.QWidget):
|
|||
return
|
||||
|
||||
is_group = index.data(self.model.GROUP_ROLE)
|
||||
if not is_group:
|
||||
is_variant_group = index.data(self.model.VARIANT_GROUP_ROLE)
|
||||
if not is_group and not is_variant_group:
|
||||
action = index.data(self.model.ACTION_ROLE)
|
||||
self.action_clicked.emit(action)
|
||||
return
|
||||
|
||||
actions = index.data(self.model.ACTION_ROLE)
|
||||
by_variant_label = collections.defaultdict(list)
|
||||
orders = []
|
||||
for action in actions:
|
||||
# Lable variants
|
||||
label = getattr(action, "label", None)
|
||||
label_variant = getattr(action, "label_variant", None)
|
||||
if label_variant and not label:
|
||||
label_variant = None
|
||||
|
||||
if not label_variant:
|
||||
orders.append(action)
|
||||
continue
|
||||
|
||||
if label not in orders:
|
||||
orders.append(label)
|
||||
by_variant_label[label].append(action)
|
||||
|
||||
menu = QtWidgets.QMenu(self)
|
||||
actions_mapping = {}
|
||||
|
||||
for action_item in orders:
|
||||
actions = by_variant_label.get(action_item)
|
||||
if not actions:
|
||||
action = action_item
|
||||
elif len(actions) == 1:
|
||||
action = actions[0]
|
||||
else:
|
||||
action = None
|
||||
|
||||
if action:
|
||||
if is_variant_group:
|
||||
for action in actions:
|
||||
menu_action = QtWidgets.QAction(
|
||||
lib.get_action_label(action)
|
||||
)
|
||||
menu.addAction(menu_action)
|
||||
actions_mapping[menu_action] = action
|
||||
continue
|
||||
|
||||
sub_menu = QtWidgets.QMenu(label, menu)
|
||||
else:
|
||||
by_variant_label = collections.defaultdict(list)
|
||||
orders = []
|
||||
for action in actions:
|
||||
menu_action = QtWidgets.QAction(
|
||||
lib.get_action_label(action)
|
||||
)
|
||||
sub_menu.addAction(menu_action)
|
||||
actions_mapping[menu_action] = action
|
||||
# Lable variants
|
||||
label = getattr(action, "label", None)
|
||||
label_variant = getattr(action, "label_variant", None)
|
||||
if label_variant and not label:
|
||||
label_variant = None
|
||||
|
||||
menu.addMenu(sub_menu)
|
||||
if not label_variant:
|
||||
orders.append(action)
|
||||
continue
|
||||
|
||||
if label not in orders:
|
||||
orders.append(label)
|
||||
by_variant_label[label].append(action)
|
||||
|
||||
for action_item in orders:
|
||||
actions = by_variant_label.get(action_item)
|
||||
if not actions:
|
||||
action = action_item
|
||||
elif len(actions) == 1:
|
||||
action = actions[0]
|
||||
else:
|
||||
action = None
|
||||
|
||||
if action:
|
||||
menu_action = QtWidgets.QAction(
|
||||
lib.get_action_label(action)
|
||||
)
|
||||
menu.addAction(menu_action)
|
||||
actions_mapping[menu_action] = action
|
||||
continue
|
||||
|
||||
sub_menu = QtWidgets.QMenu(label, menu)
|
||||
for action in actions:
|
||||
menu_action = QtWidgets.QAction(
|
||||
lib.get_action_label(action)
|
||||
)
|
||||
sub_menu.addAction(menu_action)
|
||||
actions_mapping[menu_action] = action
|
||||
|
||||
menu.addMenu(sub_menu)
|
||||
|
||||
result = menu.exec_(QtGui.QCursor.pos())
|
||||
if result:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue