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 |
10 from PyQt4.QtCore import QEvent, QSize, Qt, QByteArray, QDataStream, QIODevice, QTimer |
11 from PyQt4.QtGui import QTabBar, QWidget, QStackedWidget, QBoxLayout, QToolButton, \ |
11 from PyQt4.QtGui import QTabBar, QWidget, QStackedWidget, QBoxLayout, QToolButton, \ |
12 QSizePolicy |
12 QSizePolicy |
13 |
13 |
14 from E5Gui.E5Application import e5App |
14 from E5Gui.E5Application import e5App |
15 |
15 |
26 North = 0 |
26 North = 0 |
27 East = 1 |
27 East = 1 |
28 South = 2 |
28 South = 2 |
29 West = 3 |
29 West = 3 |
30 |
30 |
31 def __init__(self, orientation=None, parent=None): |
31 def __init__(self, orientation=None, delay=200, parent=None): |
32 """ |
32 """ |
33 Constructor |
33 Constructor |
34 |
34 |
35 @param orientation orientation of the sidebar widget (North, East, South, West) |
35 @param orientation orientation of the sidebar widget (North, East, South, West) |
|
36 @param delay value for the expand/shrink delay in milliseconds (integer) |
36 @param parent parent widget (QWidget) |
37 @param parent parent widget (QWidget) |
37 """ |
38 """ |
38 super().__init__(parent) |
39 super().__init__(parent) |
39 |
40 |
40 self.__tabBar = QTabBar() |
41 self.__tabBar = QTabBar() |
59 self.barLayout.addWidget(self.__tabBar) |
60 self.barLayout.addWidget(self.__tabBar) |
60 self.layout.addLayout(self.barLayout) |
61 self.layout.addLayout(self.barLayout) |
61 self.layout.addWidget(self.__stackedWidget) |
62 self.layout.addWidget(self.__stackedWidget) |
62 self.setLayout(self.layout) |
63 self.setLayout(self.layout) |
63 |
64 |
|
65 # initialize the delay timer |
|
66 self.__actionMethod = None |
|
67 self.__delayTimer = QTimer(self) |
|
68 self.__delayTimer.setSingleShot(True) |
|
69 self.__delayTimer.setInterval(delay) |
|
70 self.__delayTimer.timeout.connect(self.__delayedAction) |
|
71 |
64 self.__minimized = False |
72 self.__minimized = False |
65 self.__minSize = 0 |
73 self.__minSize = 0 |
66 self.__maxSize = 0 |
74 self.__maxSize = 0 |
67 self.__bigSize = QSize() |
75 self.__bigSize = QSize() |
68 |
76 |
103 @param index index of the splitter handle (integer) |
111 @param index index of the splitter handle (integer) |
104 """ |
112 """ |
105 if self.splitter: |
113 if self.splitter: |
106 self.splitterSizes = self.splitter.sizes() |
114 self.splitterSizes = self.splitter.sizes() |
107 |
115 |
|
116 def __delayedAction(self): |
|
117 """ |
|
118 Private slot to handle the firing of the delay timer. |
|
119 """ |
|
120 if self.__actionMethod is not None: |
|
121 self.__actionMethod() |
|
122 |
|
123 def setDelay(self, delay): |
|
124 """ |
|
125 Public method to set the delay value for the expand/shrink delay in milliseconds. |
|
126 |
|
127 @param delay value for the expand/shrink delay in milliseconds (integer) |
|
128 """ |
|
129 self.__delayTimer.setInterval(delay) |
|
130 |
|
131 def delay(self): |
|
132 """ |
|
133 Public method to get the delay value for the expand/shrink delay in milliseconds. |
|
134 |
|
135 @return value for the expand/shrink delay in milliseconds (integer) |
|
136 """ |
|
137 return self.__delayTimer.interval() |
|
138 |
|
139 def __cancelDelayTimer(self): |
|
140 """ |
|
141 Private method to cancel the current delay timer. |
|
142 """ |
|
143 self.__delayTimer.stop() |
|
144 self.__actionMethod = None |
|
145 |
108 def shrink(self): |
146 def shrink(self): |
109 """ |
147 """ |
110 Public method to shrink the sidebar. |
148 Public method to record a shrink request. |
|
149 """ |
|
150 self.__delayTimer.stop() |
|
151 self.__actionMethod = self.__shrinkIt |
|
152 self.__delayTimer.start() |
|
153 |
|
154 def __shrinkIt(self): |
|
155 """ |
|
156 Private method to shrink the sidebar. |
111 """ |
157 """ |
112 self.__minimized = True |
158 self.__minimized = True |
113 self.__bigSize = self.size() |
159 self.__bigSize = self.size() |
114 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
160 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
115 self.__minSize = self.minimumSizeHint().height() |
161 self.__minSize = self.minimumSizeHint().height() |
124 |
170 |
125 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
171 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
126 self.setFixedHeight(self.__tabBar.minimumSizeHint().height()) |
172 self.setFixedHeight(self.__tabBar.minimumSizeHint().height()) |
127 else: |
173 else: |
128 self.setFixedWidth(self.__tabBar.minimumSizeHint().width()) |
174 self.setFixedWidth(self.__tabBar.minimumSizeHint().width()) |
|
175 |
|
176 self.__actionMethod = None |
129 |
177 |
130 def expand(self): |
178 def expand(self): |
131 """ |
179 """ |
132 Public method to expand the sidebar. |
180 Public method to record a expand request. |
|
181 """ |
|
182 self.__delayTimer.stop() |
|
183 self.__actionMethod = self.__expandIt |
|
184 self.__delayTimer.start() |
|
185 |
|
186 def __expandIt(self): |
|
187 """ |
|
188 Private method to expand the sidebar. |
133 """ |
189 """ |
134 self.__minimized = False |
190 self.__minimized = False |
135 self.__stackedWidget.show() |
191 self.__stackedWidget.show() |
136 self.resize(self.__bigSize) |
192 self.resize(self.__bigSize) |
137 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
193 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
142 minSize = max(self.__minSize, self.minimumSizeHint().width()) |
198 minSize = max(self.__minSize, self.minimumSizeHint().width()) |
143 self.setMinimumWidth(minSize) |
199 self.setMinimumWidth(minSize) |
144 self.setMaximumWidth(self.__maxSize) |
200 self.setMaximumWidth(self.__maxSize) |
145 if self.splitter: |
201 if self.splitter: |
146 self.splitter.setSizes(self.splitterSizes) |
202 self.splitter.setSizes(self.splitterSizes) |
|
203 |
|
204 self.__actionMethod = None |
147 |
205 |
148 def isMinimized(self): |
206 def isMinimized(self): |
149 """ |
207 """ |
150 Public method to check the minimized state. |
208 Public method to check the minimized state. |
151 |
209 |
583 |
641 |
584 @param event reference to the event (QEvent) |
642 @param event reference to the event (QEvent) |
585 """ |
643 """ |
586 if self.__autoHide and self.isMinimized(): |
644 if self.__autoHide and self.isMinimized(): |
587 self.expand() |
645 self.expand() |
|
646 else: |
|
647 self.__cancelDelayTimer() |
588 |
648 |
589 def leaveEvent(self, event): |
649 def leaveEvent(self, event): |
590 """ |
650 """ |
591 Protected method to handle the mouse leaving this widget. |
651 Protected method to handle the mouse leaving this widget. |
592 |
652 |
593 @param event reference to the event (QEvent) |
653 @param event reference to the event (QEvent) |
594 """ |
654 """ |
595 if self.__autoHide and not self.__hasFocus and not self.isMinimized(): |
655 if self.__autoHide and not self.__hasFocus and not self.isMinimized(): |
596 self.shrink() |
656 self.shrink() |
|
657 else: |
|
658 self.__cancelDelayTimer() |
597 |
659 |
598 def shutdown(self): |
660 def shutdown(self): |
599 """ |
661 """ |
600 Public method to shut down the object. |
662 Public method to shut down the object. |
601 |
663 |