|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a horizontal and a vertical toolbox class. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtGui import QToolBox, QTabWidget |
|
11 |
|
12 from .E5TabWidget import E5TabWidget |
|
13 |
|
14 class E5VerticalToolBox(QToolBox): |
|
15 """ |
|
16 Class implementing a ToolBox class substituting QToolBox to support wheel events. |
|
17 """ |
|
18 def __init__(self, parent = None): |
|
19 """ |
|
20 Constructor |
|
21 |
|
22 @param parent reference to the parent widget (QWidget) |
|
23 """ |
|
24 QToolBox.__init__(self, parent) |
|
25 |
|
26 def wheelEvent(self, event): |
|
27 """ |
|
28 Protected slot to support wheel events. |
|
29 |
|
30 @param reference to the wheel event (QWheelEvent) |
|
31 """ |
|
32 index = self.currentIndex() |
|
33 if event.delta() > 0: |
|
34 index -= 1 |
|
35 else: |
|
36 index += 1 |
|
37 if index < 0: |
|
38 index = self.count() - 1 |
|
39 elif index == self.count(): |
|
40 index = 0 |
|
41 |
|
42 self.setCurrentIndex(index) |
|
43 |
|
44 event.accept() |
|
45 |
|
46 class E5HorizontalToolBox(E5TabWidget): |
|
47 """ |
|
48 Class implementing a vertical QToolBox like widget. |
|
49 """ |
|
50 def __init__(self, parent = None): |
|
51 """ |
|
52 Constructor |
|
53 |
|
54 @param parent reference to the parent widget (QWidget) |
|
55 """ |
|
56 E5TabWidget.__init__(self, parent) |
|
57 self.setTabPosition(QTabWidget.West) |
|
58 |
|
59 def addItem(self, widget, icon, text): |
|
60 """ |
|
61 Public method to add a widget to the toolbox. |
|
62 |
|
63 @param widget reference to the widget to be added (QWidget) |
|
64 @param icon the icon to be shown (QIcon) |
|
65 @param text the text to be shown (string) |
|
66 @return index of the added widget (integer) |
|
67 """ |
|
68 index = self.addTab(widget, icon, "") |
|
69 self.setTabToolTip(index, text) |
|
70 return index |
|
71 |
|
72 def insertItem(self, index, widget, icon, text): |
|
73 """ |
|
74 Public method to add a widget to the toolbox. |
|
75 |
|
76 @param index position at which the widget should be inserted (integer) |
|
77 @param widget reference to the widget to be added (QWidget) |
|
78 @param icon the icon to be shown (QIcon) |
|
79 @param text the text to be shown (string) |
|
80 @return index of the added widget (integer) |
|
81 """ |
|
82 index = self.insertTab(index, widget, icon, "") |
|
83 self.setTabToolTip(index, text) |
|
84 return index |
|
85 |
|
86 def setItemToolTip(self, index, toolTip): |
|
87 """ |
|
88 Public method to set the tooltip of an item. |
|
89 |
|
90 @param index index of the item (integer) |
|
91 @param toolTip tooltip text to be set (string) |
|
92 """ |
|
93 self.setTabToolTip(index, toolTip) |
|
94 |
|
95 def setItemEnabled(self, index, enabled): |
|
96 """ |
|
97 Public method to set the enabled state of an item. |
|
98 |
|
99 @param index index of the item (integer) |
|
100 @param enabled flag indicating the enabled state (boolean) |
|
101 """ |
|
102 self.setTabEnabled(index, enabled) |