Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit columns #210

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions lisp/plugins/list_layout/list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
QTimer,
)
from PyQt5.QtGui import QKeyEvent, QContextMenuEvent, QBrush, QColor
from PyQt5.QtWidgets import QTreeWidget, QHeaderView, QTreeWidgetItem
from PyQt5.QtWidgets import QTreeWidget, QHeaderView, QTreeWidgetItem, QMenu

from lisp.application import Application
from lisp.backend import get_backend
Expand All @@ -44,12 +44,13 @@


class ListColumn:
def __init__(self, name, widget, resize=None, width=None, visible=True):
def __init__(self, name, widget, resize=None, width=None, displayName=True):
self.baseName = name
self.widget = widget
self.resize = resize
self.width = width
self.visible = visible
self.displayName = displayName
self.action = None

@property
def name(self):
Expand All @@ -72,7 +73,7 @@ class CueListView(QTreeWidget):
# TODO: add ability to show/hide
# TODO: implement columns (cue-type / target / etc..)
COLUMNS = [
ListColumn("", CueStatusIcons, QHeaderView.Fixed, width=45),
ListColumn(QT_TRANSLATE_NOOP("ListLayoutHeader", "Cue Status"), CueStatusIcons, QHeaderView.Fixed, width=45, displayName=False),
ListColumn("#", IndexWidget, QHeaderView.ResizeToContents),
ListColumn(
QT_TRANSLATE_NOOP("ListLayoutHeader", "Cue"),
Expand All @@ -88,7 +89,7 @@ class CueListView(QTreeWidget):
ListColumn(
QT_TRANSLATE_NOOP("ListLayoutHeader", "Post wait"), PostWaitWidget
),
ListColumn("", NextActionIcon, QHeaderView.Fixed, width=18),
ListColumn(QT_TRANSLATE_NOOP("ListLayoutHeader", "Next Action"), NextActionIcon, QHeaderView.Fixed, width=18, displayName=False),
]

ITEM_DEFAULT_BG = QBrush(Qt.transparent)
Expand All @@ -109,16 +110,30 @@ def __init__(self, listModel, parent=None):
self._model.item_removed.connect(self.__cueRemoved)
self._model.model_reset.connect(self.__modelReset)

# Create context menu for column headers
self.__columnMenu = QMenu()
self.__hideMenu = self.__columnMenu.addAction(QT_TRANSLATE_NOOP("ListLayoutHeaderMenu", "Hide"))
self.__showMenu = self.__columnMenu.addMenu(QT_TRANSLATE_NOOP("ListLayoutHeaderMenu","Show"))

# Setup the columns headers
self.setHeaderLabels((c.name for c in CueListView.COLUMNS))
self.setHeaderLabels((c.name if c.displayName else "" for c in CueListView.COLUMNS))
for i, column in enumerate(CueListView.COLUMNS):
if column.resize is not None:
self.header().setSectionResizeMode(i, column.resize)
if column.width is not None:
self.setColumnWidth(i, column.width)
# Create context menu to show the column
column.action = self.__showMenu.addAction(column.name)
column.action.triggered.connect(
lambda chk, item=i: self.showColumn(item))


self.header().setDragEnabled(False)
self.header().setDragEnabled(True)
self.header().setStretchLastSection(False)

# Connect local context menu for headers
self.header().setContextMenuPolicy(Qt.CustomContextMenu)
self.header().customContextMenuRequested.connect(self.__openHeaderMenu)

self.setDragDropMode(self.InternalMove)

Expand Down Expand Up @@ -323,3 +338,19 @@ def __updateScrollRange(self, min_, max_):
self.__scrollRangeGuard = True
self.verticalScrollBar().setMaximum(max_ + 1)
self.__scrollRangeGuard = False

def __openHeaderMenu(self, position):
# Prepare and open context menu
index = self.indexAt(position)
showShowMenu = False
for i, column in enumerate(CueListView.COLUMNS):
# show column name in menu if column is hidden
column.action.setVisible(self.isColumnHidden(i))
showShowMenu |= self.isColumnHidden(i)
self.__showMenu.menuAction().setVisible(showShowMenu)
action = self.__columnMenu.exec_(self.mapToGlobal(position))
if action == self.__hideMenu:
self.hideColumn(index.column())