29 class EricSideBar(QWidget): |
29 class EricSideBar(QWidget): |
30 """ |
30 """ |
31 Class implementing a sidebar with a widget area, that is hidden or shown, |
31 Class implementing a sidebar with a widget area, that is hidden or shown, |
32 if the current tab is clicked again. |
32 if the current tab is clicked again. |
33 """ |
33 """ |
34 Version = 3 |
34 Version = 4 |
35 |
35 |
36 def __init__(self, orientation=None, |
36 def __init__(self, orientation=None, |
37 iconBarSize=EricIconBar.DefaultBarSize, parent=None): |
37 iconBarSize=EricIconBar.DefaultBarSize, parent=None): |
38 """ |
38 """ |
39 Constructor |
39 Constructor |
65 self.__minimized = False |
65 self.__minimized = False |
66 self.__minSize = 0 |
66 self.__minSize = 0 |
67 self.__maxSize = 0 |
67 self.__maxSize = 0 |
68 self.__bigSize = QSize() |
68 self.__bigSize = QSize() |
69 |
69 |
70 self.splitter = None |
|
71 self.splitterSizes = [] |
|
72 |
|
73 self.__hasFocus = False |
70 self.__hasFocus = False |
74 # flag storing if this widget or any child has the focus |
71 # flag storing if this widget or any child has the focus |
75 self.__autoHide = False |
72 self.__autoHide = False |
76 |
73 |
77 self.__orientation = EricSideBarSide.NORTH |
74 self.__orientation = EricSideBarSide.NORTH |
84 self.__iconBar.currentChanged.connect( |
81 self.__iconBar.currentChanged.connect( |
85 self.__currentIconChanged) |
82 self.__currentIconChanged) |
86 self.__iconBar.currentClicked.connect( |
83 self.__iconBar.currentClicked.connect( |
87 self.__currentIconClicked) |
84 self.__currentIconClicked) |
88 |
85 |
89 def setSplitter(self, splitter): |
|
90 """ |
|
91 Public method to set the splitter managing the sidebar. |
|
92 |
|
93 @param splitter reference to the splitter (QSplitter) |
|
94 """ |
|
95 self.splitter = splitter |
|
96 self.splitter.splitterMoved.connect(self.__splitterMoved) |
|
97 self.splitter.setChildrenCollapsible(False) |
|
98 index = self.splitter.indexOf(self) |
|
99 self.splitter.setCollapsible(index, False) |
|
100 |
|
101 def __splitterMoved(self, pos, index): |
|
102 """ |
|
103 Private slot to react on splitter moves. |
|
104 |
|
105 @param pos new position of the splitter handle (integer) |
|
106 @param index index of the splitter handle (integer) |
|
107 """ |
|
108 if self.splitter: |
|
109 self.splitterSizes = self.splitter.sizes() |
|
110 |
|
111 def __shrinkIt(self): |
86 def __shrinkIt(self): |
112 """ |
87 """ |
113 Private method to shrink the sidebar. |
88 Private method to shrink the sidebar. |
114 """ |
89 """ |
115 self.__minimized = True |
90 self.__minimized = True |
120 self.__minSize = self.minimumSizeHint().height() |
95 self.__minSize = self.minimumSizeHint().height() |
121 self.__maxSize = self.maximumHeight() |
96 self.__maxSize = self.maximumHeight() |
122 else: |
97 else: |
123 self.__minSize = self.minimumSizeHint().width() |
98 self.__minSize = self.minimumSizeHint().width() |
124 self.__maxSize = self.maximumWidth() |
99 self.__maxSize = self.maximumWidth() |
125 if self.splitter: |
|
126 self.splitterSizes = self.splitter.sizes() |
|
127 |
100 |
128 self.__stackedWidget.hide() |
101 self.__stackedWidget.hide() |
129 |
102 |
130 if self.__orientation in ( |
103 if self.__orientation in ( |
131 EricSideBarSide.NORTH, EricSideBarSide.SOUTH |
104 EricSideBarSide.NORTH, EricSideBarSide.SOUTH |
149 self.setMaximumHeight(self.__maxSize) |
122 self.setMaximumHeight(self.__maxSize) |
150 else: |
123 else: |
151 minSize = max(self.__minSize, self.minimumSizeHint().width()) |
124 minSize = max(self.__minSize, self.minimumSizeHint().width()) |
152 self.setMinimumWidth(minSize) |
125 self.setMinimumWidth(minSize) |
153 self.setMaximumWidth(self.__maxSize) |
126 self.setMaximumWidth(self.__maxSize) |
154 if self.splitter: |
|
155 self.splitter.setSizes(self.splitterSizes) |
|
156 |
127 |
157 def isMinimized(self): |
128 def isMinimized(self): |
158 """ |
129 """ |
159 Public method to check the minimized state. |
130 Public method to check the minimized state. |
160 |
131 |
415 """ |
386 """ |
416 Public method to save the state of the sidebar. |
387 Public method to save the state of the sidebar. |
417 |
388 |
418 @return saved state as a byte array (QByteArray) |
389 @return saved state as a byte array (QByteArray) |
419 """ |
390 """ |
420 if len(self.splitterSizes) == 0: |
391 self.__bigSize = self.size() |
421 if self.splitter: |
392 if self.__orientation in ( |
422 self.splitterSizes = self.splitter.sizes() |
393 EricSideBarSide.NORTH, EricSideBarSide.SOUTH |
423 self.__bigSize = self.size() |
394 ): |
424 if self.__orientation in ( |
395 self.__minSize = self.minimumSizeHint().height() |
425 EricSideBarSide.NORTH, EricSideBarSide.SOUTH |
396 self.__maxSize = self.maximumHeight() |
426 ): |
397 else: |
427 self.__minSize = self.minimumSizeHint().height() |
398 self.__minSize = self.minimumSizeHint().width() |
428 self.__maxSize = self.maximumHeight() |
399 self.__maxSize = self.maximumWidth() |
429 else: |
|
430 self.__minSize = self.minimumSizeHint().width() |
|
431 self.__maxSize = self.maximumWidth() |
|
432 |
400 |
433 dataDict = { |
401 dataDict = { |
434 "version": self.Version, |
402 "version": self.Version, |
435 "minimized": self.__minimized, |
403 "minimized": self.__minimized, |
436 "big_size": [self.__bigSize.width(), self.__bigSize.height()], |
404 "big_size": [self.__bigSize.width(), self.__bigSize.height()], |
437 "min_size": self.__minSize, |
405 "min_size": self.__minSize, |
438 "max_size": self.__maxSize, |
406 "max_size": self.__maxSize, |
439 "splitter_sizes": self.splitterSizes, |
|
440 } |
407 } |
441 data = json.dumps(dataDict) |
408 data = json.dumps(dataDict) |
442 |
409 |
443 return data |
410 return data |
444 |
411 |
467 maxSize = self.maximumHeight() |
434 maxSize = self.maximumHeight() |
468 else: |
435 else: |
469 minSize = self.layout.minimumSize().width() |
436 minSize = self.layout.minimumSize().width() |
470 maxSize = self.maximumWidth() |
437 maxSize = self.maximumWidth() |
471 |
438 |
472 if stateDict["version"] in (2, 3): |
439 if stateDict["version"] in (2, 3, 4): |
473 if stateDict["minimized"] and not self.__minimized: |
440 if stateDict["minimized"] and not self.__minimized: |
474 self.__shrinkIt() |
441 self.__shrinkIt() |
475 |
442 |
476 self.__bigSize = QSize(*stateDict["big_size"]) |
443 self.__bigSize = QSize(*stateDict["big_size"]) |
477 self.__minSize = max(stateDict["min_size"], minSize) |
444 self.__minSize = max(stateDict["min_size"], minSize) |
478 self.__maxSize = max(stateDict["max_size"], maxSize) |
445 self.__maxSize = max(stateDict["max_size"], maxSize) |
479 self.splitterSizes = stateDict["splitter_sizes"] |
|
480 |
446 |
481 if not stateDict["minimized"]: |
447 if not stateDict["minimized"]: |
482 self.__expandIt() |
448 self.__expandIt() |
483 |
449 |
484 return True |
450 return True |