From e5e5cec7a50fc62c8d043bb1b6d1993575cc230c Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 4 Mar 2012 18:30:34 +0100 Subject: [PATCH] Added Access Keys Navigation plugin. Closes #288 --- scripts/plugin_translations.sh | 2 + src/lib/app/qupzilla.cpp | 8 +- src/lib/lib.pro | 6 +- src/lib/other/licenseviewer.cpp | 35 ++ src/lib/other/licenseviewer.h | 33 ++ src/lib/preferences/preferences.cpp | 2 +- src/lib/preferences/thememanager.cpp | 16 +- src/lib/preferences/thememanager.h | 6 +- .../AccessKeysNavigation.pro | 21 ++ .../AccessKeysNavigation/akn_handler.cpp | 325 ++++++++++++++++++ .../AccessKeysNavigation/akn_handler.h | 71 ++++ .../AccessKeysNavigation/akn_plugin.cpp | 88 +++++ src/plugins/AccessKeysNavigation/akn_plugin.h | 47 +++ src/plugins/AccessKeysNavigation/akn_res.qrc | 6 + .../AccessKeysNavigation/akn_settings.cpp | 66 ++++ .../AccessKeysNavigation/akn_settings.h | 48 +++ .../AccessKeysNavigation/akn_settings.ui | 144 ++++++++ .../AccessKeysNavigation/data/copyright | 20 ++ .../AccessKeysNavigation/data/icon.png | Bin 0 -> 656 bytes .../translations/cs_CZ.ts | 47 +++ src/plugins/MouseGestures/MouseGestures.pro | 6 +- src/plugins/MouseGestures/mousegestures.cpp | 22 +- src/plugins/MouseGestures/mousegestures.h | 18 +- .../MouseGestures/mousegesturesplugin.cpp | 19 +- .../MouseGestures/mousegesturesplugin.h | 17 + .../mousegesturessettingsdialog.cpp | 30 +- .../mousegesturessettingsdialog.h | 17 + src/plugins/plugins.pro | 2 +- 28 files changed, 1092 insertions(+), 30 deletions(-) create mode 100644 src/lib/other/licenseviewer.cpp create mode 100644 src/lib/other/licenseviewer.h create mode 100644 src/plugins/AccessKeysNavigation/AccessKeysNavigation.pro create mode 100644 src/plugins/AccessKeysNavigation/akn_handler.cpp create mode 100644 src/plugins/AccessKeysNavigation/akn_handler.h create mode 100644 src/plugins/AccessKeysNavigation/akn_plugin.cpp create mode 100644 src/plugins/AccessKeysNavigation/akn_plugin.h create mode 100644 src/plugins/AccessKeysNavigation/akn_res.qrc create mode 100644 src/plugins/AccessKeysNavigation/akn_settings.cpp create mode 100644 src/plugins/AccessKeysNavigation/akn_settings.h create mode 100644 src/plugins/AccessKeysNavigation/akn_settings.ui create mode 100644 src/plugins/AccessKeysNavigation/data/copyright create mode 100644 src/plugins/AccessKeysNavigation/data/icon.png create mode 100644 src/plugins/AccessKeysNavigation/translations/cs_CZ.ts diff --git a/scripts/plugin_translations.sh b/scripts/plugin_translations.sh index 0e88c42b9..d34c76e63 100755 --- a/scripts/plugin_translations.sh +++ b/scripts/plugin_translations.sh @@ -4,5 +4,7 @@ lupdate ../src/plugins/TestPlugin/TestPlugin.pro -no-obsolete lupdate ../src/plugins/MouseGestures/MouseGestures.pro -no-obsolete +lupdate ../src/plugins/AccessKeysNavigation/AccessKeysNavigation.pro -no-obsolete + read -p "Press [ENTER] to close terminal" exit diff --git a/src/lib/app/qupzilla.cpp b/src/lib/app/qupzilla.cpp index 5269636b4..1c0abd75f 100644 --- a/src/lib/app/qupzilla.cpp +++ b/src/lib/app/qupzilla.cpp @@ -1416,7 +1416,13 @@ void QupZilla::searchOnPage() void QupZilla::openFile() { - const QString &filePath = QFileDialog::getOpenFileName(this, tr("Open file..."), QDir::homePath(), "(*.html *.htm *.jpg *.png)"); + const QString &fileTypes = QString("%1(*.html *.htm *.shtml *.shtm);;" + "%2(*.txt);;" + "%3(*.png *.jpg *.jpeg *.bmp *.gif *.svg);;" + "%4(*.*)").arg(tr("HTML files"), tr("Image files"), tr("Text files"), tr("All files")); + + const QString &filePath = QFileDialog::getOpenFileName(this, tr("Open file..."), QDir::homePath(), fileTypes); + if (!filePath.isEmpty()) { loadAddress(QUrl::fromLocalFile(filePath)); } diff --git a/src/lib/lib.pro b/src/lib/lib.pro index dc1cd7e3b..2e3a4c571 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -163,7 +163,8 @@ SOURCES += \ webview/webview.cpp \ webview/webviewsettings.cpp \ preferences/pluginlistdelegate.cpp \ - popupwindow/popupstatusbarmessage.cpp + popupwindow/popupstatusbarmessage.cpp \ + other/licenseviewer.cpp HEADERS += \ 3rdparty/qtwin.h \ @@ -298,7 +299,8 @@ HEADERS += \ app/qz_namespace.h \ webview/webviewsettings.h \ preferences/pluginlistdelegate.h \ - popupwindow/popupstatusbarmessage.h + popupwindow/popupstatusbarmessage.h \ + other/licenseviewer.h FORMS += \ preferences/autofillmanager.ui \ diff --git a/src/lib/other/licenseviewer.cpp b/src/lib/other/licenseviewer.cpp new file mode 100644 index 000000000..04f701323 --- /dev/null +++ b/src/lib/other/licenseviewer.cpp @@ -0,0 +1,35 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#include "licenseviewer.h" +#include "globalfunctions.h" + +LicenseViewer::LicenseViewer(QWidget *parent) + : QTextBrowser() +{ + setAttribute(Qt::WA_DeleteOnClose); + setWindowTitle(tr("License Viewer")); + + resize(450, 500); + + qz_centerWidgetToParent(this, parent); +} + +void LicenseViewer::setLicenseFile(const QString &fileName) +{ + setText(qz_readAllFileContents(fileName)); +} diff --git a/src/lib/other/licenseviewer.h b/src/lib/other/licenseviewer.h new file mode 100644 index 000000000..9b1527667 --- /dev/null +++ b/src/lib/other/licenseviewer.h @@ -0,0 +1,33 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#ifndef LICENSEVIEWER_H +#define LICENSEVIEWER_H + +#include + +class LicenseViewer : public QTextBrowser +{ + Q_OBJECT + +public: + explicit LicenseViewer(QWidget *parent = 0); + + void setLicenseFile(const QString &fileName); +}; + +#endif // LICENSEVIEWER_H diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index edb01bef1..a344b2ec1 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -146,7 +146,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) startProfileIndexChanged(ui->startProfile->currentText()); //APPEREANCE - m_themesManager = new ThemeManager(ui->themesWidget); + m_themesManager = new ThemeManager(ui->themesWidget, this); settings.beginGroup("Browser-View-Settings"); ui->showStatusbar->setChecked(settings.value("showStatusBar", true).toBool()); ui->showBookmarksToolbar->setChecked(p_QupZilla->bookmarksToolbar()->isVisible()); diff --git a/src/lib/preferences/thememanager.cpp b/src/lib/preferences/thememanager.cpp index 4509aa3b3..9cc2bf3e4 100644 --- a/src/lib/preferences/thememanager.cpp +++ b/src/lib/preferences/thememanager.cpp @@ -20,6 +20,8 @@ #include "mainapplication.h" #include "globalfunctions.h" #include "settings.h" +#include "licenseviewer.h" +#include "preferences.h" #include #include @@ -30,9 +32,10 @@ #define DEFAULT_THEME_NAME "linux" #endif -ThemeManager::ThemeManager(QWidget* parent) +ThemeManager::ThemeManager(QWidget* parent, Preferences *preferences) : QWidget() , ui(new Ui::ThemeManager) + , m_preferences(preferences) { ui->setupUi(parent); ui->license->hide(); @@ -78,14 +81,9 @@ void ThemeManager::showLicense() Theme currentTheme = m_themeHash[currentItem->data(Qt::UserRole).toString()]; - QTextBrowser* b = new QTextBrowser(); - b->setAttribute(Qt::WA_DeleteOnClose); - b->setWindowTitle(tr("License Viewer")); -// b->move(mapToGlobal(parent()->pos())); - b->resize(450, 500); - b->setText(currentTheme.license); - qz_centerWidgetOnScreen(b); - b->show(); + LicenseViewer* v = new LicenseViewer(m_preferences); + v->setText(currentTheme.license); + v->show(); } void ThemeManager::currentChanged() diff --git a/src/lib/preferences/thememanager.h b/src/lib/preferences/thememanager.h index 30239443b..e78b4a1c6 100644 --- a/src/lib/preferences/thememanager.h +++ b/src/lib/preferences/thememanager.h @@ -30,12 +30,14 @@ namespace Ui class ThemeManager; } +class Preferences; + class QT_QUPZILLA_EXPORT ThemeManager : public QWidget { Q_OBJECT public: - explicit ThemeManager(QWidget* parent); + explicit ThemeManager(QWidget *parent, Preferences *preferences); ~ThemeManager(); void save(); @@ -58,6 +60,8 @@ private: Theme parseTheme(const QString &name); Ui::ThemeManager* ui; + Preferences* m_preferences; + QString m_activeTheme; QHash m_themeHash; }; diff --git a/src/plugins/AccessKeysNavigation/AccessKeysNavigation.pro b/src/plugins/AccessKeysNavigation/AccessKeysNavigation.pro new file mode 100644 index 000000000..86c1854ba --- /dev/null +++ b/src/plugins/AccessKeysNavigation/AccessKeysNavigation.pro @@ -0,0 +1,21 @@ +QT += webkit +TARGET = AccessKeysNavigation + +SOURCES = \ + akn_plugin.cpp \ + akn_handler.cpp \ + akn_settings.cpp + +HEADERS = \ + akn_plugin.h \ + akn_handler.h \ + akn_settings.h + +FORMS += \ + akn_settings.ui + +RESOURCES = akn_res.qrc + +TRANSLATIONS = translations/cs_CZ.ts \ + +include(../../plugins.pri) diff --git a/src/plugins/AccessKeysNavigation/akn_handler.cpp b/src/plugins/AccessKeysNavigation/akn_handler.cpp new file mode 100644 index 000000000..8a1223824 --- /dev/null +++ b/src/plugins/AccessKeysNavigation/akn_handler.cpp @@ -0,0 +1,325 @@ +/* ============================================================ +* Access Keys Navigation plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +/* + * Copyright 2008-2009 Benjamin C. Meyer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ +#include "akn_handler.h" +#include "webview.h" + +#include +#include +#include +#include +#include +#include +#include + +Qt::Key keyFromCode(int code) +{ + switch (code) { + case 0: + return Qt::Key_Control; + + case 1: + return Qt::Key_Alt; + + case 2: + return Qt::Key_Shift; + + default: + // Using default shortcut + return Qt::Key_Control; + } +} + +AKN_Handler::AKN_Handler(const QString &sPath, QObject* parent) + : QObject(parent) + , m_view(0) + , m_settingsPath(sPath) +{ + loadSettings(); +} + +QString AKN_Handler::settingsPath() +{ + return m_settingsPath; +} + +void AKN_Handler::loadSettings() +{ + QSettings settings(m_settingsPath, QSettings::IniFormat); + + settings.beginGroup("AccessKeysNavigation"); + m_key = keyFromCode(settings.value("Key", 0).toInt()); + m_isDoublePress = settings.value("DoublePress", true).toBool(); + settings.endGroup(); +} + +bool AKN_Handler::handleKeyPress(QObject* obj, QKeyEvent* event) +{ + WebView* view = qobject_cast(obj); + if (!view) { + return false; + } + + if (m_accessKeysVisible) { + handleAccessKey(event); + return true; + } + + if (event->key() != m_key) { + return false; + } + + m_view = view; + + if (!m_isDoublePress) { + triggerShowAccessKeys(); + } + else { + if (!m_lastKeyPressTime.isValid()) { + // It is the first press of our button + m_lastKeyPressTime = QTime::currentTime(); + } + else { + // It is the second press of our button + if (QTime(m_lastKeyPressTime).addMSecs(500) >= QTime::currentTime()) { + triggerShowAccessKeys(); + } + else { + m_lastKeyPressTime = QTime::currentTime(); + } + } + } + + return false; +} + +bool AKN_Handler::eventFilter(QObject* obj, QEvent* event) +{ + if (obj != m_view) { + return false; + } + + switch (event->type()) { + case QEvent::FocusOut: + case QEvent::Wheel: + hideAccessKeys(); + break; + + default: + break; + } + + return false; +} + +void AKN_Handler::triggerShowAccessKeys() +{ + if (m_accessKeysVisible) { + hideAccessKeys(); + } + else { + QTimer::singleShot(0, this, SLOT(showAccessKeys())); + } +} + +void AKN_Handler::handleAccessKey(QKeyEvent* event) +{ + if (event->key() == m_key) { + hideAccessKeys(); + return; + } + + QString text = event->text(); + if (text.isEmpty()) { + return; + } + + QChar key = text.at(0).toUpper(); + + if (m_accessKeyNodes.contains(key)) { + QWebElement element = m_accessKeyNodes[key]; + QPoint p = element.geometry().center(); + QWebFrame* frame = element.webFrame(); + + if (!frame) { + return; + } + + do { + p -= frame->scrollPosition(); + frame = frame->parentFrame(); + } + while (frame && frame != m_view->page()->mainFrame()); + + QMouseEvent pevent(QEvent::MouseButtonPress, p, Qt::LeftButton, 0, 0); + qApp->sendEvent(m_view, &pevent); + + QMouseEvent revent(QEvent::MouseButtonRelease, p, Qt::LeftButton, 0, 0); + qApp->sendEvent(m_view, &revent); + + hideAccessKeys(); + } +} + +void AKN_Handler::showAccessKeys() +{ + QWebPage* page = m_view->page(); + + // Install event filter and connect loadStarted + m_accessKeysVisible = true; + qApp->installEventFilter(this); + connect(m_view, SIGNAL(loadStarted()), this, SLOT(hideAccessKeys())); + + QStringList supportedElement; + supportedElement << QLatin1String("input") + << QLatin1String("a") + << QLatin1String("area") + << QLatin1String("button") + << QLatin1String("label") + << QLatin1String("legend") + << QLatin1String("textarea"); + + QList unusedKeys; + for (char c = 'A'; c <= 'Z'; ++c) { + unusedKeys << QLatin1Char(c); + } + for (char c = '0'; c <= '9'; ++c) { + unusedKeys << QLatin1Char(c); + } + + QRect viewport = QRect(page->mainFrame()->scrollPosition(), page->viewportSize()); + // Priority first goes to elements with accesskey attributes + QList alreadyLabeled; + foreach(const QString & elementType, supportedElement) { + QList result = page->mainFrame()->findAllElements(elementType).toList(); + foreach(const QWebElement & element, result) { + const QRect geometry = element.geometry(); + if (geometry.size().isEmpty() + || !viewport.contains(geometry.topLeft())) { + continue; + } + QString accessKeyAttribute = element.attribute(QLatin1String("accesskey")).toUpper(); + if (accessKeyAttribute.isEmpty()) { + continue; + } + QChar accessKey; + for (int i = 0; i < accessKeyAttribute.count(); i += 2) { + const QChar &possibleAccessKey = accessKeyAttribute[i]; + if (unusedKeys.contains(possibleAccessKey)) { + accessKey = possibleAccessKey; + break; + } + } + if (accessKey.isNull()) { + continue; + } + unusedKeys.removeOne(accessKey); + makeAccessKeyLabel(accessKey, element); + alreadyLabeled.append(element); + } + } + + // Pick an access key first from the letters in the text and then from the + // list of unused access keys + foreach(const QString & elementType, supportedElement) { + QWebElementCollection result = page->mainFrame()->findAllElements(elementType); + foreach(const QWebElement & element, result) { + const QRect geometry = element.geometry(); + if (unusedKeys.isEmpty() + || alreadyLabeled.contains(element) + || geometry.size().isEmpty() + || !viewport.contains(geometry.topLeft())) { + continue; + } + QChar accessKey; + QString text = element.toPlainText().toUpper(); + for (int i = 0; i < text.count(); ++i) { + const QChar &c = text.at(i); + if (unusedKeys.contains(c)) { + accessKey = c; + break; + } + } + if (accessKey.isNull()) { + accessKey = unusedKeys.takeFirst(); + } + unusedKeys.removeOne(accessKey); + makeAccessKeyLabel(accessKey, element); + } + } +} + +void AKN_Handler::hideAccessKeys() +{ + if (!m_accessKeyLabels.isEmpty()) { + for (int i = 0; i < m_accessKeyLabels.count(); ++i) { + QLabel* label = m_accessKeyLabels[i]; + label->hide(); + label->deleteLater(); + } + m_accessKeyLabels.clear(); + m_accessKeyNodes.clear(); + m_view->update(); + + // Uninstall event filter and disconnect loadStarted + qApp->removeEventFilter(this); + disconnect(m_view, SIGNAL(loadStarted()), this, SLOT(hideAccessKeys())); + } + + m_accessKeysVisible = false; +} + +void AKN_Handler::makeAccessKeyLabel(const QChar &accessKey, const QWebElement &element) +{ + QLabel* label = new QLabel(m_view); + label->setText(QString(QLatin1String("%1")).arg(accessKey)); + + QPalette p = QToolTip::palette(); + QColor color = QColor(220, 243, 253); + color.setAlpha(175); + p.setColor(QPalette::Window, color); + + label->setPalette(p); + label->setAutoFillBackground(true); + label->setFrameStyle(QFrame::Box | QFrame::Plain); + QPoint point = element.geometry().center(); + point -= m_view->page()->mainFrame()->scrollPosition(); + label->move(point); + label->show(); + point.setX(point.x() - label->width() / 2); + label->move(point); + m_accessKeyLabels.append(label); + m_accessKeyNodes[accessKey] = element; +} diff --git a/src/plugins/AccessKeysNavigation/akn_handler.h b/src/plugins/AccessKeysNavigation/akn_handler.h new file mode 100644 index 000000000..395378591 --- /dev/null +++ b/src/plugins/AccessKeysNavigation/akn_handler.h @@ -0,0 +1,71 @@ +/* ============================================================ +* Access Keys Navigation plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#ifndef AKN_HANDLER_H +#define AKN_HANDLER_H + +#include +#include +#include +#include + +class QKeyEvent; +class QWebElement; +class QTime; +class QLabel; + +class WebView; + +class AKN_Handler : public QObject +{ + Q_OBJECT +public: + explicit AKN_Handler(const QString &sPath, QObject* parent = 0); + + QString settingsPath(); + void loadSettings(); + + bool handleKeyPress(QObject* obj, QKeyEvent* event); + bool eventFilter(QObject* obj, QEvent* event); + +signals: + +public slots: + +private slots: + void showAccessKeys(); + void hideAccessKeys(); + +private: + void triggerShowAccessKeys(); + + void makeAccessKeyLabel(const QChar &accessKey, const QWebElement &element); + void handleAccessKey(QKeyEvent* event); + + WebView* m_view; + + QList m_accessKeyLabels; + QHash m_accessKeyNodes; + bool m_accessKeysVisible; + + Qt::Key m_key; + bool m_isDoublePress; + QTime m_lastKeyPressTime; + QString m_settingsPath; +}; + +#endif // AKN_HANDLER_H diff --git a/src/plugins/AccessKeysNavigation/akn_plugin.cpp b/src/plugins/AccessKeysNavigation/akn_plugin.cpp new file mode 100644 index 000000000..9a4c6d8a3 --- /dev/null +++ b/src/plugins/AccessKeysNavigation/akn_plugin.cpp @@ -0,0 +1,88 @@ +/* ============================================================ +* Access Keys Navigation plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#include "akn_plugin.h" +#include "akn_handler.h" +#include "akn_settings.h" +#include "pluginproxy.h" +#include "qupzilla.h" + +#include + +AKN_Plugin::AKN_Plugin() + : QObject() +{ +} + +PluginSpec AKN_Plugin::pluginSpec() +{ + PluginSpec spec; + spec.name = "Access Keys Navigation"; + spec.info = "Access keys navigation for QupZilla"; + spec.description = "Provides support for navigating in webpages by keyboard shortcuts"; + spec.version = "0.1.0"; + spec.author = "David Rosca "; + spec.icon = QPixmap(":/accesskeysnavigation/data/icon.png"); + spec.hasSettings = true; + + return spec; +} + +void AKN_Plugin::init(const QString &sPath) +{ + m_handler = new AKN_Handler(sPath, this); + + QZ_REGISTER_EVENT_HANDLER(PluginProxy::KeyPressHandler); +} + +void AKN_Plugin::unload() +{ + m_handler->deleteLater(); +} + +bool AKN_Plugin::testPlugin() +{ + // Let's be sure, require latest version of QupZilla + + return (QupZilla::VERSION == "1.1.8"); +} + +QTranslator* AKN_Plugin::getTranslator(const QString &locale) +{ + QTranslator* translator = new QTranslator(); + translator->load(":/accesskeysnavigation/locale/" + locale); + return translator; +} + +void AKN_Plugin::showSettings(QWidget* parent) +{ + AKN_Settings* settings = new AKN_Settings(m_handler, parent); + settings->setAttribute(Qt::WA_DeleteOnClose); + + settings->show(); +} + +bool AKN_Plugin::keyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event) +{ + if (type == Qz::ON_WebView) { + return m_handler->handleKeyPress(obj, event); + } + + return false; +} + +Q_EXPORT_PLUGIN2(AccessKeysNavigation, AKN_Plugin) diff --git a/src/plugins/AccessKeysNavigation/akn_plugin.h b/src/plugins/AccessKeysNavigation/akn_plugin.h new file mode 100644 index 000000000..efc8943e9 --- /dev/null +++ b/src/plugins/AccessKeysNavigation/akn_plugin.h @@ -0,0 +1,47 @@ +/* ============================================================ +* Access Keys Navigation plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#ifndef AKN_PLUGIN_H +#define AKN_PLUGIN_H + +#include "plugininterface.h" + +class AKN_Handler; + +class AKN_Plugin : public QObject, public PluginInterface +{ + Q_OBJECT + Q_INTERFACES(PluginInterface) + +public: + AKN_Plugin(); + PluginSpec pluginSpec(); + + void init(const QString &sPath); + void unload(); + bool testPlugin(); + + QTranslator* getTranslator(const QString &locale); + void showSettings(QWidget* parent = 0); + + bool keyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event); + +private: + AKN_Handler* m_handler; +}; + +#endif // AKN_PLUGIN_H diff --git a/src/plugins/AccessKeysNavigation/akn_res.qrc b/src/plugins/AccessKeysNavigation/akn_res.qrc new file mode 100644 index 000000000..a379a0cb4 --- /dev/null +++ b/src/plugins/AccessKeysNavigation/akn_res.qrc @@ -0,0 +1,6 @@ + + + data/icon.png + data/copyright + + diff --git a/src/plugins/AccessKeysNavigation/akn_settings.cpp b/src/plugins/AccessKeysNavigation/akn_settings.cpp new file mode 100644 index 000000000..f4d22a167 --- /dev/null +++ b/src/plugins/AccessKeysNavigation/akn_settings.cpp @@ -0,0 +1,66 @@ +/* ============================================================ +* Access Keys Navigation plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ + +#include "akn_settings.h" +#include "ui_akn_settings.h" +#include "akn_handler.h" +#include "licenseviewer.h" + +#include +#include + +AKN_Settings::AKN_Settings(AKN_Handler *handler, QWidget *parent) + : QDialog(parent) + , ui(new Ui::AKN_Settings) + , m_handler(handler) + , m_settingsPath(handler->settingsPath()) +{ + ui->setupUi(this); + + QSettings settings(m_settingsPath, QSettings::IniFormat); + settings.beginGroup("AccessKeysNavigation"); + ui->key->setCurrentIndex(settings.value("Key", 0).toInt()); + ui->doubleClick->setChecked(settings.value("DoublePress", true).toBool()); + settings.endGroup(); + + connect(ui->licence, SIGNAL(clicked()), this, SLOT(showLicence())); + connect(this, SIGNAL(accepted()), this, SLOT(dialogAccepted())); +} + +AKN_Settings::~AKN_Settings() +{ + delete ui; +} + +void AKN_Settings::dialogAccepted() +{ + QSettings settings(m_settingsPath, QSettings::IniFormat); + settings.beginGroup("AccessKeysNavigation"); + settings.setValue("Key", ui->key->currentIndex()); + settings.setValue("DoublePress", ui->doubleClick->isChecked()); + settings.endGroup(); + + m_handler->loadSettings(); +} + +void AKN_Settings::showLicence() +{ + LicenseViewer* v = new LicenseViewer(this); + v->setLicenseFile(":accesskeysnavigation/data/copyright"); + v->show(); +} diff --git a/src/plugins/AccessKeysNavigation/akn_settings.h b/src/plugins/AccessKeysNavigation/akn_settings.h new file mode 100644 index 000000000..38a6d3637 --- /dev/null +++ b/src/plugins/AccessKeysNavigation/akn_settings.h @@ -0,0 +1,48 @@ +/* ============================================================ +* Access Keys Navigation plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#ifndef AKN_SETTINGS_H +#define AKN_SETTINGS_H + +#include + +namespace Ui { +class AKN_Settings; +} + +class AKN_Handler; + +class AKN_Settings : public QDialog +{ + Q_OBJECT + +public: + explicit AKN_Settings(AKN_Handler* handler, QWidget *parent = 0); + ~AKN_Settings(); + +private slots: + void dialogAccepted(); + void showLicence(); + +private: + Ui::AKN_Settings *ui; + + AKN_Handler* m_handler; + QString m_settingsPath; +}; + +#endif // AKN_SETTINGS_H diff --git a/src/plugins/AccessKeysNavigation/akn_settings.ui b/src/plugins/AccessKeysNavigation/akn_settings.ui new file mode 100644 index 000000000..41b8d66d3 --- /dev/null +++ b/src/plugins/AccessKeysNavigation/akn_settings.ui @@ -0,0 +1,144 @@ + + + AKN_Settings + + + + 0 + 0 + 470 + 146 + + + + Access Keys Navigation + + + + + + <h1>Access Keys Navigation</h1> + + + Qt::AlignCenter + + + + + + + + + + Ctrl + + + + + Alt + + + + + Shift + + + + + + + + Double press + + + + + + + Key for showing access keys: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Licence + + + + + + + + + buttonBox + accepted() + AKN_Settings + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AKN_Settings + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/plugins/AccessKeysNavigation/data/copyright b/src/plugins/AccessKeysNavigation/data/copyright new file mode 100644 index 000000000..63ef26bf2 --- /dev/null +++ b/src/plugins/AccessKeysNavigation/data/copyright @@ -0,0 +1,20 @@ +Access Keys showing function is under following license: + +/* + * Copyright 2008-2009 Benjamin C. Meyer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ diff --git a/src/plugins/AccessKeysNavigation/data/icon.png b/src/plugins/AccessKeysNavigation/data/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..7efd18378dfb19fae51699149b66dc74b41e362e GIT binary patch literal 656 zcmV;B0&o3^P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_0006bNklV7BNe=k&;|Ih1nbR18-JKY;q(vBH zcvu;6s_Gj5@4x>>T?e%FPlj7y zZf%1h|Loh}|0Wiea5ZiHlZkc!QE6cFy47%YR$(b-$->CUkX=*;=WkiRmb!`X`jyLY zwwA6wRyEps25|O`tCy+kfX|;k!P(-Hl33MhyA};a&u`9R!Kl=3Z|Iy1g{|7}x!Q~{SrT^b}{*Jok!1M3_{vW$? z>%X$98s3tSUqImh=KV)WDhU~JH~_25zJLGDuzbN>hOHacFRS`U;~QEDhy5C{R|8Y3=BVi{$$8cO + + + + AKN_Settings + + + Access Keys Navigation + Klávesové zkratky + + + + <h1>Access Keys Navigation</h1> + <h1>Klávesové zkratky</h1> + + + + Ctrl + Ctrl + + + + Alt + Alt + + + + Shift + Shift + + + + Double press + Dvojitý stisk + + + + Key for showing access keys: + Klávesa pro zobrazení zkratek: + + + + Licence + Licence + + + diff --git a/src/plugins/MouseGestures/MouseGestures.pro b/src/plugins/MouseGestures/MouseGestures.pro index b1a346093..fee92a9df 100644 --- a/src/plugins/MouseGestures/MouseGestures.pro +++ b/src/plugins/MouseGestures/MouseGestures.pro @@ -19,6 +19,9 @@ HEADERS = \ mousegesturesplugin.h \ mousegesturessettingsdialog.h +FORMS += \ + mousegesturessettingsdialog.ui + RESOURCES = mousegestures.qrc TRANSLATIONS = translations/cs_CZ.ts \ @@ -28,6 +31,3 @@ TRANSLATIONS = translations/cs_CZ.ts \ translations/zh_TW.ts \ include(../../plugins.pri) - -FORMS += \ - mousegesturessettingsdialog.ui diff --git a/src/plugins/MouseGestures/mousegestures.cpp b/src/plugins/MouseGestures/mousegestures.cpp index 375f0ff2f..af839ff73 100644 --- a/src/plugins/MouseGestures/mousegestures.cpp +++ b/src/plugins/MouseGestures/mousegestures.cpp @@ -1,11 +1,29 @@ +/* ============================================================ +* Mouse Gestures plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ #include "mousegestures.h" -#include "QjtMouseGestureFilter.h" -#include "QjtMouseGesture.h" #include "webview.h" #include "mainapplication.h" #include "qupzilla.h" #include "mousegesturessettingsdialog.h" +#include "QjtMouseGestureFilter.h" +#include "QjtMouseGesture.h" + MouseGestures::MouseGestures(QObject* parent) : QObject(parent) { diff --git a/src/plugins/MouseGestures/mousegestures.h b/src/plugins/MouseGestures/mousegestures.h index 4ddc52633..55ae7386b 100644 --- a/src/plugins/MouseGestures/mousegestures.h +++ b/src/plugins/MouseGestures/mousegestures.h @@ -1,7 +1,23 @@ +/* ============================================================ +* Mouse Gestures plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ #ifndef MOUSEGESTURES_H #define MOUSEGESTURES_H -#include #include #include diff --git a/src/plugins/MouseGestures/mousegesturesplugin.cpp b/src/plugins/MouseGestures/mousegesturesplugin.cpp index 8e1957fa7..adedaaabb 100644 --- a/src/plugins/MouseGestures/mousegesturesplugin.cpp +++ b/src/plugins/MouseGestures/mousegesturesplugin.cpp @@ -1,3 +1,20 @@ +/* ============================================================ +* Mouse Gestures plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ #include "mousegesturesplugin.h" #include "pluginproxy.h" #include "mousegestures.h" @@ -16,7 +33,7 @@ PluginSpec MouseGesturesPlugin::pluginSpec() PluginSpec spec; spec.name = "Mouse Gestures"; spec.info = "Mouse gestures for QupZilla"; - spec.description = "Provides support for navigating by mouse gestures through webpages"; + spec.description = "Provides support for navigating in webpages by mouse gestures"; spec.version = "0.1.0"; spec.author = "David Rosca "; spec.icon = QPixmap(":/mousegestures/data/icon.png"); diff --git a/src/plugins/MouseGestures/mousegesturesplugin.h b/src/plugins/MouseGestures/mousegesturesplugin.h index be11365a8..45093452b 100644 --- a/src/plugins/MouseGestures/mousegesturesplugin.h +++ b/src/plugins/MouseGestures/mousegesturesplugin.h @@ -1,3 +1,20 @@ +/* ============================================================ +* Mouse Gestures plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ #ifndef MOUSEGESTURESPLUGIN_H #define MOUSEGESTURESPLUGIN_H diff --git a/src/plugins/MouseGestures/mousegesturessettingsdialog.cpp b/src/plugins/MouseGestures/mousegesturessettingsdialog.cpp index 0a5a10032..615e3d66f 100644 --- a/src/plugins/MouseGestures/mousegesturessettingsdialog.cpp +++ b/src/plugins/MouseGestures/mousegesturessettingsdialog.cpp @@ -1,6 +1,23 @@ +/* ============================================================ +* Mouse Gestures plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ #include "mousegesturessettingsdialog.h" #include "ui_mousegesturessettingsdialog.h" -#include "globalfunctions.h" +#include "licenseviewer.h" MouseGesturesSettingsDialog::MouseGesturesSettingsDialog(QWidget* parent) : QDialog(parent) @@ -19,11 +36,8 @@ MouseGesturesSettingsDialog::~MouseGesturesSettingsDialog() void MouseGesturesSettingsDialog::showLicense() { - QTextBrowser* b = new QTextBrowser(); - b->setAttribute(Qt::WA_DeleteOnClose); - b->setWindowTitle(tr("License Viewer")); - b->resize(450, 500); - b->setText(qz_readAllFileContents(":mousegestures/data/copyright")); - qz_centerWidgetOnScreen(b); - b->show(); + LicenseViewer* v = new LicenseViewer(this); + v->setLicenseFile(":mousegestures/data/copyright"); + + v->show(); } diff --git a/src/plugins/MouseGestures/mousegesturessettingsdialog.h b/src/plugins/MouseGestures/mousegesturessettingsdialog.h index 683cc7f6d..7632c2951 100644 --- a/src/plugins/MouseGestures/mousegesturessettingsdialog.h +++ b/src/plugins/MouseGestures/mousegesturessettingsdialog.h @@ -1,3 +1,20 @@ +/* ============================================================ +* Mouse Gestures plugin for QupZilla +* Copyright (C) 2012 David Rosca +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ #ifndef MOUSEGESTURESSETTINGSDIALOG_H #define MOUSEGESTURESSETTINGSDIALOG_H diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 53f8e7505..a8e138305 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs -SUBDIRS = MouseGestures +SUBDIRS = MouseGestures AccessKeysNavigation # TestPlugin only in debug build CONFIG(debug, debug|release): SUBDIRS += TestPlugin