17 from E5Gui.E5Application import e5App |
19 from E5Gui.E5Application import e5App |
18 |
20 |
19 import UI.PixmapCache |
21 import UI.PixmapCache |
20 |
22 |
21 |
23 |
|
24 class E5SideBarSide(enum.Enum): |
|
25 """ |
|
26 Class defining the sidebar sides. |
|
27 """ |
|
28 NORTH = 0 |
|
29 EAST = 1 |
|
30 SOUTH = 2 |
|
31 WEST = 3 |
|
32 |
|
33 |
22 class E5SideBar(QWidget): |
34 class E5SideBar(QWidget): |
23 """ |
35 """ |
24 Class implementing a sidebar with a widget area, that is hidden or shown, |
36 Class implementing a sidebar with a widget area, that is hidden or shown, |
25 if the current tab is clicked again. |
37 if the current tab is clicked again. |
26 """ |
38 """ |
27 Version = 2 |
39 Version = 2 |
28 |
40 |
29 North = 0 |
|
30 East = 1 |
|
31 South = 2 |
|
32 West = 3 |
|
33 |
|
34 def __init__(self, orientation=None, delay=200, parent=None): |
41 def __init__(self, orientation=None, delay=200, parent=None): |
35 """ |
42 """ |
36 Constructor |
43 Constructor |
37 |
44 |
38 @param orientation orientation of the sidebar widget (North, East, |
45 @param orientation orientation of the sidebar widget |
39 South, West) |
46 @type E5SideBarSide |
40 @param delay value for the expand/shrink delay in milliseconds |
47 @param delay value for the expand/shrink delay in milliseconds |
41 (integer) |
48 @type int |
42 @param parent parent widget (QWidget) |
49 @param parent parent widget |
|
50 @type QWidget |
43 """ |
51 """ |
44 super().__init__(parent) |
52 super().__init__(parent) |
45 |
53 |
46 self.__tabBar = QTabBar() |
54 self.__tabBar = QTabBar() |
47 self.__tabBar.setDrawBase(True) |
55 self.__tabBar.setDrawBase(True) |
87 # flag storing if this widget or any child has the focus |
95 # flag storing if this widget or any child has the focus |
88 self.__autoHide = False |
96 self.__autoHide = False |
89 |
97 |
90 self.__tabBar.installEventFilter(self) |
98 self.__tabBar.installEventFilter(self) |
91 |
99 |
92 self.__orientation = E5SideBar.North |
100 self.__orientation = E5SideBarSide.NORTH |
93 if orientation is None: |
101 if orientation is None: |
94 orientation = E5SideBar.North |
102 orientation = E5SideBarSide.NORTH |
95 self.setOrientation(orientation) |
103 self.setOrientation(orientation) |
96 |
104 |
97 self.__tabBar.currentChanged[int].connect( |
105 self.__tabBar.currentChanged[int].connect( |
98 self.__stackedWidget.setCurrentIndex) |
106 self.__stackedWidget.setCurrentIndex) |
99 e5App().focusChanged.connect(self.__appFocusChanged) |
107 e5App().focusChanged.connect(self.__appFocusChanged) |
166 """ |
174 """ |
167 Private method to shrink the sidebar. |
175 Private method to shrink the sidebar. |
168 """ |
176 """ |
169 self.__minimized = True |
177 self.__minimized = True |
170 self.__bigSize = self.size() |
178 self.__bigSize = self.size() |
171 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
179 if self.__orientation in (E5SideBarSide.NORTH, E5SideBarSide.SOUTH): |
172 self.__minSize = self.minimumSizeHint().height() |
180 self.__minSize = self.minimumSizeHint().height() |
173 self.__maxSize = self.maximumHeight() |
181 self.__maxSize = self.maximumHeight() |
174 else: |
182 else: |
175 self.__minSize = self.minimumSizeHint().width() |
183 self.__minSize = self.minimumSizeHint().width() |
176 self.__maxSize = self.maximumWidth() |
184 self.__maxSize = self.maximumWidth() |
177 if self.splitter: |
185 if self.splitter: |
178 self.splitterSizes = self.splitter.sizes() |
186 self.splitterSizes = self.splitter.sizes() |
179 |
187 |
180 self.__stackedWidget.hide() |
188 self.__stackedWidget.hide() |
181 |
189 |
182 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
190 if self.__orientation in (E5SideBarSide.NORTH, E5SideBarSide.SOUTH): |
183 self.setFixedHeight(self.__tabBar.minimumSizeHint().height()) |
191 self.setFixedHeight(self.__tabBar.minimumSizeHint().height()) |
184 else: |
192 else: |
185 self.setFixedWidth(self.__tabBar.minimumSizeHint().width()) |
193 self.setFixedWidth(self.__tabBar.minimumSizeHint().width()) |
186 |
194 |
187 self.__actionMethod = None |
195 self.__actionMethod = None |
199 Private method to expand the sidebar. |
207 Private method to expand the sidebar. |
200 """ |
208 """ |
201 self.__minimized = False |
209 self.__minimized = False |
202 self.__stackedWidget.show() |
210 self.__stackedWidget.show() |
203 self.resize(self.__bigSize) |
211 self.resize(self.__bigSize) |
204 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
212 if self.__orientation in (E5SideBarSide.NORTH, E5SideBarSide.SOUTH): |
205 minSize = max(self.__minSize, self.minimumSizeHint().height()) |
213 minSize = max(self.__minSize, self.minimumSizeHint().height()) |
206 self.setMinimumHeight(minSize) |
214 self.setMinimumHeight(minSize) |
207 self.setMaximumHeight(self.__maxSize) |
215 self.setMaximumHeight(self.__maxSize) |
208 else: |
216 else: |
209 minSize = max(self.__minSize, self.minimumSizeHint().width()) |
217 minSize = max(self.__minSize, self.minimumSizeHint().width()) |
278 self.__tabBar.setTabToolTip(index, label) |
286 self.__tabBar.setTabToolTip(index, label) |
279 else: |
287 else: |
280 index = self.__tabBar.addTab(iconOrLabel) |
288 index = self.__tabBar.addTab(iconOrLabel) |
281 self.__tabBar.setTabToolTip(index, iconOrLabel) |
289 self.__tabBar.setTabToolTip(index, iconOrLabel) |
282 self.__stackedWidget.addWidget(widget) |
290 self.__stackedWidget.addWidget(widget) |
283 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
291 if self.__orientation in (E5SideBarSide.NORTH, E5SideBarSide.SOUTH): |
284 self.__minSize = self.minimumSizeHint().height() |
292 self.__minSize = self.minimumSizeHint().height() |
285 else: |
293 else: |
286 self.__minSize = self.minimumSizeHint().width() |
294 self.__minSize = self.minimumSizeHint().width() |
287 |
295 |
288 def insertTab(self, index, widget, iconOrLabel, label=None): |
296 def insertTab(self, index, widget, iconOrLabel, label=None): |
301 self.__tabBar.setTabToolTip(index, label) |
309 self.__tabBar.setTabToolTip(index, label) |
302 else: |
310 else: |
303 index = self.__tabBar.insertTab(index, iconOrLabel) |
311 index = self.__tabBar.insertTab(index, iconOrLabel) |
304 self.__tabBar.setTabToolTip(index, iconOrLabel) |
312 self.__tabBar.setTabToolTip(index, iconOrLabel) |
305 self.__stackedWidget.insertWidget(index, widget) |
313 self.__stackedWidget.insertWidget(index, widget) |
306 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
314 if self.__orientation in (E5SideBarSide.NORTH, E5SideBarSide.SOUTH): |
307 self.__minSize = self.minimumSizeHint().height() |
315 self.__minSize = self.minimumSizeHint().height() |
308 else: |
316 else: |
309 self.__minSize = self.minimumSizeHint().width() |
317 self.__minSize = self.minimumSizeHint().width() |
310 |
318 |
311 def removeTab(self, index): |
319 def removeTab(self, index): |
426 |
434 |
427 def orientation(self): |
435 def orientation(self): |
428 """ |
436 """ |
429 Public method to get the orientation of the sidebar. |
437 Public method to get the orientation of the sidebar. |
430 |
438 |
431 @return orientation of the sidebar (North, East, South, West) |
439 @return orientation of the sidebar |
|
440 @rtype E5SideBarSide |
432 """ |
441 """ |
433 return self.__orientation |
442 return self.__orientation |
434 |
443 |
435 def setOrientation(self, orient): |
444 def setOrientation(self, orient): |
436 """ |
445 """ |
437 Public method to set the orientation of the sidebar. |
446 Public method to set the orientation of the sidebar. |
438 |
447 |
439 @param orient orientation of the sidebar (North, East, South, West) |
448 @param orient orientation of the sidebar |
440 """ |
449 @type E5SideBarSide |
441 if orient == E5SideBar.North: |
450 """ |
|
451 if orient == E5SideBarSide.NORTH: |
442 self.__tabBar.setShape(QTabBar.Shape.RoundedNorth) |
452 self.__tabBar.setShape(QTabBar.Shape.RoundedNorth) |
443 self.__tabBar.setSizePolicy( |
453 self.__tabBar.setSizePolicy( |
444 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
454 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
445 self.barLayout.setDirection(QBoxLayout.Direction.LeftToRight) |
455 self.barLayout.setDirection(QBoxLayout.Direction.LeftToRight) |
446 self.layout.setDirection(QBoxLayout.Direction.TopToBottom) |
456 self.layout.setDirection(QBoxLayout.Direction.TopToBottom) |
447 self.layout.setAlignment(self.barLayout, |
457 self.layout.setAlignment(self.barLayout, |
448 Qt.AlignmentFlag.AlignLeft) |
458 Qt.AlignmentFlag.AlignLeft) |
449 elif orient == E5SideBar.East: |
459 elif orient == E5SideBarSide.EAST: |
450 self.__tabBar.setShape(QTabBar.Shape.RoundedEast) |
460 self.__tabBar.setShape(QTabBar.Shape.RoundedEast) |
451 self.__tabBar.setSizePolicy( |
461 self.__tabBar.setSizePolicy( |
452 QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Expanding) |
462 QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Expanding) |
453 self.barLayout.setDirection(QBoxLayout.Direction.TopToBottom) |
463 self.barLayout.setDirection(QBoxLayout.Direction.TopToBottom) |
454 self.layout.setDirection(QBoxLayout.Direction.RightToLeft) |
464 self.layout.setDirection(QBoxLayout.Direction.RightToLeft) |
455 self.layout.setAlignment(self.barLayout, Qt.AlignmentFlag.AlignTop) |
465 self.layout.setAlignment(self.barLayout, Qt.AlignmentFlag.AlignTop) |
456 elif orient == E5SideBar.South: |
466 elif orient == E5SideBarSide.SOUTH: |
457 self.__tabBar.setShape(QTabBar.Shape.RoundedSouth) |
467 self.__tabBar.setShape(QTabBar.Shape.RoundedSouth) |
458 self.__tabBar.setSizePolicy( |
468 self.__tabBar.setSizePolicy( |
459 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
469 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) |
460 self.barLayout.setDirection(QBoxLayout.Direction.LeftToRight) |
470 self.barLayout.setDirection(QBoxLayout.Direction.LeftToRight) |
461 self.layout.setDirection(QBoxLayout.Direction.BottomToTop) |
471 self.layout.setDirection(QBoxLayout.Direction.BottomToTop) |
462 self.layout.setAlignment(self.barLayout, |
472 self.layout.setAlignment(self.barLayout, |
463 Qt.AlignmentFlag.AlignLeft) |
473 Qt.AlignmentFlag.AlignLeft) |
464 elif orient == E5SideBar.West: |
474 elif orient == E5SideBarSide.WEST: |
465 self.__tabBar.setShape(QTabBar.Shape.RoundedWest) |
475 self.__tabBar.setShape(QTabBar.Shape.RoundedWest) |
466 self.__tabBar.setSizePolicy( |
476 self.__tabBar.setSizePolicy( |
467 QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Expanding) |
477 QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Expanding) |
468 self.barLayout.setDirection(QBoxLayout.Direction.TopToBottom) |
478 self.barLayout.setDirection(QBoxLayout.Direction.TopToBottom) |
469 self.layout.setDirection(QBoxLayout.Direction.LeftToRight) |
479 self.layout.setDirection(QBoxLayout.Direction.LeftToRight) |
559 """ |
569 """ |
560 if len(self.splitterSizes) == 0: |
570 if len(self.splitterSizes) == 0: |
561 if self.splitter: |
571 if self.splitter: |
562 self.splitterSizes = self.splitter.sizes() |
572 self.splitterSizes = self.splitter.sizes() |
563 self.__bigSize = self.size() |
573 self.__bigSize = self.size() |
564 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
574 if self.__orientation in ( |
|
575 E5SideBarSide.NORTH, E5SideBarSide.SOUTH |
|
576 ): |
565 self.__minSize = self.minimumSizeHint().height() |
577 self.__minSize = self.minimumSizeHint().height() |
566 self.__maxSize = self.maximumHeight() |
578 self.__maxSize = self.maximumHeight() |
567 else: |
579 else: |
568 self.__minSize = self.minimumSizeHint().width() |
580 self.__minSize = self.minimumSizeHint().width() |
569 self.__maxSize = self.maximumWidth() |
581 self.__maxSize = self.maximumWidth() |