61 |
61 |
62 self.__pressTimer = QTimer() |
62 self.__pressTimer = QTimer() |
63 self.__pressTimer.setSingleShot(True) |
63 self.__pressTimer.setSingleShot(True) |
64 self.__pressTimer.setInterval( |
64 self.__pressTimer.setInterval( |
65 QApplication.style().styleHint( |
65 QApplication.style().styleHint( |
66 QStyle.SH_ToolButton_PopupDelay, opt, self)) |
66 QStyle.StyleHint.SH_ToolButton_PopupDelay, opt, self)) |
67 self.__pressTimer.timeout.connect(self.__showMenu) |
67 self.__pressTimer.timeout.connect(self.__showMenu) |
68 |
68 |
69 ################################################################## |
69 ################################################################## |
70 ## Menu handling methods below. |
70 ## Menu handling methods below. |
71 ## |
71 ## |
129 |
129 |
130 self.aboutToShowMenu.emit() |
130 self.aboutToShowMenu.emit() |
131 |
131 |
132 if self.__options & E5ToolButton.ShowMenuInsideOption: |
132 if self.__options & E5ToolButton.ShowMenuInsideOption: |
133 pos = self.mapToGlobal(self.rect().bottomRight()) |
133 pos = self.mapToGlobal(self.rect().bottomRight()) |
134 if QApplication.layoutDirection() == Qt.RightToLeft: |
134 if ( |
|
135 QApplication.layoutDirection() == |
|
136 Qt.LayoutDirection.RightToLeft |
|
137 ): |
135 pos.setX(pos.x() - self.rect().width()) |
138 pos.setX(pos.x() - self.rect().width()) |
136 else: |
139 else: |
137 pos.setX(pos.x() - self.__menu.sizeHint().width()) |
140 pos.setX(pos.x() - self.__menu.sizeHint().width()) |
138 else: |
141 else: |
139 pos = self.mapToGlobal(self.rect().bottomLeft()) |
142 pos = self.mapToGlobal(self.rect().bottomLeft()) |
172 self.__options |= E5ToolButton.ToolBarLookOption |
175 self.__options |= E5ToolButton.ToolBarLookOption |
173 |
176 |
174 opt = QStyleOption() |
177 opt = QStyleOption() |
175 opt.initFrom(self) |
178 opt.initFrom(self) |
176 size = self.style().pixelMetric( |
179 size = self.style().pixelMetric( |
177 QStyle.PM_ToolBarIconSize, opt, self) |
180 QStyle.PixelMetric.PM_ToolBarIconSize, opt, self) |
178 self.setIconSize(QSize(size, size)) |
181 self.setIconSize(QSize(size, size)) |
179 else: |
182 else: |
180 self.__options &= ~E5ToolButton.ToolBarLookOption |
183 self.__options &= ~E5ToolButton.ToolBarLookOption |
181 |
184 |
182 self.setProperty("toolbar-look", enable) |
185 self.setProperty("toolbar-look", enable) |
192 Protected method to handle mouse press events. |
195 Protected method to handle mouse press events. |
193 |
196 |
194 @param evt reference to the mouse event |
197 @param evt reference to the mouse event |
195 @type QMouseEvent |
198 @type QMouseEvent |
196 """ |
199 """ |
197 if self.popupMode() == QToolButton.DelayedPopup: |
200 if self.popupMode() == QToolButton.ToolButtonPopupMode.DelayedPopup: |
198 self.__pressTimer.start() |
201 self.__pressTimer.start() |
199 |
202 |
200 if ( |
203 if ( |
201 evt.buttons() == Qt.LeftButton and |
204 evt.buttons() == Qt.MouseButton.LeftButton and |
202 self.__menu is not None and |
205 self.__menu is not None and |
203 self.popupMode() == QToolButton.InstantPopup |
206 self.popupMode() == QToolButton.ToolButtonPopupMode.InstantPopup |
204 ): |
207 ): |
205 self.setDown(True) |
208 self.setDown(True) |
206 self.__showMenu() |
209 self.__showMenu() |
207 elif ( |
210 elif ( |
208 evt.buttons() == Qt.RightButton and |
211 evt.buttons() == Qt.MouseButton.RightButton and |
209 self.__menu is not None |
212 self.__menu is not None |
210 ): |
213 ): |
211 self.setDown(True) |
214 self.setDown(True) |
212 self.__showMenu() |
215 self.__showMenu() |
213 else: |
216 else: |
221 @type QMouseEvent |
224 @type QMouseEvent |
222 """ |
225 """ |
223 self.__pressTimer.stop() |
226 self.__pressTimer.stop() |
224 |
227 |
225 if ( |
228 if ( |
226 evt.button() == Qt.MiddleButton and |
229 evt.button() == Qt.MouseButton.MiddleButton and |
227 self.rect().contains(evt.pos()) |
230 self.rect().contains(evt.pos()) |
228 ): |
231 ): |
229 self.middleClicked.emit() |
232 self.middleClicked.emit() |
230 self.setDown(False) |
233 self.setDown(False) |
231 elif ( |
234 elif ( |
232 evt.button() == Qt.LeftButton and |
235 evt.button() == Qt.MouseButton.LeftButton and |
233 self.rect().contains(evt.pos()) and |
236 self.rect().contains(evt.pos()) and |
234 evt.modifiers() == Qt.ControlModifier |
237 evt.modifiers() == Qt.KeyboardModifier.ControlModifier |
235 ): |
238 ): |
236 self.controlClicked.emit() |
239 self.controlClicked.emit() |
237 self.setDown(False) |
240 self.setDown(False) |
238 else: |
241 else: |
239 super(E5ToolButton, self).mouseReleaseEvent(evt) |
242 super(E5ToolButton, self).mouseReleaseEvent(evt) |
247 """ |
250 """ |
248 super(E5ToolButton, self).mouseDoubleClickEvent(evt) |
251 super(E5ToolButton, self).mouseDoubleClickEvent(evt) |
249 |
252 |
250 self.__pressTimer.stop() |
253 self.__pressTimer.stop() |
251 |
254 |
252 if evt.buttons() == Qt.LeftButton: |
255 if evt.buttons() == Qt.MouseButton.LeftButton: |
253 self.doubleClicked.emit() |
256 self.doubleClicked.emit() |
254 |
257 |
255 def contextMenuEvent(self, evt): |
258 def contextMenuEvent(self, evt): |
256 """ |
259 """ |
257 Protected method to handle context menu events. |
260 Protected method to handle context menu events. |