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 |
11 from PyQt4.QtGui import QTabBar, QWidget, QStackedWidget, QBoxLayout, QToolButton |
11 from PyQt4.QtGui import QTabBar, QWidget, QStackedWidget, QBoxLayout, QToolButton, QSizePolicy |
12 |
12 |
13 from E5Gui.E5Application import e5App |
13 from E5Gui.E5Application import e5App |
14 |
14 |
15 import UI.PixmapCache |
15 import UI.PixmapCache |
16 |
16 |
37 super().__init__(parent) |
37 super().__init__(parent) |
38 |
38 |
39 self.__tabBar = QTabBar() |
39 self.__tabBar = QTabBar() |
40 self.__tabBar.setDrawBase(True) |
40 self.__tabBar.setDrawBase(True) |
41 self.__tabBar.setShape(QTabBar.RoundedNorth) |
41 self.__tabBar.setShape(QTabBar.RoundedNorth) |
42 self.__tabBar.setUsesScrollButtons(False) |
42 self.__tabBar.setUsesScrollButtons(True) |
|
43 self.__tabBar.setDrawBase(False) |
43 self.__stackedWidget = QStackedWidget(self) |
44 self.__stackedWidget = QStackedWidget(self) |
44 self.__stackedWidget.setContentsMargins(0, 0, 0, 0) |
45 self.__stackedWidget.setContentsMargins(0, 0, 0, 0) |
45 self.__autoHideButton = QToolButton() |
46 self.__autoHideButton = QToolButton() |
46 self.__autoHideButton.setCheckable(True) |
47 self.__autoHideButton.setCheckable(True) |
47 self.__autoHideButton.setIcon(UI.PixmapCache.getIcon("autoHideOff.png")) |
48 self.__autoHideButton.setIcon(UI.PixmapCache.getIcon("autoHideOff.png")) |
200 (QIcon, string) |
201 (QIcon, string) |
201 @param label the labeltext of the tab (string) (only to be |
202 @param label the labeltext of the tab (string) (only to be |
202 used, if the second parameter is a QIcon) |
203 used, if the second parameter is a QIcon) |
203 """ |
204 """ |
204 if label: |
205 if label: |
205 index = self.__tabBar.addTab(iconOrLabel, "") |
206 self.__tabBar.addTab(iconOrLabel, label) |
206 self.__tabBar.setTabToolTip(index, label) |
|
207 else: |
207 else: |
208 self.__tabBar.addTab(iconOrLabel) |
208 self.__tabBar.addTab(iconOrLabel) |
209 self.__stackedWidget.addWidget(widget) |
209 self.__stackedWidget.addWidget(widget) |
210 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
210 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
211 self.__minSize = self.minimumSizeHint().height() |
211 self.__minSize = self.minimumSizeHint().height() |
222 (QIcon, string) |
222 (QIcon, string) |
223 @param label the labeltext of the tab (string) (only to be |
223 @param label the labeltext of the tab (string) (only to be |
224 used, if the second parameter is a QIcon) |
224 used, if the second parameter is a QIcon) |
225 """ |
225 """ |
226 if label: |
226 if label: |
227 self.__tabBar.insertTab(index, iconOrLabel, "") |
227 self.__tabBar.insertTab(index, iconOrLabel, label) |
228 self.__tabBar.setTabToolTip(index, label) |
|
229 else: |
228 else: |
230 self.__tabBar.insertTab(index, iconOrLabel) |
229 self.__tabBar.insertTab(index, iconOrLabel) |
231 self.__stackedWidget.insertWidget(index, widget) |
230 self.__stackedWidget.insertWidget(index, widget) |
232 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
231 if self.__orientation in [E5SideBar.North, E5SideBar.South]: |
233 self.__minSize = self.minimumSizeHint().height() |
232 self.__minSize = self.minimumSizeHint().height() |
362 Public method to set the orientation of the sidebar. |
361 Public method to set the orientation of the sidebar. |
363 @param orient orientation of the sidebar (North, East, South, West) |
362 @param orient orientation of the sidebar (North, East, South, West) |
364 """ |
363 """ |
365 if orient == E5SideBar.North: |
364 if orient == E5SideBar.North: |
366 self.__tabBar.setShape(QTabBar.RoundedNorth) |
365 self.__tabBar.setShape(QTabBar.RoundedNorth) |
|
366 self.__tabBar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) |
367 self.barLayout.setDirection(QBoxLayout.LeftToRight) |
367 self.barLayout.setDirection(QBoxLayout.LeftToRight) |
368 self.layout.setDirection(QBoxLayout.TopToBottom) |
368 self.layout.setDirection(QBoxLayout.TopToBottom) |
369 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) |
369 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) |
370 elif orient == E5SideBar.East: |
370 elif orient == E5SideBar.East: |
371 self.__tabBar.setShape(QTabBar.RoundedEast) |
371 self.__tabBar.setShape(QTabBar.RoundedEast) |
|
372 self.__tabBar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) |
372 self.barLayout.setDirection(QBoxLayout.TopToBottom) |
373 self.barLayout.setDirection(QBoxLayout.TopToBottom) |
373 self.layout.setDirection(QBoxLayout.RightToLeft) |
374 self.layout.setDirection(QBoxLayout.RightToLeft) |
374 self.layout.setAlignment(self.barLayout, Qt.AlignTop) |
375 self.layout.setAlignment(self.barLayout, Qt.AlignTop) |
375 elif orient == E5SideBar.South: |
376 elif orient == E5SideBar.South: |
376 self.__tabBar.setShape(QTabBar.RoundedSouth) |
377 self.__tabBar.setShape(QTabBar.RoundedSouth) |
|
378 self.__tabBar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) |
377 self.barLayout.setDirection(QBoxLayout.LeftToRight) |
379 self.barLayout.setDirection(QBoxLayout.LeftToRight) |
378 self.layout.setDirection(QBoxLayout.BottomToTop) |
380 self.layout.setDirection(QBoxLayout.BottomToTop) |
379 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) |
381 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) |
380 elif orient == E5SideBar.West: |
382 elif orient == E5SideBar.West: |
381 self.__tabBar.setShape(QTabBar.RoundedWest) |
383 self.__tabBar.setShape(QTabBar.RoundedWest) |
|
384 self.__tabBar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) |
382 self.barLayout.setDirection(QBoxLayout.TopToBottom) |
385 self.barLayout.setDirection(QBoxLayout.TopToBottom) |
383 self.layout.setDirection(QBoxLayout.LeftToRight) |
386 self.layout.setDirection(QBoxLayout.LeftToRight) |
384 self.layout.setAlignment(self.barLayout, Qt.AlignTop) |
387 self.layout.setAlignment(self.barLayout, Qt.AlignTop) |
385 self.__orientation = orient |
388 self.__orientation = orient |
386 |
389 |