I finally figured how to false positively send by ctrl+enter - happens if you
quickly enter (newline) and then use some ctr+something shortcut (usually
ctrl+v)
Acting on keyPressEvent doesn't help either, because you can cause false
positives the other way (ctrl+v, then quickly press enter)
So the solution is to ensure there's a complete ctrl+enter press/release combo
to ensure this is what you want. (Had to fix that after accidentally sending
half a rant ;-)
The patch replaces the former one.
The other patch allows to dynamically load an external stylesheet[1], what
allows very powerful and detailed configuration of the message look. Therefore
it also restores the <b>*bold*</b> appearance as preferred by Jan.
Cheers,
Thomas
[1] ~/.local/share/data/flaska.net/trojita/message.css
From 0728edb82e9663f78757f4af994d8f89cdeb5eab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20L=C3=BCbking?= <[email protected]>
Date: Wed, 10 Oct 2012 00:31:20 +0200
Subject: [PATCH] send by ctrl+enter
---
src/Gui/ComposeWidget.cpp | 1 +
src/Gui/ComposerTextEdit.cpp | 24 ++++++++++++++++++++++++
src/Gui/ComposerTextEdit.h | 4 ++++
3 files changed, 29 insertions(+)
diff --git a/src/Gui/ComposeWidget.cpp b/src/Gui/ComposeWidget.cpp
index efdd514..d8ad22e 100644
--- a/src/Gui/ComposeWidget.cpp
+++ b/src/Gui/ComposeWidget.cpp
@@ -95,6 +95,7 @@ ComposeWidget::ComposeWidget(MainWindow *parent) :
ui->mailText->setFont(font);
connect(ui->mailText, SIGNAL(urlsAdded(QList<QUrl>)), SLOT(slotAttachFiles(QList<QUrl>)));
+ connect(ui->mailText, SIGNAL(sendRequest()), SLOT(send()));
}
ComposeWidget::~ComposeWidget()
diff --git a/src/Gui/ComposerTextEdit.cpp b/src/Gui/ComposerTextEdit.cpp
index 0a39e80..9533657 100644
--- a/src/Gui/ComposerTextEdit.cpp
+++ b/src/Gui/ComposerTextEdit.cpp
@@ -27,6 +27,7 @@
#include <QUrl>
ComposerTextEdit::ComposerTextEdit(QWidget *parent) : QTextEdit(parent)
+, m_couldBeSendRequest(false)
{
m_notificationTimer = new QTimer(this);
m_notificationTimer->setSingleShot(true);
@@ -71,6 +72,29 @@ void ComposerTextEdit::insertFromMimeData(const QMimeData *source)
QTextEdit::insertFromMimeData(source);
}
+#define IS_SEND_COMBO \
+((ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) && ke->modifiers() == Qt::ControlModifier)
+
+void ComposerTextEdit::keyPressEvent(QKeyEvent *ke) {
+ m_couldBeSendRequest = false;
+ if (IS_SEND_COMBO) {
+ m_couldBeSendRequest = true;
+ }
+ QTextEdit::keyPressEvent(ke);
+}
+
+void ComposerTextEdit::keyReleaseEvent(QKeyEvent *ke) {
+ if (m_couldBeSendRequest && IS_SEND_COMBO) {
+ m_couldBeSendRequest = false;
+ emit sendRequest();
+ return;
+ }
+ m_couldBeSendRequest = false;
+ QTextEdit::keyReleaseEvent(ke);
+}
+
+#undef IS_SEND_COMBO
+
void ComposerTextEdit::paintEvent(QPaintEvent *pe)
{
QTextEdit::paintEvent(pe);
diff --git a/src/Gui/ComposerTextEdit.h b/src/Gui/ComposerTextEdit.h
index eef4cf9..b9ac156 100644
--- a/src/Gui/ComposerTextEdit.h
+++ b/src/Gui/ComposerTextEdit.h
@@ -36,11 +36,14 @@ public:
*/
void notify(const QString &n, uint timeout = 0);
signals:
+ void sendRequest();
void urlsAdded(QList<QUrl> urls);
protected:
/** DND reimplementation **/
bool canInsertFromMimeData( const QMimeData * source ) const;
void insertFromMimeData(const QMimeData *source);
+ void keyPressEvent(QKeyEvent *event);
+ void keyReleaseEvent(QKeyEvent *event);
/** painter reimplementation for notification **/
void paintEvent(QPaintEvent *pe);
private slots:
@@ -48,4 +51,5 @@ private slots:
private:
QString m_notification;
QTimer *m_notificationTimer;
+ bool m_couldBeSendRequest;
};
\ No newline at end of file
--
1.7.12.2
From 3b4f391bba617f7a3ba232b10187a82a416f154f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20L=C3=BCbking?= <[email protected]>
Date: Sun, 14 Oct 2012 12:29:10 +0200
Subject: [PATCH] support external css source
---
src/Gui/SimplePartWidget.cpp | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/src/Gui/SimplePartWidget.cpp b/src/Gui/SimplePartWidget.cpp
index c7e45a8..69e8273 100644
--- a/src/Gui/SimplePartWidget.cpp
+++ b/src/Gui/SimplePartWidget.cpp
@@ -18,6 +18,7 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
+#include <QDesktopServices>
#include <QFileDialog>
#include <QMessageBox>
#include <QNetworkReply>
@@ -64,14 +65,28 @@ void SimplePartWidget::slotMarkupPlainText() {
static const QRegExp bold(intro + "\\*(\\S*)\\*" + extro);
static const QRegExp italic(intro + "/(\\S*)/" + extro);
static const QRegExp underline(intro + "_(\\S*)_" + extro);
- // TODO: include some extern css here?
- QString stylesheet(
+
+ static const QString defaultStyle(
"pre{word-wrap: break-word; white-space: pre-wrap;}"
- ".markup{color:transparent;font-size:0px;}"
".quotemarks{color:transparent;font-size:0px;}"
"blockquote{font-size:90%; margin: 4pt 0 4pt 0; padding: 0 0 0 1em; border-left: 2px solid blue;}"
);
- static QString htmlHeader("<html><head><style type=\"text/css\"><!--" + stylesheet + "--></style></head><body><pre>");
+
+ // build stylesheet and html header
+ static QString stylesheet = defaultStyle;
+ static QFile file(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/message.css");
+ static QDateTime lastVersion;
+ QDateTime lastTouched(file.exists() ? QFileInfo(file).lastModified() : QDateTime());
+ if (lastVersion < lastTouched) {
+ stylesheet = defaultStyle;
+ if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ const QString userSheet = QString::fromLocal8Bit(file.readAll().data());
+ lastVersion = lastTouched;
+ stylesheet += "\n" + userSheet;
+ file.close();
+ }
+ }
+ QString htmlHeader("<html><head><style type=\"text/css\"><!--" + stylesheet + "--></style></head><body><pre>");
static QString htmlFooter("\n</pre></body></html>");
// Processing:
--
1.7.12.2