This repository was archived by the owner on Mar 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathWorkspaceListDelegate.py
173 lines (148 loc) · 5.23 KB
/
WorkspaceListDelegate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import Utils
from PySide import QtCore
# import os
# from datetime import datetime
# import json
# import shutil
# import re
# import requests
# import uuid
# import base64
# import webbrowser
# from inspect import cleandoc
# import jwt
# from jwt.exceptions import ExpiredSignatureError
# import FreeCAD
# import FreeCADGui as Gui
# import AddonManager
# from DataModels import (
# WorkspaceListModel,
# CACHE_PATH,
# getBookmarkModel,
# ROLE_TYPE,
# TYPE_ORG,
# TYPE_BOOKMARK,
# ROLE_SHARE_MODEL_ID,
# )
# from VersionModel import OndselVersionModel
# from LinkModel import ShareLinkModel
# from APIClient import (
# APIClient,
# APIClientException,
# APIClientAuthenticationException,
# APIClientConnectionError,
# APIClientRequestException,
# )
# from Workspace import (
# WorkspaceModel,
# LocalWorkspaceModel,
# ServerWorkspaceModel,
# FileStatus,
# )
from PySide.QtGui import QStyledItemDelegate, QStyle
# from PySide.QtCore import QByteArray
# from PySide.QtWidgets import QTreeView
# import IntegrationStart
logger = Utils.getLogger(__name__)
class WorkspaceListDelegate(QStyledItemDelegate):
def getOrganizationText(self, workspaceData):
organizationData = workspaceData.get("organization")
if organizationData:
organizationName = organizationData.get("name")
if organizationName:
return f"({organizationName})"
else:
logger.debug("No 'name' in organization'")
else:
logger.debug("No 'organization' in workspaceData")
return ""
def paint(self, painter, option, index):
# Get the data for the current index
workspaceData = index.data(QtCore.Qt.DisplayRole)
if option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight())
# Set up font for the name (bold)
name_font = painter.font()
name_font.setBold(True)
# Set up font for the type (normal)
type_font = painter.font()
type_font.setBold(False)
# Draw the name
name_rect = QtCore.QRect(
option.rect.left() + 20,
option.rect.top(),
option.rect.width() - 20,
option.rect.height() // 3,
)
painter.setFont(name_font)
painter.drawText(
name_rect,
QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter,
workspaceData["name"],
)
# Calculate the width of the name text
name_width = painter.fontMetrics().boundingRect(workspaceData["name"]).width()
# Draw the organization in parentheses TODO : name and not the id.
type_text = self.getOrganizationText(workspaceData)
type_rect = QtCore.QRect(
option.rect.left() + 20 + name_width + 5,
option.rect.top(),
option.rect.width() - 20,
option.rect.height() // 3,
)
painter.setFont(type_font)
painter.drawText(
type_rect, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, type_text
)
# Adjust the height of the item
item_height = option.rect.height() // 3
name_rect.setHeight(item_height)
type_rect.setHeight(item_height)
# Draw the description
desc_rect = QtCore.QRect(
option.rect.left() + 20,
type_rect.bottom(),
option.rect.width() - 20,
item_height,
)
painter.drawText(
desc_rect,
QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter,
workspaceData["description"],
)
# Draw the button
# button_rect = QtCore.QRect(
# option.rect.right() - 80, # Adjust position as needed
# option.rect.top() + 10, # Adjust position as needed
# 70, 30 # Width and height of the button
# )
# painter.save()
# painter.setPen(QtCore.Qt.NoPen)
# painter.setBrush(QtCore.Qt.lightGray) # Button color
# painter.drawRoundedRect(button_rect, 5, 5)
# painter.restore()
# # Draw button text
# painter.setFont(type_font)
# painter.drawText(
# button_rect,
# QtCore.Qt.AlignCenter,
# "Enter"
# )
def sizeHint(self, option, index):
return QtCore.QSize(100, 60) # Adjust the desired width and height
# def editorEvent(self, event, model, option, index):
# # Check if the event is a mouse button release
# if event.type() == QtCore.QEvent.MouseButtonRelease:
# # Define the button rect same as in the paint method
# button_rect = QtCore.QRect(
# option.rect.right() - 80,
# option.rect.top() + 10,
# 70, 30
# )
# # Check if the click was within the button rect
# if button_rect.contains(event.pos()):
# # Handle button click here
# logger.debug("Button clicked for item:", index.row())
# return True # Event was handled
# return super(WorkspaceListDelegate, self).editorEvent(event, model,
# option, index)