/ src / bitmessageqt / messagecompose.py
messagecompose.py
 1  """
 2  Message editor with a wheel zoom functionality
 3  """
 4  # pylint: disable=bad-continuation
 5  
 6  from PyQt4 import QtCore, QtGui
 7  
 8  
 9  class MessageCompose(QtGui.QTextEdit):
10      """Editor class with wheel zoom functionality"""
11      def __init__(self, parent=0):
12          super(MessageCompose, self).__init__(parent)
13          self.setAcceptRichText(False)
14          self.defaultFontPointSize = self.currentFont().pointSize()
15  
16      def wheelEvent(self, event):
17          """Mouse wheel scroll event handler"""
18          if (
19              QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ControlModifier
20          ) == QtCore.Qt.ControlModifier and event.orientation() == QtCore.Qt.Vertical:
21              if event.delta() > 0:
22                  self.zoomIn(1)
23              else:
24                  self.zoomOut(1)
25              zoom = self.currentFont().pointSize() * 100 / self.defaultFontPointSize
26              QtGui.QApplication.activeWindow().statusBar().showMessage(
27                  QtGui.QApplication.translate("MainWindow", "Zoom level %1%").arg(
28                      str(zoom)
29                  )
30              )
31          else:
32              # in QTextEdit, super does not zoom, only scroll
33              super(MessageCompose, self).wheelEvent(event)
34  
35      def reset(self):
36          """Clear the edit content"""
37          self.setText('')