35 |
35 |
36 @param parent reference to the parent object (QObject) |
36 @param parent reference to the parent object (QObject) |
37 """ |
37 """ |
38 super(GreaseMonkeyConfigurationListDelegate, self).__init__(parent) |
38 super(GreaseMonkeyConfigurationListDelegate, self).__init__(parent) |
39 |
39 |
40 self.__removePixmap = \ |
40 self.__removePixmap = UI.PixmapCache.getIcon( |
41 UI.PixmapCache.getIcon("greaseMonkeyTrash.png").pixmap( |
41 "greaseMonkeyTrash.png").pixmap( |
42 GreaseMonkeyConfigurationListDelegate.RemoveIconSize) |
42 GreaseMonkeyConfigurationListDelegate.RemoveIconSize) |
43 self.__rowHeight = 0 |
43 self.__rowHeight = 0 |
44 self.__padding = 0 |
44 self.__padding = 0 |
45 |
45 |
46 def padding(self): |
46 def padding(self): |
74 |
74 |
75 titleMetrics = QFontMetrics(titleFont) |
75 titleMetrics = QFontMetrics(titleFont) |
76 if Globals.isWindowsPlatform(): |
76 if Globals.isWindowsPlatform(): |
77 colorRole = QPalette.Text |
77 colorRole = QPalette.Text |
78 else: |
78 else: |
79 colorRole = QPalette.HighlightedText \ |
79 colorRole = ( |
|
80 QPalette.HighlightedText |
80 if opt.state & QStyle.State_Selected else QPalette.Text |
81 if opt.state & QStyle.State_Selected else QPalette.Text |
|
82 ) |
81 |
83 |
82 leftPos = self.__padding |
84 leftPos = self.__padding |
83 rightPos = opt.rect.right() - self.__padding - \ |
85 rightPos = ( |
|
86 opt.rect.right() - self.__padding - |
84 GreaseMonkeyConfigurationListDelegate.RemoveIconSize |
87 GreaseMonkeyConfigurationListDelegate.RemoveIconSize |
|
88 ) |
85 |
89 |
86 # Draw background |
90 # Draw background |
87 style.drawPrimitive(QStyle.PE_PanelItemViewItem, opt, painter, widget) |
91 style.drawPrimitive(QStyle.PE_PanelItemViewItem, opt, painter, widget) |
88 |
92 |
89 # Draw checkbox |
93 # Draw checkbox |
90 checkBoxYPos = center - \ |
94 checkBoxYPos = ( |
|
95 center - |
91 GreaseMonkeyConfigurationListDelegate.CheckBoxSize // 2 |
96 GreaseMonkeyConfigurationListDelegate.CheckBoxSize // 2 |
|
97 ) |
92 opt2 = QStyleOptionViewItem(opt) |
98 opt2 = QStyleOptionViewItem(opt) |
93 if opt2.checkState == Qt.Checked: |
99 if opt2.checkState == Qt.Checked: |
94 opt2.state |= QStyle.State_On |
100 opt2.state |= QStyle.State_On |
95 else: |
101 else: |
96 opt2.state |= QStyle.State_Off |
102 opt2.state |= QStyle.State_Off |
144 painter.setFont(opt.font) |
150 painter.setFont(opt.font) |
145 style.drawItemText(painter, infoRect, Qt.AlignLeft | Qt.TextSingleLine, |
151 style.drawItemText(painter, infoRect, Qt.AlignLeft | Qt.TextSingleLine, |
146 opt.palette, True, info, colorRole) |
152 opt.palette, True, info, colorRole) |
147 |
153 |
148 # Draw remove button |
154 # Draw remove button |
149 removeIconYPos = center - \ |
155 removeIconYPos = ( |
|
156 center - |
150 GreaseMonkeyConfigurationListDelegate.RemoveIconSize // 2 |
157 GreaseMonkeyConfigurationListDelegate.RemoveIconSize // 2 |
|
158 ) |
151 removeIconRect = QRect( |
159 removeIconRect = QRect( |
152 rightPos, removeIconYPos, |
160 rightPos, removeIconYPos, |
153 GreaseMonkeyConfigurationListDelegate.RemoveIconSize, |
161 GreaseMonkeyConfigurationListDelegate.RemoveIconSize, |
154 GreaseMonkeyConfigurationListDelegate.RemoveIconSize) |
162 GreaseMonkeyConfigurationListDelegate.RemoveIconSize) |
155 painter.drawPixmap(removeIconRect, self.__removePixmap) |
163 painter.drawPixmap(removeIconRect, self.__removePixmap) |
165 if not self.__rowHeight: |
173 if not self.__rowHeight: |
166 opt = QStyleOptionViewItem(option) |
174 opt = QStyleOptionViewItem(option) |
167 self.initStyleOption(opt, index) |
175 self.initStyleOption(opt, index) |
168 |
176 |
169 widget = opt.widget |
177 widget = opt.widget |
170 style = widget.style() if widget is not None \ |
178 style = ( |
|
179 widget.style() if widget is not None |
171 else QApplication.style() |
180 else QApplication.style() |
|
181 ) |
172 padding = style.pixelMetric(QStyle.PM_FocusFrameHMargin) + 1 |
182 padding = style.pixelMetric(QStyle.PM_FocusFrameHMargin) + 1 |
173 |
183 |
174 titleFont = opt.font |
184 titleFont = opt.font |
175 titleFont.setBold(True) |
185 titleFont.setBold(True) |
176 titleFont.setPointSize(titleFont.pointSize() + 1) |
186 titleFont.setPointSize(titleFont.pointSize() + 1) |
177 |
187 |
178 self.__padding = padding \ |
188 self.__padding = ( |
179 if padding > GreaseMonkeyConfigurationListDelegate.MinPadding \ |
189 padding |
|
190 if padding > GreaseMonkeyConfigurationListDelegate.MinPadding |
180 else GreaseMonkeyConfigurationListDelegate.MinPadding |
191 else GreaseMonkeyConfigurationListDelegate.MinPadding |
|
192 ) |
181 |
193 |
182 titleMetrics = QFontMetrics(titleFont) |
194 titleMetrics = QFontMetrics(titleFont) |
183 |
195 |
184 self.__rowHeight = 2 * self.__padding + \ |
196 self.__rowHeight = ( |
185 opt.fontMetrics.leading() + \ |
197 2 * self.__padding + |
186 opt.fontMetrics.height() + \ |
198 opt.fontMetrics.leading() + |
|
199 opt.fontMetrics.height() + |
187 titleMetrics.height() |
200 titleMetrics.height() |
|
201 ) |
188 |
202 |
189 return QSize(GreaseMonkeyConfigurationListDelegate.ItemWidth, |
203 return QSize(GreaseMonkeyConfigurationListDelegate.ItemWidth, |
190 self.__rowHeight) |
204 self.__rowHeight) |