eric7/EricWidgets/EricSideBar.py

branch
eric7
changeset 8583
aac629a05f8b
parent 8579
cfd0e44ef084
child 8584
90391fda03d5
equal deleted inserted replaced
8582:ae6032e4b4ef 8583:aac629a05f8b
8 """ 8 """
9 9
10 import enum 10 import enum
11 import json 11 import json
12 12
13 from PyQt6.QtCore import QEvent, QSize, Qt, QTimer 13 from PyQt6.QtCore import pyqtSlot, Qt, QSize
14 from PyQt6.QtWidgets import ( 14 from PyQt6.QtGui import QIcon
15 QTabBar, QWidget, QStackedWidget, QBoxLayout, QToolButton, QSizePolicy 15 from PyQt6.QtWidgets import QWidget, QStackedWidget, QBoxLayout
16 ) 16
17 17 from .EricIconBar import EricIconBar
18 from EricWidgets.EricApplication import ericApp
19
20 import UI.PixmapCache
21 18
22 19
23 class EricSideBarSide(enum.Enum): 20 class EricSideBarSide(enum.Enum):
24 """ 21 """
25 Class defining the sidebar sides. 22 Class defining the sidebar sides.
28 EAST = 1 25 EAST = 1
29 SOUTH = 2 26 SOUTH = 2
30 WEST = 3 27 WEST = 3
31 28
32 29
33 # TODO: change to used a QListWidget with icons (48px) instead of QTabBar and
34 # remove the auto hide/show feature (?)
35 class EricSideBar(QWidget): 30 class EricSideBar(QWidget):
36 """ 31 """
37 Class implementing a sidebar with a widget area, that is hidden or shown, 32 Class implementing a sidebar with a widget area, that is hidden or shown,
38 if the current tab is clicked again. 33 if the current tab is clicked again.
39 """ 34 """
40 Version = 2 35 Version = 3
41 36
42 def __init__(self, orientation=None, delay=200, parent=None): 37 def __init__(self, orientation=None, parent=None):
43 """ 38 """
44 Constructor 39 Constructor
45 40
46 @param orientation orientation of the sidebar widget 41 @param orientation orientation of the sidebar widget
47 @type EricSideBarSide 42 @type EricSideBarSide
48 @param delay value for the expand/shrink delay in milliseconds
49 @type int
50 @param parent parent widget 43 @param parent parent widget
51 @type QWidget 44 @type QWidget
52 """ 45 """
53 super().__init__(parent) 46 super().__init__(parent)
54 47
55 self.__tabBar = QTabBar() 48 # initial layout is done for NORTH
56 self.__tabBar.setDrawBase(True) 49 self.__iconBar = EricIconBar(Qt.Orientation.Horizontal)
57 self.__tabBar.setShape(QTabBar.Shape.RoundedNorth) 50
58 self.__tabBar.setUsesScrollButtons(True)
59 self.__tabBar.setDrawBase(False)
60 self.__stackedWidget = QStackedWidget(self) 51 self.__stackedWidget = QStackedWidget(self)
61 self.__stackedWidget.setContentsMargins(0, 0, 0, 0) 52 self.__stackedWidget.setContentsMargins(0, 0, 0, 0)
62 self.__autoHideButton = QToolButton() 53
63 self.__autoHideButton.setCheckable(True)
64 self.__autoHideButton.setIcon(
65 UI.PixmapCache.getIcon("autoHideOff"))
66 self.__autoHideButton.setChecked(True)
67 self.__autoHideButton.setToolTip(
68 self.tr("Deselect to activate automatic collapsing"))
69 self.barLayout = QBoxLayout(QBoxLayout.Direction.LeftToRight)
70 self.barLayout.setContentsMargins(0, 0, 0, 0)
71 self.layout = QBoxLayout(QBoxLayout.Direction.TopToBottom) 54 self.layout = QBoxLayout(QBoxLayout.Direction.TopToBottom)
72 self.layout.setContentsMargins(0, 0, 0, 0) 55 self.layout.setContentsMargins(0, 0, 0, 0)
73 self.layout.setSpacing(0) 56 self.layout.setSpacing(0)
74 self.barLayout.addWidget(self.__autoHideButton) 57 self.layout.addWidget(self.__iconBar)
75 self.barLayout.addWidget(self.__tabBar)
76 self.layout.addLayout(self.barLayout)
77 self.layout.addWidget(self.__stackedWidget) 58 self.layout.addWidget(self.__stackedWidget)
78 self.setLayout(self.layout) 59 self.setLayout(self.layout)
79
80 # initialize the delay timer
81 self.__actionMethod = None
82 self.__delayTimer = QTimer(self)
83 self.__delayTimer.setSingleShot(True)
84 self.__delayTimer.setInterval(delay)
85 self.__delayTimer.timeout.connect(self.__delayedAction)
86 60
87 self.__minimized = False 61 self.__minimized = False
88 self.__minSize = 0 62 self.__minSize = 0
89 self.__maxSize = 0 63 self.__maxSize = 0
90 self.__bigSize = QSize() 64 self.__bigSize = QSize()
94 68
95 self.__hasFocus = False 69 self.__hasFocus = False
96 # flag storing if this widget or any child has the focus 70 # flag storing if this widget or any child has the focus
97 self.__autoHide = False 71 self.__autoHide = False
98 72
99 self.__tabBar.installEventFilter(self)
100
101 self.__orientation = EricSideBarSide.NORTH 73 self.__orientation = EricSideBarSide.NORTH
102 if orientation is None: 74 if orientation is None:
103 orientation = EricSideBarSide.NORTH 75 orientation = EricSideBarSide.NORTH
104 self.setOrientation(orientation) 76 self.setOrientation(orientation)
105 77
106 self.__tabBar.currentChanged[int].connect( 78 self.__iconBar.currentChanged.connect(
107 self.__stackedWidget.setCurrentIndex) 79 self.__stackedWidget.setCurrentIndex)
108 ericApp().focusChanged.connect(self.__appFocusChanged) 80 self.__iconBar.currentChanged.connect(
109 self.__autoHideButton.toggled[bool].connect(self.__autoHideToggled) 81 self.__currentIconChanged)
82 self.__iconBar.currentClicked.connect(
83 self.__currentIconClicked)
110 84
111 def setSplitter(self, splitter): 85 def setSplitter(self, splitter):
112 """ 86 """
113 Public method to set the splitter managing the sidebar. 87 Public method to set the splitter managing the sidebar.
114 88
128 @param index index of the splitter handle (integer) 102 @param index index of the splitter handle (integer)
129 """ 103 """
130 if self.splitter: 104 if self.splitter:
131 self.splitterSizes = self.splitter.sizes() 105 self.splitterSizes = self.splitter.sizes()
132 106
133 def __delayedAction(self):
134 """
135 Private slot to handle the firing of the delay timer.
136 """
137 if self.__actionMethod is not None:
138 self.__actionMethod()
139
140 def setDelay(self, delay):
141 """
142 Public method to set the delay value for the expand/shrink delay in
143 milliseconds.
144
145 @param delay value for the expand/shrink delay in milliseconds
146 (integer)
147 """
148 self.__delayTimer.setInterval(delay)
149
150 def delay(self):
151 """
152 Public method to get the delay value for the expand/shrink delay in
153 milliseconds.
154
155 @return value for the expand/shrink delay in milliseconds (integer)
156 """
157 return self.__delayTimer.interval()
158
159 def __cancelDelayTimer(self):
160 """
161 Private method to cancel the current delay timer.
162 """
163 self.__delayTimer.stop()
164 self.__actionMethod = None
165
166 def shrink(self):
167 """
168 Public method to record a shrink request.
169 """
170 self.__delayTimer.stop()
171 self.__actionMethod = self.__shrinkIt
172 self.__delayTimer.start()
173
174 def __shrinkIt(self): 107 def __shrinkIt(self):
175 """ 108 """
176 Private method to shrink the sidebar. 109 Private method to shrink the sidebar.
177 """ 110 """
178 self.__minimized = True 111 self.__minimized = True
191 self.__stackedWidget.hide() 124 self.__stackedWidget.hide()
192 125
193 if self.__orientation in ( 126 if self.__orientation in (
194 EricSideBarSide.NORTH, EricSideBarSide.SOUTH 127 EricSideBarSide.NORTH, EricSideBarSide.SOUTH
195 ): 128 ):
196 self.setFixedHeight(self.__tabBar.minimumSizeHint().height()) 129 self.setFixedHeight(self.__iconBar.minimumSizeHint().height())
197 else: 130 else:
198 self.setFixedWidth(self.__tabBar.minimumSizeHint().width()) 131 self.setFixedWidth(self.__iconBar.minimumSizeHint().width())
199
200 self.__actionMethod = None
201
202 def expand(self):
203 """
204 Public method to record a expand request.
205 """
206 self.__delayTimer.stop()
207 self.__actionMethod = self.__expandIt
208 self.__delayTimer.start()
209 132
210 def __expandIt(self): 133 def __expandIt(self):
211 """ 134 """
212 Private method to expand the sidebar. 135 Private method to expand the sidebar.
213 """ 136 """
224 minSize = max(self.__minSize, self.minimumSizeHint().width()) 147 minSize = max(self.__minSize, self.minimumSizeHint().width())
225 self.setMinimumWidth(minSize) 148 self.setMinimumWidth(minSize)
226 self.setMaximumWidth(self.__maxSize) 149 self.setMaximumWidth(self.__maxSize)
227 if self.splitter: 150 if self.splitter:
228 self.splitter.setSizes(self.splitterSizes) 151 self.splitter.setSizes(self.splitterSizes)
229
230 self.__actionMethod = None
231 152
232 def isMinimized(self): 153 def isMinimized(self):
233 """ 154 """
234 Public method to check the minimized state. 155 Public method to check the minimized state.
235 156
236 @return flag indicating the minimized state (boolean) 157 @return flag indicating the minimized state (boolean)
237 """ 158 """
238 return self.__minimized 159 return self.__minimized
239 160
240 def isAutoHiding(self): 161 @pyqtSlot(int)
241 """ 162 def __currentIconChanged(self, index):
242 Public method to check, if the auto hide function is active. 163 """
243 164 Private slot to handle a change of the current icon.
244 @return flag indicating the state of auto hiding (boolean) 165
245 """ 166 @param index index of the current icon
246 return self.__autoHide 167 @type int
247 168 """
248 def eventFilter(self, obj, evt): 169 if self.isMinimized():
249 """ 170 self.__expandIt()
250 Public method to handle some events for the tabbar. 171
251 172 @pyqtSlot(int)
252 @param obj reference to the object (QObject) 173 def __currentIconClicked(self, index):
253 @param evt reference to the event object (QEvent) 174 """
254 @return flag indicating, if the event was handled (boolean) 175 Private slot to handle a click of the current icon.
255 """ 176
256 if obj == self.__tabBar: 177 @param index index of the clicked icon
257 if evt.type() == QEvent.Type.MouseButtonPress: 178 @type int
258 pos = evt.position().toPoint() 179 """
259 for i in range(self.__tabBar.count()): 180 if self.isMinimized():
260 if self.__tabBar.tabRect(i).contains(pos): 181 self.__expandIt()
261 break 182 else:
262 183 self.__shrinkIt()
263 if i == self.__tabBar.currentIndex(): 184
264 if self.isMinimized(): 185 def addTab(self, widget, icon, label=None):
265 self.expand()
266 else:
267 self.shrink()
268 return True
269 elif self.isMinimized():
270 self.expand()
271 elif evt.type() == QEvent.Type.Wheel:
272 delta = evt.angleDelta().y()
273 if delta > 0:
274 self.prevTab()
275 else:
276 self.nextTab()
277 return True
278
279 return QWidget.eventFilter(self, obj, evt)
280
281 def addTab(self, widget, iconOrLabel, label=None):
282 """ 186 """
283 Public method to add a tab to the sidebar. 187 Public method to add a tab to the sidebar.
284 188
285 @param widget reference to the widget to add (QWidget) 189 @param widget reference to the widget to add
286 @param iconOrLabel reference to the icon or the label text of the tab 190 @type QWidget
287 (QIcon, string) 191 @param icon reference to the icon of the widget
288 @param label the labeltext of the tab (string) (only to be 192 @type QIcon or QPixmap
289 used, if the second parameter is a QIcon) 193 @param label the label text of the widget
290 """ 194 @type str
291 if label: 195 """
292 index = self.__tabBar.addTab(iconOrLabel, label) 196 if isinstance(icon, QIcon):
293 self.__tabBar.setTabToolTip(index, label) 197 icon = icon.pixmap(48, 48)
294 else: 198 self.__iconBar.addIcon(icon, label)
295 index = self.__tabBar.addTab(iconOrLabel)
296 self.__tabBar.setTabToolTip(index, iconOrLabel)
297 self.__stackedWidget.addWidget(widget) 199 self.__stackedWidget.addWidget(widget)
298 if self.__orientation in ( 200 if self.__orientation in (
299 EricSideBarSide.NORTH, EricSideBarSide.SOUTH 201 EricSideBarSide.NORTH, EricSideBarSide.SOUTH
300 ): 202 ):
301 self.__minSize = self.minimumSizeHint().height() 203 self.__minSize = self.minimumSizeHint().height()
302 else: 204 else:
303 self.__minSize = self.minimumSizeHint().width() 205 self.__minSize = self.minimumSizeHint().width()
304 206
305 def insertTab(self, index, widget, iconOrLabel, label=None): 207 def insertTab(self, index, widget, icon, label=None):
306 """ 208 """
307 Public method to insert a tab into the sidebar. 209 Public method to insert a tab into the sidebar.
308 210
309 @param index the index to insert the tab at (integer) 211 @param index the index to insert the tab at
310 @param widget reference to the widget to insert (QWidget) 212 @type int
311 @param iconOrLabel reference to the icon or the labeltext of the tab 213 @param widget reference to the widget to insert
312 (QIcon, string) 214 @type QWidget
313 @param label the labeltext of the tab (string) (only to be 215 @param icon reference to the icon of the widget
314 used, if the second parameter is a QIcon) 216 @type QIcon or QPixmap
315 """ 217 @param label the label text of the widget
316 if label: 218 @type str
317 index = self.__tabBar.insertTab(index, iconOrLabel, label) 219 """
318 self.__tabBar.setTabToolTip(index, label) 220 if isinstance(icon, QIcon):
319 else: 221 icon = icon.pixmap(48, 48)
320 index = self.__tabBar.insertTab(index, iconOrLabel) 222 self.__iconBar.insertIcon(index, icon, label)
321 self.__tabBar.setTabToolTip(index, iconOrLabel) 223
322 self.__stackedWidget.insertWidget(index, widget) 224 self.__stackedWidget.insertWidget(index, widget)
323 if self.__orientation in ( 225 if self.__orientation in (
324 EricSideBarSide.NORTH, EricSideBarSide.SOUTH 226 EricSideBarSide.NORTH, EricSideBarSide.SOUTH
325 ): 227 ):
326 self.__minSize = self.minimumSizeHint().height() 228 self.__minSize = self.minimumSizeHint().height()
329 231
330 def removeTab(self, index): 232 def removeTab(self, index):
331 """ 233 """
332 Public method to remove a tab. 234 Public method to remove a tab.
333 235
334 @param index the index of the tab to remove (integer) 236 @param index the index of the tab to remove
237 @type int
335 """ 238 """
336 self.__stackedWidget.removeWidget(self.__stackedWidget.widget(index)) 239 self.__stackedWidget.removeWidget(self.__stackedWidget.widget(index))
337 self.__tabBar.removeTab(index) 240 self.__iconBar.removeIcon(index)
338 if self.__orientation in ( 241 if self.__orientation in (
339 EricSideBarSide.NORTH, EricSideBarSide.SOUTH 242 EricSideBarSide.NORTH, EricSideBarSide.SOUTH
340 ): 243 ):
341 self.__minSize = self.minimumSizeHint().height() 244 self.__minSize = self.minimumSizeHint().height()
342 else: 245 else:
375 """ 278 """
376 Public method to get the number of tabs. 279 Public method to get the number of tabs.
377 280
378 @return number of tabs in the sidebar (integer) 281 @return number of tabs in the sidebar (integer)
379 """ 282 """
380 return self.__tabBar.count() 283 return self.__iconBar.count()
381 284
382 def currentIndex(self): 285 def currentIndex(self):
383 """ 286 """
384 Public method to get the index of the current tab. 287 Public method to get the index of the current tab.
385 288
391 """ 294 """
392 Public slot to set the current index. 295 Public slot to set the current index.
393 296
394 @param index the index to set as the current index (integer) 297 @param index the index to set as the current index (integer)
395 """ 298 """
396 self.__tabBar.setCurrentIndex(index) 299 self.__iconBar.setCurrentIndex(index)
397 self.__stackedWidget.setCurrentIndex(index) 300 self.__stackedWidget.setCurrentIndex(index)
398 if self.isMinimized(): 301 if self.isMinimized():
399 self.expand() 302 self.__expandIt()
400 303
401 def currentWidget(self): 304 def currentWidget(self):
402 """ 305 """
403 Public method to get a reference to the current widget. 306 Public method to get a reference to the current widget.
404 307
412 315
413 @param widget reference to the widget to become the current widget 316 @param widget reference to the widget to become the current widget
414 (QWidget) 317 (QWidget)
415 """ 318 """
416 self.__stackedWidget.setCurrentWidget(widget) 319 self.__stackedWidget.setCurrentWidget(widget)
417 self.__tabBar.setCurrentIndex(self.__stackedWidget.currentIndex()) 320 self.__iconBar.setCurrentIndex(self.__stackedWidget.currentIndex())
418 if self.isMinimized(): 321 if self.isMinimized():
419 self.expand() 322 self.__expandIt()
420 323
421 def indexOf(self, widget): 324 def indexOf(self, widget):
422 """ 325 """
423 Public method to get the index of the given widget. 326 Public method to get the index of the given widget.
424 327
425 @param widget reference to the widget to get the index of (QWidget) 328 @param widget reference to the widget to get the index of (QWidget)
426 @return index of the given widget (integer) 329 @return index of the given widget (integer)
427 """ 330 """
428 return self.__stackedWidget.indexOf(widget) 331 return self.__stackedWidget.indexOf(widget)
429 332
430 def isTabEnabled(self, index):
431 """
432 Public method to check, if a tab is enabled.
433
434 @param index index of the tab to check (integer)
435 @return flag indicating the enabled state (boolean)
436 """
437 return self.__tabBar.isTabEnabled(index)
438
439 def setTabEnabled(self, index, enabled):
440 """
441 Public method to set the enabled state of a tab.
442
443 @param index index of the tab to set (integer)
444 @param enabled enabled state to set (boolean)
445 """
446 self.__tabBar.setTabEnabled(index, enabled)
447
448 def orientation(self): 333 def orientation(self):
449 """ 334 """
450 Public method to get the orientation of the sidebar. 335 Public method to get the orientation of the sidebar.
451 336
452 @return orientation of the sidebar 337 @return orientation of the sidebar
460 345
461 @param orient orientation of the sidebar 346 @param orient orientation of the sidebar
462 @type EricSideBarSide 347 @type EricSideBarSide
463 """ 348 """
464 if orient == EricSideBarSide.NORTH: 349 if orient == EricSideBarSide.NORTH:
465 self.__tabBar.setShape(QTabBar.Shape.RoundedNorth) 350 self.__iconBar.setOrientation(Qt.Orientation.Horizontal)
466 self.__tabBar.setSizePolicy(
467 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
468 self.barLayout.setDirection(QBoxLayout.Direction.LeftToRight)
469 self.layout.setDirection(QBoxLayout.Direction.TopToBottom) 351 self.layout.setDirection(QBoxLayout.Direction.TopToBottom)
470 self.layout.setAlignment(self.barLayout,
471 Qt.AlignmentFlag.AlignLeft)
472 elif orient == EricSideBarSide.EAST: 352 elif orient == EricSideBarSide.EAST:
473 self.__tabBar.setShape(QTabBar.Shape.RoundedEast) 353 self.__iconBar.setOrientation(Qt.Orientation.Vertical)
474 self.__tabBar.setSizePolicy(
475 QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Expanding)
476 self.barLayout.setDirection(QBoxLayout.Direction.TopToBottom)
477 self.layout.setDirection(QBoxLayout.Direction.RightToLeft) 354 self.layout.setDirection(QBoxLayout.Direction.RightToLeft)
478 self.layout.setAlignment(self.barLayout, Qt.AlignmentFlag.AlignTop)
479 elif orient == EricSideBarSide.SOUTH: 355 elif orient == EricSideBarSide.SOUTH:
480 self.__tabBar.setShape(QTabBar.Shape.RoundedSouth) 356 self.__iconBar.setOrientation(Qt.Orientation.Horizontal)
481 self.__tabBar.setSizePolicy(
482 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
483 self.barLayout.setDirection(QBoxLayout.Direction.LeftToRight)
484 self.layout.setDirection(QBoxLayout.Direction.BottomToTop) 357 self.layout.setDirection(QBoxLayout.Direction.BottomToTop)
485 self.layout.setAlignment(self.barLayout,
486 Qt.AlignmentFlag.AlignLeft)
487 elif orient == EricSideBarSide.WEST: 358 elif orient == EricSideBarSide.WEST:
488 self.__tabBar.setShape(QTabBar.Shape.RoundedWest) 359 self.__iconBar.setOrientation(Qt.Orientation.Vertical)
489 self.__tabBar.setSizePolicy(
490 QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Expanding)
491 self.barLayout.setDirection(QBoxLayout.Direction.TopToBottom)
492 self.layout.setDirection(QBoxLayout.Direction.LeftToRight) 360 self.layout.setDirection(QBoxLayout.Direction.LeftToRight)
493 self.layout.setAlignment(self.barLayout, Qt.AlignmentFlag.AlignTop)
494 self.__orientation = orient 361 self.__orientation = orient
495
496 def tabIcon(self, index):
497 """
498 Public method to get the icon of a tab.
499
500 @param index index of the tab (integer)
501 @return icon of the tab (QIcon)
502 """
503 return self.__tabBar.tabIcon(index)
504
505 def setTabIcon(self, index, icon):
506 """
507 Public method to set the icon of a tab.
508
509 @param index index of the tab (integer)
510 @param icon icon to be set (QIcon)
511 """
512 self.__tabBar.setTabIcon(index, icon)
513
514 def tabText(self, index):
515 """
516 Public method to get the text of a tab.
517
518 @param index index of the tab (integer)
519 @return text of the tab (string)
520 """
521 return self.__tabBar.tabText(index)
522
523 def setTabText(self, index, text):
524 """
525 Public method to set the text of a tab.
526
527 @param index index of the tab (integer)
528 @param text text to set (string)
529 """
530 self.__tabBar.setTabText(index, text)
531
532 def tabToolTip(self, index):
533 """
534 Public method to get the tooltip text of a tab.
535
536 @param index index of the tab (integer)
537 @return tooltip text of the tab (string)
538 """
539 return self.__tabBar.tabToolTip(index)
540
541 def setTabToolTip(self, index, tip):
542 """
543 Public method to set the tooltip text of a tab.
544
545 @param index index of the tab (integer)
546 @param tip tooltip text to set (string)
547 """
548 self.__tabBar.setTabToolTip(index, tip)
549
550 def tabWhatsThis(self, index):
551 """
552 Public method to get the WhatsThis text of a tab.
553
554 @param index index of the tab (integer)
555 @return WhatsThis text of the tab (string)
556 """
557 return self.__tabBar.tabWhatsThis(index)
558
559 def setTabWhatsThis(self, index, text):
560 """
561 Public method to set the WhatsThis text of a tab.
562
563 @param index index of the tab (integer)
564 @param text WhatsThis text to set (string)
565 """
566 self.__tabBar.setTabWhatsThis(index, text)
567 362
568 def widget(self, index): 363 def widget(self, index):
569 """ 364 """
570 Public method to get a reference to the widget associated with a tab. 365 Public method to get a reference to the widget associated with a tab.
571 366
572 @param index index of the tab (integer) 367 @param index index of the tab (integer)
573 @return reference to the widget (QWidget) 368 @return reference to the widget (QWidget)
574 """ 369 """
575 return self.__stackedWidget.widget(index) 370 return self.__stackedWidget.widget(index)
371
372 def setIconBarColor(self, color):
373 """
374 Public method to set the icon bar color.
375
376 @param color icon bar color
377 @type QColor
378 """
379 self.__iconBar.setColor(color)
380
381 def iconBarColor(self):
382 """
383 Public method to get the icon bar color.
384
385 @return icon bar color
386 @rtype QColor
387 """
388 return self.__iconBar.color()
576 389
577 def saveState(self): 390 def saveState(self):
578 """ 391 """
579 Public method to save the state of the sidebar. 392 Public method to save the state of the sidebar.
580 393
598 "minimized": self.__minimized, 411 "minimized": self.__minimized,
599 "big_size": [self.__bigSize.width(), self.__bigSize.height()], 412 "big_size": [self.__bigSize.width(), self.__bigSize.height()],
600 "min_size": self.__minSize, 413 "min_size": self.__minSize,
601 "max_size": self.__maxSize, 414 "max_size": self.__maxSize,
602 "splitter_sizes": self.splitterSizes, 415 "splitter_sizes": self.splitterSizes,
603 "auto_hide": self.__autoHide
604 } 416 }
605 data = json.dumps(dataDict) 417 data = json.dumps(dataDict)
606 418
607 return data 419 return data
608 420
631 maxSize = self.maximumHeight() 443 maxSize = self.maximumHeight()
632 else: 444 else:
633 minSize = self.layout.minimumSize().width() 445 minSize = self.layout.minimumSize().width()
634 maxSize = self.maximumWidth() 446 maxSize = self.maximumWidth()
635 447
636 if stateDict["version"] == 2: 448 if stateDict["version"] in (2, 3):
637 if stateDict["minimized"] and not self.__minimized: 449 if stateDict["minimized"] and not self.__minimized:
638 self.shrink() 450 self.__shrinkIt()
639 451
640 self.__bigSize = QSize(*stateDict["big_size"]) 452 self.__bigSize = QSize(*stateDict["big_size"])
641 self.__minSize = max(stateDict["min_size"], minSize) 453 self.__minSize = max(stateDict["min_size"], minSize)
642 self.__maxSize = max(stateDict["max_size"], maxSize) 454 self.__maxSize = max(stateDict["max_size"], maxSize)
643 self.splitterSizes = stateDict["splitter_sizes"] 455 self.splitterSizes = stateDict["splitter_sizes"]
644 456
645 self.__autoHide = stateDict["auto_hide"]
646 self.__autoHideButton.setChecked(not self.__autoHide)
647
648 if not stateDict["minimized"]: 457 if not stateDict["minimized"]:
649 self.expand() 458 self.__expandIt()
650 459
651 return True 460 return True
652 461
653 return False 462 return False
654
655 #######################################################################
656 ## methods below implement the autohide functionality
657 #######################################################################
658
659 def __autoHideToggled(self, checked):
660 """
661 Private slot to handle the toggling of the autohide button.
662
663 @param checked flag indicating the checked state of the button
664 (boolean)
665 """
666 self.__autoHide = not checked
667 if self.__autoHide:
668 self.__autoHideButton.setIcon(
669 UI.PixmapCache.getIcon("autoHideOn"))
670 else:
671 self.__autoHideButton.setIcon(
672 UI.PixmapCache.getIcon("autoHideOff"))
673
674 def __appFocusChanged(self, old, now):
675 """
676 Private slot to handle a change of the focus.
677
678 @param old reference to the widget, that lost focus (QWidget or None)
679 @param now reference to the widget having the focus (QWidget or None)
680 """
681 if isinstance(now, QWidget):
682 self.__hasFocus = self.isAncestorOf(now)
683 if (
684 self.__autoHide and
685 not self.__hasFocus and
686 not self.isMinimized()
687 ):
688 self.shrink()
689 elif self.__autoHide and self.__hasFocus and self.isMinimized():
690 self.expand()
691
692 def enterEvent(self, event):
693 """
694 Protected method to handle the mouse entering this widget.
695
696 @param event reference to the event (QEvent)
697 """
698 if self.__autoHide and self.isMinimized():
699 self.expand()
700 else:
701 self.__cancelDelayTimer()
702
703 def leaveEvent(self, event):
704 """
705 Protected method to handle the mouse leaving this widget.
706
707 @param event reference to the event (QEvent)
708 """
709 if self.__autoHide and not self.__hasFocus and not self.isMinimized():
710 self.shrink()
711 else:
712 self.__cancelDelayTimer()
713
714 def shutdown(self):
715 """
716 Public method to shut down the object.
717
718 This method does some preparations so the object can be deleted
719 properly. It disconnects from the focusChanged signal in order to
720 avoid trouble later on.
721 """
722 ericApp().focusChanged.disconnect(self.__appFocusChanged)

eric ide

mercurial