2020-06-05 13:43:42 +02:00
|
|
|
"""
|
|
|
|
Message editor with a wheel zoom functionality
|
|
|
|
"""
|
|
|
|
# pylint: disable=bad-continuation
|
|
|
|
|
2016-01-22 19:16:47 +01:00
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
|
2020-06-05 13:43:42 +02:00
|
|
|
|
2016-01-22 19:16:47 +01:00
|
|
|
class MessageCompose(QtGui.QTextEdit):
|
2020-06-05 13:43:42 +02:00
|
|
|
"""Editor class with wheel zoom functionality"""
|
|
|
|
def __init__(self, parent=0):
|
2016-01-22 19:16:47 +01:00
|
|
|
super(MessageCompose, self).__init__(parent)
|
2020-06-05 13:43:42 +02:00
|
|
|
self.setAcceptRichText(False)
|
2016-01-22 19:16:47 +01:00
|
|
|
self.defaultFontPointSize = self.currentFont().pointSize()
|
2020-06-05 13:43:42 +02:00
|
|
|
|
2016-01-22 19:16:47 +01:00
|
|
|
def wheelEvent(self, event):
|
2020-06-05 13:43:42 +02:00
|
|
|
"""Mouse wheel scroll event handler"""
|
|
|
|
if (
|
|
|
|
QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ControlModifier
|
|
|
|
) == QtCore.Qt.ControlModifier and event.orientation() == QtCore.Qt.Vertical:
|
2016-01-23 09:55:12 +01:00
|
|
|
if event.delta() > 0:
|
|
|
|
self.zoomIn(1)
|
2016-01-22 19:16:47 +01:00
|
|
|
else:
|
2016-01-23 09:55:12 +01:00
|
|
|
self.zoomOut(1)
|
|
|
|
zoom = self.currentFont().pointSize() * 100 / self.defaultFontPointSize
|
2020-06-05 13:43:42 +02:00
|
|
|
QtGui.QApplication.activeWindow().statusBar().showMessage(
|
|
|
|
QtGui.QApplication.translate("MainWindow", "Zoom level %1%").arg(
|
|
|
|
str(zoom)
|
|
|
|
)
|
|
|
|
)
|
2016-01-23 12:21:58 +01:00
|
|
|
else:
|
|
|
|
# in QTextEdit, super does not zoom, only scroll
|
|
|
|
super(MessageCompose, self).wheelEvent(event)
|
2016-01-22 19:16:47 +01:00
|
|
|
|
|
|
|
def reset(self):
|
2020-06-05 13:43:42 +02:00
|
|
|
"""Clear the edit content"""
|
2016-01-22 19:16:47 +01:00
|
|
|
self.setText('')
|