49 self.__editor.selectionChanged.connect(self.__editorSelectionChanged) |
53 self.__editor.selectionChanged.connect(self.__editorSelectionChanged) |
50 |
54 |
51 self.__createButtons() |
55 self.__createButtons() |
52 |
56 |
53 self.__layout.addStretch() |
57 self.__layout.addStretch() |
|
58 |
|
59 self.__outerLayout = QVBoxLayout(self) |
|
60 self.__outerLayout.setContentsMargins(margin, margin, margin, margin) |
|
61 self.__outerLayout.setSpacing(spacing) |
|
62 self.__outerLayout.setAlignment(Qt.AlignHCenter) |
|
63 |
|
64 self.__upButton = QToolButton(self) |
|
65 self.__upButton.setArrowType(Qt.UpArrow) |
|
66 self.__upButton.setSizePolicy( |
|
67 QSizePolicy.MinimumExpanding, QSizePolicy.Minimum) |
|
68 self.__upButton.setAutoRepeat(True) |
|
69 |
|
70 self.__scroller = QScrollArea(self) |
|
71 self.__scroller.setWidget(self.__buttonsWidget) |
|
72 self.__scroller.setSizePolicy( |
|
73 QSizePolicy.Minimum, QSizePolicy.Expanding) |
|
74 self.__scroller.setFrameShape(QFrame.NoFrame) |
|
75 self.__scroller.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) |
|
76 self.__scroller.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) |
|
77 self.__scroller.setWidgetResizable(False) |
|
78 |
|
79 self.__downButton = QToolButton(self) |
|
80 self.__downButton.setArrowType(Qt.DownArrow) |
|
81 self.__downButton.setSizePolicy( |
|
82 QSizePolicy.MinimumExpanding, QSizePolicy.Minimum) |
|
83 self.__downButton.setAutoRepeat(True) |
|
84 |
|
85 self.__outerLayout.addWidget(self.__upButton) |
|
86 self.__outerLayout.addWidget(self.__scroller) |
|
87 self.__outerLayout.addWidget(self.__downButton) |
|
88 |
|
89 self.__upButton.clicked.connect(self.__slideUp) |
|
90 self.__downButton.clicked.connect(self.__slideDown) |
|
91 |
54 self.setMaximumWidth( |
92 self.setMaximumWidth( |
55 self.__buttons["bold"].sizeHint().width() + 2 * margin) |
93 self.__buttons["bold"].sizeHint().width() + 2 * margin) |
56 |
94 |
57 self.__updateButtonStates() |
95 self.__updateButtonStates() |
|
96 |
|
97 ####################################################################### |
|
98 ## Methods below implement some event handlers |
|
99 ####################################################################### |
|
100 |
|
101 def show(self): |
|
102 """ |
|
103 Public slot to show the widget. |
|
104 """ |
|
105 super(EditorButtonsWidget, self).show() |
|
106 self.__enableScrollerButtons() |
|
107 |
|
108 def resizeEvent(self, evt): |
|
109 """ |
|
110 Protected method to handle resize events. |
|
111 |
|
112 @param evt reference to the resize event (QResizeEvent) |
|
113 """ |
|
114 self.__enableScrollerButtons() |
|
115 super(EditorButtonsWidget, self).resizeEvent(evt) |
|
116 |
|
117 ####################################################################### |
|
118 ## Methods below implement scroller related functions |
|
119 ####################################################################### |
|
120 |
|
121 def __enableScrollerButtons(self): |
|
122 """ |
|
123 Private method to set the enabled state of the scroll buttons. |
|
124 """ |
|
125 scrollBar = self.__scroller.verticalScrollBar() |
|
126 self.__upButton.setEnabled(scrollBar.value() > 0) |
|
127 self.__downButton.setEnabled(scrollBar.value() < scrollBar.maximum()) |
|
128 |
|
129 def __slideUp(self): |
|
130 """ |
|
131 Private slot to move the widget upwards, i.e. show contents to the |
|
132 bottom. |
|
133 """ |
|
134 self.__slide(True) |
|
135 |
|
136 def __slideDown(self): |
|
137 """ |
|
138 Private slot to move the widget downwards, i.e. show contents to |
|
139 the top. |
|
140 """ |
|
141 self.__slide(False) |
|
142 |
|
143 def __slide(self, up): |
|
144 """ |
|
145 Private method to move the sliding widget. |
|
146 |
|
147 @param up flag indicating to move upwards (boolean) |
|
148 """ |
|
149 scrollBar = self.__scroller.verticalScrollBar() |
|
150 stepSize = scrollBar.singleStep() |
|
151 if up: |
|
152 stepSize = -stepSize |
|
153 newValue = scrollBar.value() + stepSize |
|
154 if newValue < 0: |
|
155 newValue = 0 |
|
156 elif newValue > scrollBar.maximum(): |
|
157 newValue = scrollBar.maximum() |
|
158 scrollBar.setValue(newValue) |
|
159 self.__enableScrollerButtons() |
|
160 |
|
161 ####################################################################### |
|
162 ## Methods below implement the format button functions |
|
163 ####################################################################### |
58 |
164 |
59 def __createButtons(self): |
165 def __createButtons(self): |
60 """ |
166 """ |
61 Private slot to create the various tool buttons. |
167 Private slot to create the various tool buttons. |
62 """ |
168 """ |
167 act.setData("header{0}".format(level)) |
273 act.setData("header{0}".format(level)) |
168 |
274 |
169 self.__buttons["code"].setEnabled(self.__provider.hasCode()) |
275 self.__buttons["code"].setEnabled(self.__provider.hasCode()) |
170 self.__buttons["codeBlock"].setEnabled( |
276 self.__buttons["codeBlock"].setEnabled( |
171 self.__provider.hasCodeBlock()) |
277 self.__provider.hasCodeBlock()) |
|
278 |
|
279 self.__buttons["bulletedList"].setEnabled( |
|
280 self.__provider.hasBulletedList()) |
|
281 self.__buttons["numberedList"].setEnabled( |
|
282 self.__provider.hasNumberedList()) |
172 |
283 |
173 self.__editorSelectionChanged() |
284 self.__editorSelectionChanged() |
174 |
285 |
175 # TODO: make this configurable |
286 # TODO: make this configurable |
176 self.setVisible(self.__provider.kind() != "none") |
287 self.setVisible(self.__provider.kind() != "none") |
204 self.__provider.hyperlink(self.__editor) |
315 self.__provider.hyperlink(self.__editor) |
205 elif format == "line": |
316 elif format == "line": |
206 self.__provider.line(self.__editor) |
317 self.__provider.line(self.__editor) |
207 elif format == "image": |
318 elif format == "image": |
208 self.__provider.image(self.__editor) |
319 self.__provider.image(self.__editor) |
|
320 elif format == "bulletedList": |
|
321 self.__provider.bulletedList(self.__editor) |
|
322 elif format == "numberedList": |
|
323 self.__provider.numberedList(self.__editor) |
209 |
324 |
210 def __headerMenuTriggered(self, act): |
325 def __headerMenuTriggered(self, act): |
211 """ |
326 """ |
212 Private method handling the selection of a header menu entry. |
327 Private method handling the selection of a header menu entry. |
213 |
328 |