71 titleFont.setBold(True) |
71 titleFont.setBold(True) |
72 titleFont.setPointSize(titleFont.pointSize() + 1) |
72 titleFont.setPointSize(titleFont.pointSize() + 1) |
73 |
73 |
74 titleMetrics = QFontMetrics(titleFont) |
74 titleMetrics = QFontMetrics(titleFont) |
75 if Globals.isWindowsPlatform(): |
75 if Globals.isWindowsPlatform(): |
76 colorRole = QPalette.Text |
76 colorRole = QPalette.ColorRole.Text |
77 else: |
77 else: |
78 colorRole = ( |
78 colorRole = ( |
79 QPalette.HighlightedText |
79 QPalette.ColorRole.HighlightedText |
80 if opt.state & QStyle.State_Selected else QPalette.Text |
80 if opt.state & QStyle.StateFlag.State_Selected else |
|
81 QPalette.ColorRole.Text |
81 ) |
82 ) |
82 |
83 |
83 leftPos = self.__padding |
84 leftPos = self.__padding |
84 rightPos = ( |
85 rightPos = ( |
85 opt.rect.right() - self.__padding - |
86 opt.rect.right() - self.__padding - |
86 GreaseMonkeyConfigurationListDelegate.RemoveIconSize |
87 GreaseMonkeyConfigurationListDelegate.RemoveIconSize |
87 ) |
88 ) |
88 |
89 |
89 # Draw background |
90 # Draw background |
90 style.drawPrimitive(QStyle.PE_PanelItemViewItem, opt, painter, widget) |
91 style.drawPrimitive( |
|
92 QStyle.PrimitiveElement.PE_PanelItemViewItem, opt, painter, widget) |
91 |
93 |
92 # Draw checkbox |
94 # Draw checkbox |
93 checkBoxYPos = ( |
95 checkBoxYPos = ( |
94 center - |
96 center - |
95 GreaseMonkeyConfigurationListDelegate.CheckBoxSize // 2 |
97 GreaseMonkeyConfigurationListDelegate.CheckBoxSize // 2 |
96 ) |
98 ) |
97 opt2 = QStyleOptionViewItem(opt) |
99 opt2 = QStyleOptionViewItem(opt) |
98 if opt2.checkState == Qt.Checked: |
100 if opt2.checkState == Qt.CheckState.Checked: |
99 opt2.state |= QStyle.State_On |
101 opt2.state |= QStyle.StateFlag.State_On |
100 else: |
102 else: |
101 opt2.state |= QStyle.State_Off |
103 opt2.state |= QStyle.StateFlag.State_Off |
102 styleCheckBoxRect = style.subElementRect( |
104 styleCheckBoxRect = style.subElementRect( |
103 QStyle.SE_ViewItemCheckIndicator, opt2, widget) |
105 QStyle.SubElement.SE_ViewItemCheckIndicator, opt2, widget) |
104 opt2.rect = QRect( |
106 opt2.rect = QRect( |
105 leftPos, checkBoxYPos, |
107 leftPos, checkBoxYPos, |
106 styleCheckBoxRect.width(), styleCheckBoxRect.height()) |
108 styleCheckBoxRect.width(), styleCheckBoxRect.height()) |
107 style.drawPrimitive(QStyle.PE_IndicatorViewItemCheck, opt2, painter, |
109 style.drawPrimitive( |
108 widget) |
110 QStyle.PrimitiveElement.PE_IndicatorViewItemCheck, opt2, painter, |
|
111 widget) |
109 leftPos = opt2.rect.right() + self.__padding |
112 leftPos = opt2.rect.right() + self.__padding |
110 |
113 |
111 # Draw icon |
114 # Draw icon |
112 iconYPos = center - GreaseMonkeyConfigurationListDelegate.IconSize // 2 |
115 iconYPos = center - GreaseMonkeyConfigurationListDelegate.IconSize // 2 |
113 iconRect = QRect(leftPos, iconYPos, |
116 iconRect = QRect(leftPos, iconYPos, |
114 GreaseMonkeyConfigurationListDelegate.IconSize, |
117 GreaseMonkeyConfigurationListDelegate.IconSize, |
115 GreaseMonkeyConfigurationListDelegate.IconSize) |
118 GreaseMonkeyConfigurationListDelegate.IconSize) |
116 pixmap = index.data(Qt.DecorationRole).pixmap( |
119 pixmap = index.data(Qt.ItemDataRole.DecorationRole).pixmap( |
117 GreaseMonkeyConfigurationListDelegate.IconSize) |
120 GreaseMonkeyConfigurationListDelegate.IconSize) |
118 painter.drawPixmap(iconRect, pixmap) |
121 painter.drawPixmap(iconRect, pixmap) |
119 leftPos = iconRect.right() + self.__padding |
122 leftPos = iconRect.right() + self.__padding |
120 |
123 |
121 # Draw script name |
124 # Draw script name |
122 name = index.data(Qt.DisplayRole) |
125 name = index.data(Qt.ItemDataRole.DisplayRole) |
123 leftTitleEdge = leftPos + 2 |
126 leftTitleEdge = leftPos + 2 |
124 rightTitleEdge = rightPos - self.__padding |
127 rightTitleEdge = rightPos - self.__padding |
125 try: |
128 try: |
126 leftPosForVersion = ( |
129 leftPosForVersion = ( |
127 titleMetrics.horizontalAdvance(name) + self.__padding |
130 titleMetrics.horizontalAdvance(name) + self.__padding |
129 except AttributeError: |
132 except AttributeError: |
130 leftPosForVersion = titleMetrics.width(name) + self.__padding |
133 leftPosForVersion = titleMetrics.width(name) + self.__padding |
131 nameRect = QRect(leftTitleEdge, opt.rect.top() + self.__padding, |
134 nameRect = QRect(leftTitleEdge, opt.rect.top() + self.__padding, |
132 rightTitleEdge - leftTitleEdge, titleMetrics.height()) |
135 rightTitleEdge - leftTitleEdge, titleMetrics.height()) |
133 painter.setFont(titleFont) |
136 painter.setFont(titleFont) |
134 style.drawItemText(painter, nameRect, Qt.AlignLeft, opt.palette, True, |
137 style.drawItemText( |
135 name, colorRole) |
138 painter, nameRect, |
|
139 Qt.AlignmentFlag.AlignLeft, opt.palette, True, |
|
140 name, colorRole) |
136 |
141 |
137 # Draw version |
142 # Draw version |
138 version = index.data(Qt.UserRole) |
143 version = index.data(Qt.ItemDataRole.UserRole) |
139 versionRect = QRect( |
144 versionRect = QRect( |
140 nameRect.x() + leftPosForVersion, nameRect.y(), |
145 nameRect.x() + leftPosForVersion, nameRect.y(), |
141 rightTitleEdge - leftTitleEdge, titleMetrics.height()) |
146 rightTitleEdge - leftTitleEdge, titleMetrics.height()) |
142 versionFont = titleFont |
147 versionFont = titleFont |
143 painter.setFont(versionFont) |
148 painter.setFont(versionFont) |
144 style.drawItemText(painter, versionRect, Qt.AlignLeft, opt.palette, |
149 style.drawItemText( |
145 True, version, colorRole) |
150 painter, versionRect, |
|
151 Qt.AlignmentFlag.AlignLeft, opt.palette, |
|
152 True, version, colorRole) |
146 |
153 |
147 # Draw description |
154 # Draw description |
148 infoYPos = nameRect.bottom() + opt.fontMetrics.leading() |
155 infoYPos = nameRect.bottom() + opt.fontMetrics.leading() |
149 infoRect = QRect( |
156 infoRect = QRect( |
150 nameRect.x(), infoYPos, |
157 nameRect.x(), infoYPos, |
151 nameRect.width(), opt.fontMetrics.height()) |
158 nameRect.width(), opt.fontMetrics.height()) |
152 info = opt.fontMetrics.elidedText( |
159 info = opt.fontMetrics.elidedText( |
153 index.data(Qt.UserRole + 1), Qt.ElideRight, infoRect.width()) |
160 index.data(Qt.ItemDataRole.UserRole + 1), |
|
161 Qt.TextElideMode.ElideRight, infoRect.width()) |
154 painter.setFont(opt.font) |
162 painter.setFont(opt.font) |
155 style.drawItemText(painter, infoRect, Qt.AlignLeft | Qt.TextSingleLine, |
163 style.drawItemText( |
156 opt.palette, True, info, colorRole) |
164 painter, infoRect, |
|
165 Qt.AlignmentFlag.AlignLeft | Qt.TextFlag.TextSingleLine, |
|
166 opt.palette, True, info, colorRole) |
157 |
167 |
158 # Draw remove button |
168 # Draw remove button |
159 removeIconYPos = ( |
169 removeIconYPos = ( |
160 center - |
170 center - |
161 GreaseMonkeyConfigurationListDelegate.RemoveIconSize // 2 |
171 GreaseMonkeyConfigurationListDelegate.RemoveIconSize // 2 |