eric7/EricWidgets/EricIconBar.py

branch
eric7
changeset 8772
70f9dfe7116a
parent 8768
09a4a3c5b161
child 8881
54e42bc2437a
equal deleted inserted replaced
8771:38d28ff97d4f 8772:70f9dfe7116a
122 if orientation != self.__orientation: 122 if orientation != self.__orientation:
123 self.setOrientation(orientation) 123 self.setOrientation(orientation)
124 124
125 self.setColor(self.__color) 125 self.setColor(self.__color)
126 126
127 self.__createMoreLabel() 127 self.__createAndAddMoreLabel()
128 self.__layout.insertWidget(0, self.__moreLabel)
129 128
130 self.__adjustIconLabels() 129 self.__adjustIconLabels()
131 130
132 def setOrientation(self, orientation): 131 def setOrientation(self, orientation):
133 """ 132 """
138 """ 137 """
139 # reset list widget size constraints 138 # reset list widget size constraints
140 self.setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX) 139 self.setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)
141 140
142 # remove the 'More' icon 141 # remove the 'More' icon
143 itm = self.__layout.takeAt(self.__layout.count() - 2) 142 itm = self.__layout.takeAt(self.__layout.count() - 1)
144 itm.widget().deleteLater() 143 itm.widget().deleteLater()
145 del itm 144 del itm
146 145
147 if orientation == Qt.Orientation.Horizontal: 146 if orientation == Qt.Orientation.Horizontal:
148 self.setFixedHeight(self.__fixedHeightWidth) 147 self.setFixedHeight(self.__fixedHeightWidth)
153 self.setMinimumHeight(self.__minimumHeightWidth) 152 self.setMinimumHeight(self.__minimumHeightWidth)
154 self.__layout.setDirection(QBoxLayout.Direction.TopToBottom) 153 self.__layout.setDirection(QBoxLayout.Direction.TopToBottom)
155 154
156 self.__orientation = orientation 155 self.__orientation = orientation
157 156
158 self.__createMoreLabel() 157 self.__createAndAddMoreLabel()
159 self.__layout.insertWidget(self.__layout.count() - 1, self.__moreLabel)
160 158
161 self.__adjustIconLabels() 159 self.__adjustIconLabels()
162 160
163 def orientation(self): 161 def orientation(self):
164 """ 162 """
176 @param barSize size category for the bar (one of 'xs', 'sm', 'md', 174 @param barSize size category for the bar (one of 'xs', 'sm', 'md',
177 'lg', 'xl', 'xxl') 175 'lg', 'xl', 'xxl')
178 @type str 176 @type str
179 """ 177 """
180 # remove the 'More' icon 178 # remove the 'More' icon
181 itm = self.__layout.takeAt(self.__layout.count() - 2) 179 itm = self.__layout.takeAt(self.__layout.count() - 1)
182 itm.widget().deleteLater() 180 itm.widget().deleteLater()
183 del itm 181 del itm
184 182
185 self.__barSize, self.__borderSize = ( 183 self.__barSize, self.__borderSize = (
186 EricIconBar.BarSizes[barSize][:2]) 184 EricIconBar.BarSizes[barSize][:2])
208 widget = iconLabel.widget() 206 widget = iconLabel.widget()
209 widget.setFixedSize(self.__barSize, self.__barSize) 207 widget.setFixedSize(self.__barSize, self.__barSize)
210 widget.setPixmap( 208 widget.setPixmap(
211 icon.pixmap(self.__barSize, self.__barSize)) 209 icon.pixmap(self.__barSize, self.__barSize))
212 210
213 self.__createMoreLabel() 211 self.__createAndAddMoreLabel()
214 self.__layout.insertWidget(self.__layout.count() - 1, self.__moreLabel)
215 212
216 self.__adjustIconLabels() 213 self.__adjustIconLabels()
217 214
218 def barSize(self): 215 def barSize(self):
219 """ 216 """
274 271
275 iconLabel.clicked.connect(lambda: self.__iconClicked(iconLabel)) 272 iconLabel.clicked.connect(lambda: self.__iconClicked(iconLabel))
276 273
277 return iconLabel 274 return iconLabel
278 275
279 def __createMoreLabel(self): 276 def __createAndAddMoreLabel(self):
280 """ 277 """
281 Private method to create the label to be shown for too many icons. 278 Private method to create the label to be shown for too many icons.
282 """ 279 """
283 self.__moreLabel = EricClickableLabel(self) 280 self.__moreLabel = EricClickableLabel(self)
284 self.__moreLabel.setAlignment(Qt.AlignmentFlag.AlignCenter) 281 self.__moreLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
297 UI.PixmapCache.getIcon("sbDotsV96").pixmap( 294 UI.PixmapCache.getIcon("sbDotsV96").pixmap(
298 self.__barSize, int(self.__barSize * self.MoreLabelAspect) 295 self.__barSize, int(self.__barSize * self.MoreLabelAspect)
299 ) 296 )
300 ) 297 )
301 298
299 self.__layout.addWidget(self.__moreLabel)
300
302 self.__moreLabel.clicked.connect(self.__moreLabelClicked) 301 self.__moreLabel.clicked.connect(self.__moreLabelClicked)
303 302
304 def addIcon(self, icon, label=""): 303 def addIcon(self, icon, label=""):
305 """ 304 """
306 Public method to add an icon to the bar. 305 Public method to add an icon to the bar.
468 QPalette.ColorRole.Highlight) 467 QPalette.ColorRole.Highlight)
469 menu.setStyleSheet( 468 menu.setStyleSheet(
470 EricIconBar.MenuStyleSheetTemplate.format( 469 EricIconBar.MenuStyleSheetTemplate.format(
471 baseColor.name(), highlightColor.name())) 470 baseColor.name(), highlightColor.name()))
472 471
473 for index in range(self.__layout.count() - 2): 472 for index in range(self.count()):
474 iconLabel = self.__layout.itemAt(index) 473 iconLabel = self.__layout.itemAt(index)
475 if iconLabel: 474 if iconLabel:
476 widget = iconLabel.widget() 475 widget = iconLabel.widget()
477 if not widget.isVisible(): 476 if not widget.isVisible():
478 act = menu.addAction(widget.toolTip()) 477 act = menu.addAction(widget.toolTip())
504 self.width() 503 self.width()
505 if self.orientation() == Qt.Orientation.Horizontal else 504 if self.orientation() == Qt.Orientation.Horizontal else
506 self.height() 505 self.height()
507 ) - 2 * self.__borderSize 506 ) - 2 * self.__borderSize
508 507
509 iconsSize = ( 508 iconsSize = self.count() * self.__barSize
510 self.count() * self.__barSize +
511 (self.count() - 1) * self.__layout.spacing()
512 )
513 509
514 if size < iconsSize: 510 if size < iconsSize:
515 self.__moreLabel.show() 511 self.__moreLabel.show()
516 iconsSize += int(self.__barSize * self.MoreLabelAspect) 512 iconsSize += int(self.__barSize * self.MoreLabelAspect)
517 for index in range(self.count() - 1, -1, -1): 513 for index in range(self.count() - 1, -1, -1):
518 iconLabel = self.__layout.itemAt(index) 514 iconLabel = self.__layout.itemAt(index)
519 if iconLabel: 515 if iconLabel:
520 if size < iconsSize: 516 if size < iconsSize:
521 iconLabel.widget().hide() 517 iconLabel.widget().hide()
522 iconsSize -= self.__barSize - self.__layout.spacing() 518 iconsSize -= self.__barSize
523 else: 519 else:
524 iconLabel.widget().show() 520 iconLabel.widget().show()
525 else: 521 else:
526 self.__moreLabel.hide() 522 self.__moreLabel.hide()
527 for index in range(self.__layout.count() - 2): 523 for index in range(self.count()):
528 iconLabel = self.__layout.itemAt(index) 524 iconLabel = self.__layout.itemAt(index)
529 if iconLabel: 525 if iconLabel:
530 iconLabel.widget().show() 526 iconLabel.widget().show()

eric ide

mercurial