[kde-doc-english] [trojita] src/Gui: GUI: enable message scrolling via Home and End

Jan Kundrát jkt at flaska.net
Thu May 9 12:16:41 UTC 2013


Git commit 3577669fd41c1b65eb3fb2fc9f91aa08dd9134a2 by Jan Kundrát, on behalf of Thomas Lübking.
Committed on 09/05/2013 at 14:12.
Pushed by jkt into branch 'master'.

GUI: enable message scrolling via Home and End

Even with a pretty animation.

Signed-off-by: Jan Kundrát <jkt at flaska.net>

M  +19   -0    src/Gui/CompleteMessageWidget.cpp
M  +4    -0    src/Gui/CompleteMessageWidget.h
M  +3    -2    src/Gui/MessageView.cpp

http://commits.kde.org/trojita/3577669fd41c1b65eb3fb2fc9f91aa08dd9134a2

diff --git a/src/Gui/CompleteMessageWidget.cpp b/src/Gui/CompleteMessageWidget.cpp
index 6eb25d1..dcaa632 100644
--- a/src/Gui/CompleteMessageWidget.cpp
+++ b/src/Gui/CompleteMessageWidget.cpp
@@ -21,7 +21,10 @@
 */
 
 #include "CompleteMessageWidget.h"
+#include <QKeyEvent>
+#include <QPropertyAnimation>
 #include <QScrollArea>
+#include <QScrollBar>
 #include <QVBoxLayout>
 #include "FindBar.h"
 #include "MessageView.h"
@@ -37,6 +40,9 @@ CompleteMessageWidget::CompleteMessageWidget(QWidget *parent): QWidget(parent)
     QVBoxLayout *layout = new QVBoxLayout(this);
     layout->setContentsMargins(0, 0, 0, 0);
     layout->addWidget(area);
+    animator = new QPropertyAnimation(area->verticalScrollBar(), "value", this);
+    animator->setDuration(250); // the default, maybe play with values
+    animator->setEasingCurve(QEasingCurve::InOutCubic); // InOutQuad?
 
     m_findBar = new FindBar(this);
     layout->addWidget(m_findBar);
@@ -55,4 +61,17 @@ void CompleteMessageWidget::searchRequestedBy(QWebView *webView)
     }
 }
 
+void CompleteMessageWidget::keyPressEvent(QKeyEvent *ke)
+{
+    if (ke->key() == Qt::Key_Home) {
+        animator->setEndValue(area->verticalScrollBar()->minimum());
+        animator->start();
+    } else if (ke->key() == Qt::Key_End) {
+        animator->setEndValue(area->verticalScrollBar()->maximum());
+        animator->start();
+    } else { // noop, but hey.
+        QWidget::keyPressEvent(ke);
+    }
+}
+
 }
diff --git a/src/Gui/CompleteMessageWidget.h b/src/Gui/CompleteMessageWidget.h
index 1d662d6..52ad45e 100644
--- a/src/Gui/CompleteMessageWidget.h
+++ b/src/Gui/CompleteMessageWidget.h
@@ -26,6 +26,7 @@
 
 class QScrollArea;
 class QWebView;
+class QPropertyAnimation;
 
 namespace Gui
 {
@@ -41,6 +42,8 @@ public:
 
     MessageView *messageView;
     QScrollArea *area;
+protected:
+    void keyPressEvent(QKeyEvent *ke);
 
 private slots:
     void searchRequestedBy(QWebView *webView);
@@ -50,6 +53,7 @@ private:
     CompleteMessageWidget &operator=(const CompleteMessageWidget &); // don't implement
 
     FindBar *m_findBar;
+    QPropertyAnimation *animator;
 };
 
 }
diff --git a/src/Gui/MessageView.cpp b/src/Gui/MessageView.cpp
index 08f89dc..5e827f9 100644
--- a/src/Gui/MessageView.cpp
+++ b/src/Gui/MessageView.cpp
@@ -267,10 +267,11 @@ bool MessageView::eventFilter(QObject *object, QEvent *event)
         case Qt::Key_Down:
         case Qt::Key_PageUp:
         case Qt::Key_PageDown:
-        case Qt::Key_Home:
-        case Qt::Key_End:
             MessageView::event(event);
             return true;
+        case Qt::Key_Home:
+        case Qt::Key_End:
+            return false;
         default:
             return QObject::eventFilter(object, event);
         }


More information about the kde-doc-english mailing list