1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

QzTools: Add actionShortcut function

This commit is contained in:
David Rosca 2015-11-12 16:53:09 +01:00
parent 1e0cd8d12d
commit 9f6ec040bb
4 changed files with 12 additions and 29 deletions

View File

@ -88,23 +88,6 @@
#include <xcb/xcb_atom.h>
#endif
#ifdef Q_OS_WIN
#include <windows.h>
#ifndef WM_DWMCOMPOSITIONCHANGED
#define WM_DWMCOMPOSITIONCHANGED 0x031E
#endif
#endif /* Q_OS_WIN */
static QKeySequence actionShortcut(QKeySequence shortcut, QKeySequence fallBack, QKeySequence shortcutRTL = QKeySequence(), QKeySequence fallbackRTL = QKeySequence())
{
if (QApplication::isRightToLeft() && (!shortcutRTL.isEmpty() || !fallbackRTL.isEmpty())) {
return (shortcutRTL.isEmpty() ? fallbackRTL : shortcutRTL);
}
else {
return (shortcut.isEmpty() ? fallBack : shortcut);
}
}
BrowserWindow::BrowserWindow(Qz::BrowserWindowType type, const QUrl &startUrl)
: QMainWindow(0)
, m_startUrl(startUrl)
@ -463,7 +446,7 @@ void BrowserWindow::loadSettings()
settings.beginGroup("Web-Browser-Settings");
QAction *quitAction = m_mainMenu->action(QSL("Standard/Quit"));
if (settings.value("closeAppWithCtrlQ", true).toBool()) {
quitAction->setShortcut(actionShortcut(QKeySequence::Quit, QKeySequence(QSL("Ctrl+Q"))));
quitAction->setShortcut(QzTools::actionShortcut(QKeySequence::Quit, QKeySequence(QSL("Ctrl+Q"))));
} else {
quitAction->setShortcut(QKeySequence());
}

View File

@ -30,15 +30,6 @@
#include <QWebEngineHistory>
#include <QSqlQuery>
static QKeySequence actionShortcut(QKeySequence shortcut, QKeySequence fallback, QKeySequence shortcutRTL, QKeySequence fallbackRTL)
{
if (QApplication::isRightToLeft() && (!shortcutRTL.isEmpty() || !fallbackRTL.isEmpty())) {
return (shortcutRTL.isEmpty() ? fallbackRTL : shortcutRTL);
}
return (shortcut.isEmpty() ? fallback : shortcut);
}
HistoryMenu::HistoryMenu(QWidget* parent)
: Menu(parent)
{
@ -216,10 +207,10 @@ void HistoryMenu::init()
setTitle(tr("Hi&story"));
QAction* act = addAction(IconProvider::standardIcon(QStyle::SP_ArrowBack), tr("&Back"), this, SLOT(goBack()));
act->setShortcut(actionShortcut(QKeySequence::Back, Qt::ALT + Qt::Key_Left, QKeySequence::Forward, Qt::ALT + Qt::Key_Right));
act->setShortcut(QzTools::actionShortcut(QKeySequence::Back, Qt::ALT + Qt::Key_Left, QKeySequence::Forward, Qt::ALT + Qt::Key_Right));
act = addAction(IconProvider::standardIcon(QStyle::SP_ArrowForward), tr("&Forward"), this, SLOT(goForward()));
act->setShortcut(actionShortcut(QKeySequence::Forward, Qt::ALT + Qt::Key_Right, QKeySequence::Back, Qt::ALT + Qt::Key_Left));
act->setShortcut(QzTools::actionShortcut(QKeySequence::Forward, Qt::ALT + Qt::Key_Right, QKeySequence::Back, Qt::ALT + Qt::Key_Left));
act = addAction(QIcon::fromTheme("go-home"), tr("&Home"), this, SLOT(goHome()));
act->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Home));

View File

@ -695,6 +695,14 @@ bool QzTools::matchDomain(const QString &pattern, const QString &domain)
return index > 0 && domain[index - 1] == QLatin1Char('.');
}
QKeySequence QzTools::actionShortcut(QKeySequence shortcut, QKeySequence fallBack, QKeySequence shortcutRtl, QKeySequence fallbackRtl)
{
if (QApplication::isRightToLeft() && (!shortcutRtl.isEmpty() || !fallbackRtl.isEmpty()))
return shortcutRtl.isEmpty() ? fallbackRtl : shortcutRtl;
return shortcut.isEmpty() ? fallBack : shortcut;
}
static inline bool isQuote(const QChar &c)
{
return (c == QLatin1Char('"') || c == QLatin1Char('\''));

View File

@ -81,6 +81,7 @@ public:
static QString getSaveFileName(const QString &name, QWidget* parent = 0, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString* selectedFilter = 0, QFileDialog::Options options = 0);
static bool matchDomain(const QString &pattern, const QString &domain);
static QKeySequence actionShortcut(QKeySequence shortcut, QKeySequence fallBack, QKeySequence shortcutRtl = QKeySequence(), QKeySequence fallbackRtl = QKeySequence());
static QString operatingSystem();