From 9353e8eff7066a779b19f747ed40c94802e9f36a Mon Sep 17 00:00:00 2001 From: mailchuck Date: Fri, 22 Jan 2016 19:16:47 +0100 Subject: [PATCH] Message editor updates - Does not allow changing fonts (it's ignored once it's sent anyway), fixes #167 - Allows zooming, fixes #163 --- src/bitmessageqt/__init__.py | 4 ++-- src/bitmessageqt/bitmessageui.py | 5 +++-- src/bitmessageqt/messagecompose.py | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/bitmessageqt/messagecompose.py diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 753864a3..4a2c479c 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2274,7 +2274,7 @@ class MyForm(settingsmixin.SMainWindow): self.ui.comboBoxSendFrom.setCurrentIndex(0) self.ui.lineEditTo.setText('') self.ui.lineEditSubject.setText('') - self.ui.textEditMessage.setText('') + self.ui.textEditMessage.reset() if self.replyFromTab is not None: self.ui.tabWidget.setCurrentIndex(self.replyFromTab) self.replyFromTab = None @@ -2324,7 +2324,7 @@ class MyForm(settingsmixin.SMainWindow): self.ui.comboBoxSendFromBroadcast.setCurrentIndex(0) self.ui.lineEditSubjectBroadcast.setText('') - self.ui.textEditMessageBroadcast.setText('') + self.ui.textEditMessageBroadcast.reset() self.ui.tabWidget.setCurrentIndex(1) self.ui.tableWidgetInboxSubscriptions.setCurrentCell(0, 0) self.statusBar().showMessage(_translate( diff --git a/src/bitmessageqt/bitmessageui.py b/src/bitmessageqt/bitmessageui.py index 25cb178e..b50fd3fe 100644 --- a/src/bitmessageqt/bitmessageui.py +++ b/src/bitmessageqt/bitmessageui.py @@ -9,6 +9,7 @@ from PyQt4 import QtCore, QtGui from messageview import MessageView +from messagecompose import MessageCompose import settingsmixin try: @@ -232,7 +233,7 @@ class Ui_MainWindow(object): self.gridLayout_2_Widget = QtGui.QWidget() self.gridLayout_2_Widget.setLayout(self.gridLayout_2) self.verticalSplitter_5.addWidget(self.gridLayout_2_Widget) - self.textEditMessage = QtGui.QTextEdit(self.sendDirect) + self.textEditMessage = MessageCompose(self.sendDirect) self.textEditMessage.setObjectName(_fromUtf8("textEditMessage")) self.verticalSplitter_5.addWidget(self.textEditMessage) self.verticalSplitter_5.setStretchFactor(0, 0) @@ -268,7 +269,7 @@ class Ui_MainWindow(object): self.gridLayout_5_Widget = QtGui.QWidget() self.gridLayout_5_Widget.setLayout(self.gridLayout_5) self.verticalSplitter_6.addWidget(self.gridLayout_5_Widget) - self.textEditMessageBroadcast = QtGui.QTextEdit(self.sendBroadcast) + self.textEditMessageBroadcast = MessageCompose(self.sendBroadcast) self.textEditMessageBroadcast.setObjectName(_fromUtf8("textEditMessageBroadcast")) self.verticalSplitter_6.addWidget(self.textEditMessageBroadcast) self.verticalSplitter_6.setStretchFactor(0, 0) diff --git a/src/bitmessageqt/messagecompose.py b/src/bitmessageqt/messagecompose.py new file mode 100644 index 00000000..5718aa32 --- /dev/null +++ b/src/bitmessageqt/messagecompose.py @@ -0,0 +1,24 @@ +from PyQt4 import QtCore, QtGui + +class MessageCompose(QtGui.QTextEdit): + + def __init__(self, parent = 0): + super(MessageCompose, self).__init__(parent) + self.setAcceptRichText(False) # we'll deal with this later when we have a new message format + self.defaultFontPointSize = self.currentFont().pointSize() + + def wheelEvent(self, event): + if (QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ControlModifier) == QtCore.Qt.ControlModifier and event.orientation() == QtCore.Qt.Vertical: + numDegrees = event.delta() / 8 + numSteps = numDegrees / 15 + zoomDiff = numSteps + self.currentFont().pointSize() - self.defaultFontPointSize + if numSteps > 0: + self.zoomIn(numSteps) + else: + self.zoomOut(-numSteps) + QtGui.QApplication.activeWindow().statusBar().showMessage(QtGui.QApplication.translate("MainWindow", "Zoom level %1").arg(str(zoomDiff))) + # super will actually automatically take care of zooming + super(MessageCompose, self).wheelEvent(event) + + def reset(self): + self.setText('')