diff options
author | Kevin Smith <git@kismith.co.uk> | 2013-11-10 15:56:22 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2013-11-10 15:56:22 (GMT) |
commit | 0e29a6c750f30a089923b6f16d303b9640e0f589 (patch) | |
tree | 6516ecf5323ac693da8d98e3cfd4e5d95ca7bd04 /Swift/QtUI | |
parent | 238ee0861cc2f9b0143bce986abbd15ce638c561 (diff) | |
download | swift-0e29a6c750f30a089923b6f16d303b9640e0f589.zip swift-0e29a6c750f30a089923b6f16d303b9640e0f589.tar.bz2 |
Make Ctrl-K to delete to end of the line in chat input.
Change-Id: I04f34018fd99c687a41724d7a32d2b640757359f
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtTabbable.cpp | 13 | ||||
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 26 | ||||
-rw-r--r-- | Swift/QtUI/QtUtilities.cpp | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtUtilities.h | 7 |
4 files changed, 28 insertions, 19 deletions
diff --git a/Swift/QtUI/QtTabbable.cpp b/Swift/QtUI/QtTabbable.cpp index 5659157..124d1b4 100644 --- a/Swift/QtUI/QtTabbable.cpp +++ b/Swift/QtUI/QtTabbable.cpp @@ -13,17 +13,10 @@ #include <Swiften/Base/Platform.h> #include <Swift/QtUI/QtChatTabs.h> +#include <Swift/QtUI/QtUtilities.h> namespace Swift { -namespace { -#ifdef SWIFTEN_PLATFORM_MACOSX -const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::MetaModifier; -#else -const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::ControlModifier; -#endif -} - QtTabbable::QtTabbable() : QWidget() { shortcuts << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), window(), SLOT(close())); shortcuts << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp), window(), SIGNAL(requestPreviousTab())); @@ -52,9 +45,9 @@ bool QtTabbable::event(QEvent* event) { if (keyEvent) { // According to Qt's focus documentation, one can only override CTRL+TAB via reimplementing QWidget::event(). #ifdef SWIFTEN_PLATFORM_LINUX - if (keyEvent->modifiers() == ctrlHardwareKeyModifier && keyEvent->key() == Qt::Key_Tab && event->type() != QEvent::KeyRelease) { + if (keyEvent->modifiers() == QtUtilities::ctrlHardwareKeyModifier && keyEvent->key() == Qt::Key_Tab && event->type() != QEvent::KeyRelease) { #else - if (keyEvent->modifiers() == ctrlHardwareKeyModifier && keyEvent->key() == Qt::Key_Tab) { + if (keyEvent->modifiers() == QtUtilities::ctrlHardwareKeyModifier && keyEvent->key() == Qt::Key_Tab) { #endif emit requestNextTab(); return true; diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 2c4677e..cac8bb4 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -1,28 +1,31 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2013 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ +#include <Swift/QtUI/QtTextEdit.h> + #include <boost/tuple/tuple.hpp> #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> +#include <QApplication> +#include <QFontMetrics> +#include <QKeyEvent> +#include <QDebug> +#include <QMenu> + #include <Swiften/Base/foreach.h> #include <SwifTools/SpellCheckerFactory.h> #include <SwifTools/SpellChecker.h> -#include <Swift/QtUI/QtTextEdit.h> -#include <Swift/QtUI/QtSwiftUtil.h> -#include <Swift/QtUI/QtSpellCheckerWindow.h> #include <Swift/Controllers/SettingConstants.h> -#include <QApplication> -#include <QFontMetrics> -#include <QKeyEvent> -#include <QDebug> -#include <QMenu> +#include <Swift/QtUI/QtSpellCheckerWindow.h> +#include <Swift/QtUI/QtSwiftUtil.h> +#include <Swift/QtUI/QtUtilities.h> namespace Swift { @@ -63,6 +66,11 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) { emit unhandledKeyPressEvent(event); QTextEdit::keyPressEvent(event); } + else if ((key == Qt::Key_K && modifiers == QtUtilities::ctrlHardwareKeyModifier)) { + QTextCursor cursor = textCursor(); + cursor.setPosition(toPlainText().size(), QTextCursor::KeepAnchor); + cursor.removeSelectedText(); + } else { QTextEdit::keyPressEvent(event); #ifdef HAVE_SPELLCHECKER diff --git a/Swift/QtUI/QtUtilities.cpp b/Swift/QtUI/QtUtilities.cpp index e9aa4a4..5ae1b13 100644 --- a/Swift/QtUI/QtUtilities.cpp +++ b/Swift/QtUI/QtUtilities.cpp @@ -18,6 +18,7 @@ namespace QtUtilities { + void setX11Resource(QWidget* widget, const QString& c) { #if defined (Q_OS_UNIX) && !defined(Q_OS_MAC) char res_class[] = SWIFT_APPLICATION_NAME; diff --git a/Swift/QtUI/QtUtilities.h b/Swift/QtUI/QtUtilities.h index 40c16bc..6f82dfd 100644 --- a/Swift/QtUI/QtUtilities.h +++ b/Swift/QtUI/QtUtilities.h @@ -9,7 +9,14 @@ class QWidget; class QString; +#include <QKeyEvent> + namespace QtUtilities { void setX11Resource(QWidget* widget, const QString& c); QString htmlEscape(const QString& s); + #ifdef SWIFTEN_PLATFORM_MACOSX + const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::MetaModifier; + #else + const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::ControlModifier; + #endif } |