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

Sections #58

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ __pycache__
dist
cover
.coverage
build
build
.idea/
5 changes: 5 additions & 0 deletions pyblish_lite/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ QListView {
background: "transparent"
}

QTreeView {
border: 0px;
background: "transparent"
}

QPushButton {
width: 27px;
height: 27px;
Expand Down
60 changes: 60 additions & 0 deletions pyblish_lite/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,66 @@ def sizeHint(self, option, index):
return QtCore.QSize(option.rect.width(), 20)


class Section(QtWidgets.QStyledItemDelegate):
"""Generic delegate for section header"""

def paint(self, painter, option, index):
"""Paint text
_
My label

"""

body_rect = QtCore.QRectF(option.rect)

metrics = painter.fontMetrics()

label_rect = QtCore.QRectF(option.rect.adjusted(0, 2, 0, -2))

assert label_rect.width() > 0

label = index.data(model.Label)
label = metrics.elidedText(label,
QtCore.Qt.ElideRight,
label_rect.width())

font_color = colors["idle"]
if not index.data(model.IsChecked):
font_color = colors["inactive"]

# Maintain reference to state, so we can restore it once we're done
painter.save()

# Draw label
painter.setFont(fonts["h4"])
painter.setPen(QtGui.QPen(font_color))
painter.drawText(label_rect, label)

if option.state & QtWidgets.QStyle.State_MouseOver:
painter.fillRect(body_rect, colors["hover"])

if option.state & QtWidgets.QStyle.State_Selected:
painter.fillRect(body_rect, colors["selected"])

# Ok, we're done, tidy up.
painter.restore()

def sizeHint(self, option, index):
return QtCore.QSize(option.rect.width(), 20)


class ItemAndSection(Item):
"""Generic delegate for model items in proxy tree view"""
def paint(self, painter, option, index):

model = index.model()
if model.is_header(index):
Section().paint(painter, option, index)
return

super(ItemAndSection, self).paint(painter, option, index)


class Artist(QtWidgets.QStyledItemDelegate):
"""Delegate used on Artist page"""

Expand Down
2 changes: 2 additions & 0 deletions pyblish_lite/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
Label = QtCore.Qt.DisplayRole + 0
Families = QtCore.Qt.DisplayRole + 1
Icon = QtCore.Qt.DisplayRole + 13
Order = QtCore.Qt.UserRole + 62

# The item has not been used
IsIdle = QtCore.Qt.UserRole + 2
Expand Down Expand Up @@ -129,6 +130,7 @@ def __init__(self, parent=None):
Actions: "actions",
IsOptional: "optional",
Icon: "icon",
Order: "order",

# GUI-only data
Type: "_type",
Expand Down
Loading