diff options
author | Tobias Markmann <tm@ayena.de> | 2017-02-20 16:23:59 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2017-02-20 16:24:36 (GMT) |
commit | f4246a23eb76cb09c1a603d54891f80ec1e54eb5 (patch) | |
tree | b97ab65b1b07efac07b5a2ece4e9529400ee2852 /Swift/QtUI/QtTextEdit.cpp | |
parent | 9fe83ff62fb48662df7920afc0be71d04dafe3e4 (diff) | |
download | swift-f4246a23eb76cb09c1a603d54891f80ec1e54eb5.zip swift-f4246a23eb76cb09c1a603d54891f80ec1e54eb5.tar.bz2 |
Add alternative zoom shortcuts on macOS and workaround Qt bug
This adds the Ctrl + Minus and Ctrl + Equal shortcuts for
zoom out and zoom in respectively.
In addition, this commit provides a workaround for QTBUG-56571.
Test-Information:
Tested on macOS 10.12.3 with Qt 5.7.1. Tested with German
and UK keyboard layout. On UK layout both shortcuts,
Ctrl + (+/-) and Ctrl + (=/-) work. On German layout only
Ctrl + (+/-) works.
Change-Id: Ifbcab308c9a8f4c88b51978969c73c3c1138a9ba
Diffstat (limited to 'Swift/QtUI/QtTextEdit.cpp')
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index e9708bf..1b4d76d 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -1,91 +1,95 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/QtUI/QtTextEdit.h> #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> #include <boost/tuple/tuple.hpp> #include <QApplication> #include <QKeyEvent> #include <QKeySequence> #include <QMenu> #include <QTextDocument> #include <Swiften/Base/Log.h> #include <SwifTools/SpellChecker.h> #include <SwifTools/SpellCheckerFactory.h> #include <Swift/QtUI/QtSpellCheckerWindow.h> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtUISettingConstants.h> #include <Swift/QtUI/QtUtilities.h> namespace Swift { QtTextEdit::QtTextEdit(SettingsProvider* settings, QWidget* parent) : QTextEdit(parent), checker_(nullptr), highlighter_(nullptr) { connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged())); settings_ = settings; #ifdef HAVE_SPELLCHECKER setUpSpellChecker(); #endif handleTextChanged(); QTextOption textOption = document()->defaultTextOption(); textOption.setWrapMode(QTextOption::WordWrap); document()->setDefaultTextOption(textOption); } QtTextEdit::~QtTextEdit() { delete checker_; } void QtTextEdit::keyPressEvent(QKeyEvent* event) { int key = event->key(); Qt::KeyboardModifiers modifiers = event->modifiers(); if ((key == Qt::Key_Enter || key == Qt::Key_Return) && (modifiers == Qt::NoModifier || modifiers == Qt::KeypadModifier)) { emit returnPressed(); } else if (((key == Qt::Key_PageUp || key == Qt::Key_PageDown) && modifiers == Qt::ShiftModifier) || (key == Qt::Key_C && modifiers == Qt::ControlModifier && textCursor().selectedText().isEmpty()) || (key == Qt::Key_W && modifiers == Qt::ControlModifier) || (key == Qt::Key_PageUp && modifiers == Qt::ControlModifier) || (key == Qt::Key_PageDown && modifiers == Qt::ControlModifier) || (key == Qt::Key_Tab && modifiers == Qt::ControlModifier) || (key == Qt::Key_A && modifiers == Qt::AltModifier) || (key == Qt::Key_Tab) +#ifdef SWIFTEN_PLATFORM_MACOSX + || (key == Qt::Key_Minus && (modifiers & Qt::ControlModifier)) + || (key == Qt::Key_Equal && (modifiers & Qt::ControlModifier)) +#endif || (event->matches(QKeySequence::ZoomIn)) || (event->matches(QKeySequence::ZoomOut)) ) { emit unhandledKeyPressEvent(event); } else if ((key == Qt::Key_Up) || (key == Qt::Key_Down)) { 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); } } void QtTextEdit::setEmphasiseFocus(bool emphasise) { emphasiseFocus_ = emphasise; updateStyleSheet(); } void QtTextEdit::setCorrectionHighlight(bool correctionHighlight) { correctionHighlight_ = correctionHighlight; updateStyleSheet(); } |