Attached is the hardened ctrl+enter patch, uses now a static inline bool 
instead of the macro.

Regarding the search config / generator toolbutton
1. i don't mind the icon
2. i don't intend to discuss on whether it should be on the left or the right, 
but should probably explain why i initially moved it to the left.

a) detectability. Regardless of where Jans eyes go, on the left it is close to 
the cursors initial position - when you're about to enter a search, you eyes 
will inevitably be on that area

b) direction. this slightly shifts the focus to the construction, but in that 
role you build from left to right and that is where the source of your elements 
are

c) UI geometry. with the button on the left, the popup ends up under the 
lineedit. on the right, the popup shows up above the message text in the wide 
layout and outside the window in the compact one

Cheers,
Thomas
From 49e3b7ecb67b4fad92e2acd0c6af4b109ed570ba 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] harden ctrl+enter sending

it's important to ensure this is a full press/release
cycle on the ctrl modifier, otherwise quick chained usage
of eg. ctrl+v and enter in either direction can cause
accidental sends
---
 src/Gui/ComposerTextEdit.cpp | 21 +++++++++++++++++++--
 src/Gui/ComposerTextEdit.h   |  2 ++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/Gui/ComposerTextEdit.cpp b/src/Gui/ComposerTextEdit.cpp
index 580bb6e..2a048ab 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)
 {
     setAcceptRichText(false);
     setLineWrapMode(QTextEdit::FixedColumnWidth);
@@ -75,11 +76,27 @@ void ComposerTextEdit::insertFromMimeData(const QMimeData *source)
     QTextEdit::insertFromMimeData(source);
 }
 
-void ComposerTextEdit::keyReleaseEvent(QKeyEvent *ke) {
-    if ((ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) && ke->modifiers() == Qt::ControlModifier) {
+
+static inline bool isSendCombo(QKeyEvent *ke) {
+    return (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) && ke->modifiers() == Qt::ControlModifier;
+}
+
+void ComposerTextEdit::keyPressEvent(QKeyEvent *ke) {
+    m_couldBeSendRequest = false;
+    if (isSendCombo(ke)) {
+        m_couldBeSendRequest = true;
+    }
+    QTextEdit::keyPressEvent(ke);
+}
+
+void ComposerTextEdit::keyReleaseEvent(QKeyEvent *ke)
+{
+    if (m_couldBeSendRequest && isSendCombo(ke)) {
+        m_couldBeSendRequest = false;
         emit sendRequest();
         return;
     }
+    m_couldBeSendRequest = false;
     QTextEdit::keyReleaseEvent(ke);
 }
 
diff --git a/src/Gui/ComposerTextEdit.h b/src/Gui/ComposerTextEdit.h
index c347e92..b9ac156 100644
--- a/src/Gui/ComposerTextEdit.h
+++ b/src/Gui/ComposerTextEdit.h
@@ -42,6 +42,7 @@ 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);
@@ -50,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

Reply via email to