[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:22:57 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=d0c5509

The following commit has been merged in the master branch:
commit d0c550946527ed1ef727674d423fba35c9a97a5f
Author: Dan Vrátil <dvratil at redhat.com>
Date:   Fri Nov 9 17:56:00 2012 +0100

    Navigation through history of sent messages in message editor
    
    This implements navigation through history of sent messages
    by pressing Up and Down arrow keys like in Konversation.
    
    REVIEW: 106245
    BUG: 303648
    FIXED-IN: 0.6.0
---
 lib/chat-text-edit.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/chat-text-edit.h   |  7 ++++++
 2 files changed, 67 insertions(+)

diff --git a/lib/chat-text-edit.cpp b/lib/chat-text-edit.cpp
index eb4915b..9babc73 100644
--- a/lib/chat-text-edit.cpp
+++ b/lib/chat-text-edit.cpp
@@ -27,6 +27,8 @@
 
 #include <KStandardShortcut>
 
+#define MAXHISTORY 100
+
 ChatTextEdit::ChatTextEdit(QWidget *parent) :
         KTextEdit(parent)
 {
@@ -40,6 +42,10 @@ ChatTextEdit::ChatTextEdit(QWidget *parent) :
     // set to false so it doesn't paste anything unwanted apart from normal text
     setAcceptRichText(false);
 
+    // Initialize the history
+    m_history.prepend(QString());
+    m_historyPos = 0;
+
     connect(this, SIGNAL(textChanged()), SLOT(recalculateSize()));
 }
 
@@ -74,6 +80,9 @@ QSize ChatTextEdit::sizeHint() const
 void ChatTextEdit::keyPressEvent(QKeyEvent *e)
 {
     if ((e->key()==Qt::Key_Return ||  e->key()==Qt::Key_Enter) && !e->modifiers()) {
+	if (!toPlainText().isEmpty()) {
+	    addHistory(toPlainText());
+	}
         Q_EMIT returnKeyPressed();
         return;
     }
@@ -85,6 +94,14 @@ void ChatTextEdit::keyPressEvent(QKeyEvent *e)
         }
     }
 
+    if ((e->key() == Qt::Key_Up) && !textCursor().movePosition(QTextCursor::Up)) {
+        getHistory(true);
+    }
+
+    if ((e->key() == Qt::Key_Down) && !textCursor().movePosition(QTextCursor::Down)) {
+        getHistory(false);
+    }
+
     if (e->key() == Qt::Key_PageUp ||
         e->key() == Qt::Key_PageDown) {
         QWidget::keyPressEvent(e); //pass to parent.
@@ -133,3 +150,46 @@ void ChatTextEdit::updateScrollBar()
     setVerticalScrollBarPolicy(sizeHint().height() > height() ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff);
     ensureCursorVisible();
 }
+
+// History of sent messages based on code from Konversation
+// by Dario Abatianni
+
+void ChatTextEdit::getHistory(bool up)
+{
+    m_history[m_historyPos] = toPlainText();
+
+    if (up) {
+        m_historyPos++;
+
+        if (m_historyPos == m_history.length()) {
+            m_historyPos--;
+            return;
+        }
+    } else {
+        if (m_historyPos == 0) {
+            if (!toPlainText().isEmpty()) {
+                addHistory(toPlainText());
+            }
+
+            setText(QLatin1String(""));
+        } else {
+            m_historyPos--;
+        }
+    }
+
+    setText(m_history[m_historyPos]);
+}
+
+void ChatTextEdit::addHistory(const QString &text)
+{
+    if (m_history.value(1) != text) {
+        m_history[0] = text;
+        m_history.prepend(QString());
+
+        if (m_history.length() > MAXHISTORY) {
+            m_history.removeLast();
+        }
+    }
+
+    m_historyPos = 0;
+}
diff --git a/lib/chat-text-edit.h b/lib/chat-text-edit.h
index 3e2dec0..a8b0e79 100644
--- a/lib/chat-text-edit.h
+++ b/lib/chat-text-edit.h
@@ -40,6 +40,9 @@ protected:
     // reimplemented
     void resizeEvent(QResizeEvent*);
 
+    void getHistory(bool up);
+    void addHistory(const QString &text);
+
 private Q_SLOTS:
     void recalculateSize();
     void updateScrollBar();
@@ -50,6 +53,10 @@ Q_SIGNALS:
 public Q_SLOTS:
     /** wraps setFontWeight to a simple on/off bold) */
     void setFontBold(bool);
+
+private:
+    QStringList m_history;
+    int m_historyPos;
 };
 
 #endif // CHATTEXTEDIT_H

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list