5 |
5 |
6 """ |
6 """ |
7 Module implementing a sidebar class. |
7 Module implementing a sidebar class. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtCore import QEvent, QSize, Qt, QByteArray, QDataStream, QIODevice, QTimer |
10 from PyQt4.QtCore import QEvent, QSize, Qt, QByteArray, QDataStream, \ |
11 from PyQt4.QtGui import QTabBar, QWidget, QStackedWidget, QBoxLayout, QToolButton, \ |
11 QIODevice, QTimer |
12 QSizePolicy |
12 from PyQt4.QtGui import QTabBar, QWidget, QStackedWidget, QBoxLayout, \ |
|
13 QToolButton, QSizePolicy |
13 |
14 |
14 from E5Gui.E5Application import e5App |
15 from E5Gui.E5Application import e5App |
15 |
16 |
16 import UI.PixmapCache |
17 import UI.PixmapCache |
17 |
18 |
18 |
19 |
19 class E5SideBar(QWidget): |
20 class E5SideBar(QWidget): |
20 """ |
21 """ |
21 Class implementing a sidebar with a widget area, that is hidden or shown, if the |
22 Class implementing a sidebar with a widget area, that is hidden or shown, |
22 current tab is clicked again. |
23 if the current tab is clicked again. |
23 """ |
24 """ |
24 Version = 1 |
25 Version = 1 |
25 |
26 |
26 North = 0 |
27 North = 0 |
27 East = 1 |
28 East = 1 |
30 |
31 |
31 def __init__(self, orientation=None, delay=200, parent=None): |
32 def __init__(self, orientation=None, delay=200, parent=None): |
32 """ |
33 """ |
33 Constructor |
34 Constructor |
34 |
35 |
35 @param orientation orientation of the sidebar widget (North, East, South, West) |
36 @param orientation orientation of the sidebar widget (North, East, |
36 @param delay value for the expand/shrink delay in milliseconds (integer) |
37 South, West) |
|
38 @param delay value for the expand/shrink delay in milliseconds |
|
39 (integer) |
37 @param parent parent widget (QWidget) |
40 @param parent parent widget (QWidget) |
38 """ |
41 """ |
39 super().__init__(parent) |
42 super().__init__(parent) |
40 |
43 |
41 self.__tabBar = QTabBar() |
44 self.__tabBar = QTabBar() |
45 self.__tabBar.setDrawBase(False) |
48 self.__tabBar.setDrawBase(False) |
46 self.__stackedWidget = QStackedWidget(self) |
49 self.__stackedWidget = QStackedWidget(self) |
47 self.__stackedWidget.setContentsMargins(0, 0, 0, 0) |
50 self.__stackedWidget.setContentsMargins(0, 0, 0, 0) |
48 self.__autoHideButton = QToolButton() |
51 self.__autoHideButton = QToolButton() |
49 self.__autoHideButton.setCheckable(True) |
52 self.__autoHideButton.setCheckable(True) |
50 self.__autoHideButton.setIcon(UI.PixmapCache.getIcon("autoHideOff.png")) |
53 self.__autoHideButton.setIcon( |
|
54 UI.PixmapCache.getIcon("autoHideOff.png")) |
51 self.__autoHideButton.setChecked(True) |
55 self.__autoHideButton.setChecked(True) |
52 self.__autoHideButton.setToolTip( |
56 self.__autoHideButton.setToolTip( |
53 self.trUtf8("Deselect to activate automatic collapsing")) |
57 self.trUtf8("Deselect to activate automatic collapsing")) |
54 self.barLayout = QBoxLayout(QBoxLayout.LeftToRight) |
58 self.barLayout = QBoxLayout(QBoxLayout.LeftToRight) |
55 self.barLayout.setContentsMargins(0, 0, 0, 0) |
59 self.barLayout.setContentsMargins(0, 0, 0, 0) |
75 self.__bigSize = QSize() |
79 self.__bigSize = QSize() |
76 |
80 |
77 self.splitter = None |
81 self.splitter = None |
78 self.splitterSizes = [] |
82 self.splitterSizes = [] |
79 |
83 |
80 self.__hasFocus = False # flag storing if this widget or any child has the focus |
84 self.__hasFocus = False |
|
85 # flag storing if this widget or any child has the focus |
81 self.__autoHide = False |
86 self.__autoHide = False |
82 |
87 |
83 self.__tabBar.installEventFilter(self) |
88 self.__tabBar.installEventFilter(self) |
84 |
89 |
85 self.__orientation = E5SideBar.North |
90 self.__orientation = E5SideBar.North |
86 if orientation is None: |
91 if orientation is None: |
87 orientation = E5SideBar.North |
92 orientation = E5SideBar.North |
88 self.setOrientation(orientation) |
93 self.setOrientation(orientation) |
89 |
94 |
90 self.__tabBar.currentChanged[int].connect(self.__stackedWidget.setCurrentIndex) |
95 self.__tabBar.currentChanged[int].connect( |
|
96 self.__stackedWidget.setCurrentIndex) |
91 e5App().focusChanged[QWidget, QWidget].connect(self.__appFocusChanged) |
97 e5App().focusChanged[QWidget, QWidget].connect(self.__appFocusChanged) |
92 self.__autoHideButton.toggled[bool].connect(self.__autoHideToggled) |
98 self.__autoHideButton.toggled[bool].connect(self.__autoHideToggled) |
93 |
99 |
94 def setSplitter(self, splitter): |
100 def setSplitter(self, splitter): |
95 """ |
101 """ |
120 if self.__actionMethod is not None: |
126 if self.__actionMethod is not None: |
121 self.__actionMethod() |
127 self.__actionMethod() |
122 |
128 |
123 def setDelay(self, delay): |
129 def setDelay(self, delay): |
124 """ |
130 """ |
125 Public method to set the delay value for the expand/shrink delay in milliseconds. |
131 Public method to set the delay value for the expand/shrink delay in |
126 |
132 milliseconds. |
127 @param delay value for the expand/shrink delay in milliseconds (integer) |
133 |
|
134 @param delay value for the expand/shrink delay in milliseconds |
|
135 (integer) |
128 """ |
136 """ |
129 self.__delayTimer.setInterval(delay) |
137 self.__delayTimer.setInterval(delay) |
130 |
138 |
131 def delay(self): |
139 def delay(self): |
132 """ |
140 """ |
133 Public method to get the delay value for the expand/shrink delay in milliseconds. |
141 Public method to get the delay value for the expand/shrink delay in |
|
142 milliseconds. |
134 |
143 |
135 @return value for the expand/shrink delay in milliseconds (integer) |
144 @return value for the expand/shrink delay in milliseconds (integer) |
136 """ |
145 """ |
137 return self.__delayTimer.interval() |
146 return self.__delayTimer.interval() |
138 |
147 |
425 |
436 |
426 @param orient orientation of the sidebar (North, East, South, West) |
437 @param orient orientation of the sidebar (North, East, South, West) |
427 """ |
438 """ |
428 if orient == E5SideBar.North: |
439 if orient == E5SideBar.North: |
429 self.__tabBar.setShape(QTabBar.RoundedNorth) |
440 self.__tabBar.setShape(QTabBar.RoundedNorth) |
430 self.__tabBar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) |
441 self.__tabBar.setSizePolicy( |
|
442 QSizePolicy.Expanding, QSizePolicy.Preferred) |
431 self.barLayout.setDirection(QBoxLayout.LeftToRight) |
443 self.barLayout.setDirection(QBoxLayout.LeftToRight) |
432 self.layout.setDirection(QBoxLayout.TopToBottom) |
444 self.layout.setDirection(QBoxLayout.TopToBottom) |
433 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) |
445 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) |
434 elif orient == E5SideBar.East: |
446 elif orient == E5SideBar.East: |
435 self.__tabBar.setShape(QTabBar.RoundedEast) |
447 self.__tabBar.setShape(QTabBar.RoundedEast) |
436 self.__tabBar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) |
448 self.__tabBar.setSizePolicy( |
|
449 QSizePolicy.Preferred, QSizePolicy.Expanding) |
437 self.barLayout.setDirection(QBoxLayout.TopToBottom) |
450 self.barLayout.setDirection(QBoxLayout.TopToBottom) |
438 self.layout.setDirection(QBoxLayout.RightToLeft) |
451 self.layout.setDirection(QBoxLayout.RightToLeft) |
439 self.layout.setAlignment(self.barLayout, Qt.AlignTop) |
452 self.layout.setAlignment(self.barLayout, Qt.AlignTop) |
440 elif orient == E5SideBar.South: |
453 elif orient == E5SideBar.South: |
441 self.__tabBar.setShape(QTabBar.RoundedSouth) |
454 self.__tabBar.setShape(QTabBar.RoundedSouth) |
442 self.__tabBar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) |
455 self.__tabBar.setSizePolicy( |
|
456 QSizePolicy.Expanding, QSizePolicy.Preferred) |
443 self.barLayout.setDirection(QBoxLayout.LeftToRight) |
457 self.barLayout.setDirection(QBoxLayout.LeftToRight) |
444 self.layout.setDirection(QBoxLayout.BottomToTop) |
458 self.layout.setDirection(QBoxLayout.BottomToTop) |
445 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) |
459 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) |
446 elif orient == E5SideBar.West: |
460 elif orient == E5SideBar.West: |
447 self.__tabBar.setShape(QTabBar.RoundedWest) |
461 self.__tabBar.setShape(QTabBar.RoundedWest) |
448 self.__tabBar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) |
462 self.__tabBar.setSizePolicy( |
|
463 QSizePolicy.Preferred, QSizePolicy.Expanding) |
449 self.barLayout.setDirection(QBoxLayout.TopToBottom) |
464 self.barLayout.setDirection(QBoxLayout.TopToBottom) |
450 self.layout.setDirection(QBoxLayout.LeftToRight) |
465 self.layout.setDirection(QBoxLayout.LeftToRight) |
451 self.layout.setAlignment(self.barLayout, Qt.AlignTop) |
466 self.layout.setAlignment(self.barLayout, Qt.AlignTop) |
452 self.__orientation = orient |
467 self.__orientation = orient |
453 |
468 |
613 |
628 |
614 def __autoHideToggled(self, checked): |
629 def __autoHideToggled(self, checked): |
615 """ |
630 """ |
616 Private slot to handle the toggling of the autohide button. |
631 Private slot to handle the toggling of the autohide button. |
617 |
632 |
618 @param checked flag indicating the checked state of the button (boolean) |
633 @param checked flag indicating the checked state of the button |
|
634 (boolean) |
619 """ |
635 """ |
620 self.__autoHide = not checked |
636 self.__autoHide = not checked |
621 if self.__autoHide: |
637 if self.__autoHide: |
622 self.__autoHideButton.setIcon(UI.PixmapCache.getIcon("autoHideOn.png")) |
638 self.__autoHideButton.setIcon( |
623 else: |
639 UI.PixmapCache.getIcon("autoHideOn.png")) |
624 self.__autoHideButton.setIcon(UI.PixmapCache.getIcon("autoHideOff.png")) |
640 else: |
|
641 self.__autoHideButton.setIcon( |
|
642 UI.PixmapCache.getIcon("autoHideOff.png")) |
625 |
643 |
626 def __appFocusChanged(self, old, now): |
644 def __appFocusChanged(self, old, now): |
627 """ |
645 """ |
628 Private slot to handle a change of the focus. |
646 Private slot to handle a change of the focus. |
629 |
647 |