[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepim] pimcommon/texteditor: Add support for shortcut
From: Montel Laurent <montel () kde ! org>
Date: 2013-10-22 20:53:13
Message-ID: E1VYiwz-0002Me-5d () scm ! kde ! org
[Download RAW message or body]
Git commit ea82baab8846f8aa98df1fb9f90620af6a7d50d3 by Montel Laurent.
Committed on 22/10/2013 at 20:49.
Pushed by mlaurent into branch 'master'.
Add support for shortcut
M +83 -0 pimcommon/texteditor/plaintexteditor/plaintexteditor.cpp
M +4 -1 pimcommon/texteditor/plaintexteditor/plaintexteditor.h
M +83 -0 pimcommon/texteditor/richtexteditor/richtexteditor.cpp
M +4 -0 pimcommon/texteditor/richtexteditor/richtexteditor.h
http://commits.kde.org/kdepim/ea82baab8846f8aa98df1fb9f90620af6a7d50d3
diff --git a/pimcommon/texteditor/plaintexteditor/plaintexteditor.cpp \
b/pimcommon/texteditor/plaintexteditor/plaintexteditor.cpp index 24fa54b..2401a58 \
100644
--- a/pimcommon/texteditor/plaintexteditor/plaintexteditor.cpp
+++ b/pimcommon/texteditor/plaintexteditor/plaintexteditor.cpp
@@ -280,4 +280,87 @@ void PlainTextEditor::highlightWord( int length, int pos )
ensureCursorVisible();
}
+static void deleteWord(QTextCursor cursor, QTextCursor::MoveOperation op)
+{
+ cursor.clearSelection();
+ cursor.movePosition( op, QTextCursor::KeepAnchor );
+ cursor.removeSelectedText();
+}
+
+void PlainTextEditor::deleteWordBack()
+{
+ deleteWord(textCursor(), QTextCursor::PreviousWord);
+}
+
+void PlainTextEditor::deleteWordForward()
+{
+ deleteWord(textCursor(), QTextCursor::WordRight);
+}
+
+bool PlainTextEditor::event(QEvent* ev)
+{
+ if (ev->type() == QEvent::ShortcutOverride) {
+ QKeyEvent *e = static_cast<QKeyEvent *>( ev );
+ if (overrideShortcut(e)) {
+ e->accept();
+ return true;
+ }
+ }
+ return QPlainTextEdit::event(ev);
+}
+
+bool PlainTextEditor::overrideShortcut(const QKeyEvent* event)
+{
+ const int key = event->key() | event->modifiers();
+
+ if ( KStandardShortcut::copy().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::paste().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::cut().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::undo().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::redo().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::deleteWordBack().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::deleteWordForward().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::backwardWord().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::forwardWord().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::next().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::prior().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::begin().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::end().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::beginningOfLine().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::endOfLine().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::pasteSelection().contains( key ) ) {
+ return true;
+ } else if (d->hasSearchSupport && KStandardShortcut::find().contains(key)) {
+ return true;
+ } else if (d->hasSearchSupport && KStandardShortcut::findNext().contains(key)) {
+ return true;
+ } else if (d->hasSearchSupport && KStandardShortcut::replace().contains(key)) {
+ return true;
+ } else if (event->matches(QKeySequence::SelectAll)) { // currently missing in \
QTextEdit + return true;
+ } else if (event->modifiers() == Qt::ControlModifier &&
+ (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
+ qobject_cast<KDialog*>(window()) ) {
+ // ignore Ctrl-Return so that KDialogs can close the dialog
+ return true;
+ }
+ return false;
+}
+
+
#include "plaintexteditor.moc"
diff --git a/pimcommon/texteditor/plaintexteditor/plaintexteditor.h \
b/pimcommon/texteditor/plaintexteditor/plaintexteditor.h index ba4181e..bee6454 \
100644
--- a/pimcommon/texteditor/plaintexteditor/plaintexteditor.h
+++ b/pimcommon/texteditor/plaintexteditor/plaintexteditor.h
@@ -61,7 +61,7 @@ protected:
protected:
void contextMenuEvent( QContextMenuEvent *event );
void wheelEvent( QWheelEvent *event );
-
+ bool event(QEvent* ev);
Q_SIGNALS:
void findText();
@@ -71,6 +71,9 @@ Q_SIGNALS:
void languageChanged(const QString &);
private:
+ bool overrideShortcut(const QKeyEvent* event);
+ void deleteWordBack();
+ void deleteWordForward();
void highlightWord( int length, int pos );
class PlainTextEditorPrivate;
PlainTextEditorPrivate *const d;
diff --git a/pimcommon/texteditor/richtexteditor/richtexteditor.cpp \
b/pimcommon/texteditor/richtexteditor/richtexteditor.cpp index 634c6dc..d8f243c \
100644
--- a/pimcommon/texteditor/richtexteditor/richtexteditor.cpp
+++ b/pimcommon/texteditor/richtexteditor/richtexteditor.cpp
@@ -514,4 +514,87 @@ void RichTextEditor::contextMenuEvent(QContextMenuEvent *event)
}
}
+static void deleteWord(QTextCursor cursor, QTextCursor::MoveOperation op)
+{
+ cursor.clearSelection();
+ cursor.movePosition( op, QTextCursor::KeepAnchor );
+ cursor.removeSelectedText();
+}
+
+void RichTextEditor::deleteWordBack()
+{
+ deleteWord(textCursor(), QTextCursor::PreviousWord);
+}
+
+void RichTextEditor::deleteWordForward()
+{
+ deleteWord(textCursor(), QTextCursor::WordRight);
+}
+
+bool RichTextEditor::event(QEvent* ev)
+{
+ if (ev->type() == QEvent::ShortcutOverride) {
+ QKeyEvent *e = static_cast<QKeyEvent *>( ev );
+ if (overrideShortcut(e)) {
+ e->accept();
+ return true;
+ }
+ }
+ return QTextEdit::event(ev);
+}
+
+bool RichTextEditor::overrideShortcut(const QKeyEvent* event)
+{
+ const int key = event->key() | event->modifiers();
+
+ if ( KStandardShortcut::copy().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::paste().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::cut().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::undo().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::redo().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::deleteWordBack().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::deleteWordForward().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::backwardWord().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::forwardWord().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::next().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::prior().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::begin().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::end().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::beginningOfLine().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::endOfLine().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::pasteSelection().contains( key ) ) {
+ return true;
+ } else if (d->hasSearchSupport && KStandardShortcut::find().contains(key)) {
+ return true;
+ } else if (d->hasSearchSupport && KStandardShortcut::findNext().contains(key)) {
+ return true;
+ } else if (d->hasSearchSupport && KStandardShortcut::replace().contains(key)) {
+ return true;
+ } else if (event->matches(QKeySequence::SelectAll)) { // currently missing in \
QTextEdit + return true;
+ } else if (event->modifiers() == Qt::ControlModifier &&
+ (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
+ qobject_cast<KDialog*>(window()) ) {
+ // ignore Ctrl-Return so that KDialogs can close the dialog
+ return true;
+ }
+ return false;
+}
+
+
#include "richtexteditor.moc"
diff --git a/pimcommon/texteditor/richtexteditor/richtexteditor.h \
b/pimcommon/texteditor/richtexteditor/richtexteditor.h index b2b5990..60e99e3 100644
--- a/pimcommon/texteditor/richtexteditor/richtexteditor.h
+++ b/pimcommon/texteditor/richtexteditor/richtexteditor.h
@@ -69,6 +69,7 @@ protected:
void contextMenuEvent( QContextMenuEvent *event );
void wheelEvent( QWheelEvent *event );
void focusInEvent( QFocusEvent *event );
+ bool event(QEvent* ev);
Q_SIGNALS:
void findText();
@@ -79,6 +80,9 @@ Q_SIGNALS:
void spellCheckStatus(const QString &);
private:
+ bool overrideShortcut(const QKeyEvent* event);
+ void deleteWordBack();
+ void deleteWordForward();
void defaultPopupMenu(const QPoint &pos);
void setHighlighter(Sonnet::Highlighter *_highLighter);
void highlightWord( int length, int pos );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic