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 | |
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
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 6 | ||||
-rw-r--r-- | Swift/QtUI/QtWebView.cpp | 6 |
2 files changed, 8 insertions, 4 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(); } diff --git a/Swift/QtUI/QtWebView.cpp b/Swift/QtUI/QtWebView.cpp index abdc17a..967be1a 100644 --- a/Swift/QtUI/QtWebView.cpp +++ b/Swift/QtUI/QtWebView.cpp @@ -1,68 +1,68 @@ /* - * 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/QtWebView.h> #include <boost/numeric/conversion/cast.hpp> #include <QFocusEvent> #include <QKeyEvent> #include <QKeySequence> #include <QMenu> #include <Swiften/Base/Log.h> namespace Swift { QtWebView::QtWebView(QWidget* parent) : QWebView(parent), fontSizeIsMinimal(false) { setRenderHint(QPainter::SmoothPixmapTransform); filteredActions.push_back(QWebPage::CopyLinkToClipboard); filteredActions.push_back(QWebPage::CopyImageToClipboard); filteredActions.push_back(QWebPage::Copy); if (Log::getLogLevel() == Log::debug) { filteredActions.push_back(QWebPage::InspectElement); } } void QtWebView::keyPressEvent(QKeyEvent* event) { Qt::KeyboardModifiers modifiers = event->modifiers(); int key = event->key(); - if (event->matches(QKeySequence::ZoomIn)) { + if (event->matches(QKeySequence::ZoomIn) || (key == Qt::Key_Equal && (modifiers & Qt::ControlModifier))) { event->accept(); emit fontGrowRequested(); return; } - if (event->matches(QKeySequence::ZoomOut)) { + if (event->matches(QKeySequence::ZoomOut) || (key == Qt::Key_Minus && (modifiers & Qt::ControlModifier))) { event->accept(); emit fontShrinkRequested(); return; } if (modifiers == Qt::ShiftModifier && (key == Qt::Key_PageUp || key == Qt::Key_PageDown)) { modifiers = Qt::NoModifier; } QKeyEvent* translatedEvent = new QKeyEvent(QEvent::KeyPress, key, modifiers, event->text(), event->isAutoRepeat(), boost::numeric_cast<unsigned short>(event->count())); QWebView::keyPressEvent(translatedEvent); delete translatedEvent; } void QtWebView::dragEnterEvent(QDragEnterEvent*) { } void QtWebView::setFontSizeIsMinimal(bool minimum) { fontSizeIsMinimal = minimum; } void QtWebView::contextMenuEvent(QContextMenuEvent* ev) { // Filter out the relevant actions from the standard actions QMenu* menu = page()->createStandardContextMenu(); QList<QAction*> actions(menu->actions()); |