From bdc9a0417a4d4f35f783df555bf818982906e161 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sat, 22 Dec 2012 13:52:46 +0100 Subject: [PATCH] Qt5: Added new option to use Caret Browsing It can be enabled from Preferences -> Browsing, Menu View or with F7 shortcut. --- src/lib/app/mainapplication.cpp | 1 + src/lib/app/qupzilla.cpp | 27 +++++++++++++++++++++++++++ src/lib/app/qupzilla.h | 5 +++++ src/lib/preferences/preferences.cpp | 2 ++ src/lib/preferences/preferences.ui | 7 +++++++ 5 files changed, 42 insertions(+) diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 015b61524..6fd8fd240 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -373,6 +373,7 @@ void MainApplication::loadSettings() m_websettings->setDefaultTextEncoding(settings.value("DefaultEncoding", m_websettings->defaultTextEncoding()).toString()); #if QT_VERSION >= 0x050000 + m_websettings->setAttribute(QWebSettings::CaretBrowsingEnabled, settings.value("CaretBrowsing", false).toBool()); m_websettings->setAttribute(QWebSettings::ScrollAnimatorEnabled, settings.value("AnimateScrolling", true).toBool()); #endif diff --git a/src/lib/app/qupzilla.cpp b/src/lib/app/qupzilla.cpp index 3e58ec50d..f73824c5d 100644 --- a/src/lib/app/qupzilla.cpp +++ b/src/lib/app/qupzilla.cpp @@ -401,6 +401,12 @@ void QupZilla::setupMenu() m_menuEncoding = new QMenu(this); actionEncoding->setMenu(m_menuEncoding); connect(m_menuEncoding, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEncodingMenu())); +#if QT_VERSION >= 0x050000 + m_actionCaretBrowsing = new QAction(tr("Enable &Caret Browsing"), this); + m_actionCaretBrowsing->setCheckable(true); + m_actionCaretBrowsing->setShortcut(QKeySequence("F7")); + connect(m_actionCaretBrowsing, SIGNAL(triggered()), this, SLOT(triggerCaretBrowsing())); +#endif QMenu* toolbarsMenu = new QMenu(tr("Toolbars")); #ifndef Q_OS_MAC @@ -422,6 +428,9 @@ void QupZilla::setupMenu() m_menuView->addAction(QIcon::fromTheme("zoom-out"), tr("Zoom &Out"), this, SLOT(zoomOut()))->setShortcut(QKeySequence("Ctrl+-")); m_menuView->addAction(QIcon::fromTheme("zoom-original"), tr("Reset"), this, SLOT(zoomReset()))->setShortcut(QKeySequence("Ctrl+0")); m_menuView->addSeparator(); +#if QT_VERSION >= 0x050000 + m_menuView->addAction(m_actionCaretBrowsing); +#endif m_menuView->addAction(actionEncoding); m_menuView->addSeparator(); m_menuView->addAction(QIcon::fromTheme("text-html"), tr("&Page Source"), this, SLOT(showSource()))->setShortcut(QKeySequence("Ctrl+U")); @@ -969,6 +978,10 @@ void QupZilla::aboutToShowViewMenu() #endif m_actionShowStatusbar->setChecked(statusBar()->isVisible()); m_actionShowBookmarksToolbar->setChecked(m_bookmarksToolbar->isVisible()); + +#if QT_VERSION >= 0x050000 + m_actionCaretBrowsing->setChecked(mApp->webSettings()->testAttribute(QWebSettings::CaretBrowsingEnabled)); +#endif } void QupZilla::aboutToShowEditMenu() @@ -1075,6 +1088,20 @@ void QupZilla::changeEncoding() } } +#if QT_VERSION >= 0x050000 +void QupZilla::triggerCaretBrowsing() +{ + bool enable = !mApp->webSettings()->testAttribute(QWebSettings::CaretBrowsingEnabled); + + Settings settings; + settings.beginGroup("Web-Browser-Settings"); + settings.setValue("CaretBrowsing", enable); + settings.endGroup(); + + mApp->webSettings()->setAttribute(QWebSettings::CaretBrowsingEnabled, enable); +} +#endif + void QupZilla::bookmarkPage() { mApp->browsingLibrary()->bookmarksManager()->addBookmark(weView()); diff --git a/src/lib/app/qupzilla.h b/src/lib/app/qupzilla.h index 3a96c750e..91b9cebfe 100644 --- a/src/lib/app/qupzilla.h +++ b/src/lib/app/qupzilla.h @@ -188,6 +188,10 @@ private slots: void fullScreen(bool make); void changeEncoding(); +#if QT_VERSION >= 0x050000 + void triggerCaretBrowsing(); +#endif + void closeWindow(); bool quitApp(); #ifdef Q_OS_WIN @@ -260,6 +264,7 @@ private: QAction* m_actionPrivateBrowsing; QAction* m_actionStop; QAction* m_actionReload; + QAction* m_actionCaretBrowsing; QAction* m_actionRestoreTab; QLabel* m_privateBrowsing; diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 90c146997..9a7b1637f 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -244,6 +244,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) ui->allowDNSPrefetch->setChecked(settings.value("DNS-Prefetch", false).toBool()); ui->linksInFocusChain->setChecked(settings.value("IncludeLinkInFocusChain", false).toBool()); ui->zoomTextOnly->setChecked(settings.value("zoomTextOnly", false).toBool()); + ui->caretBrowsing->setChecked(settings.value("CaretBrowsing", false).toBool()); ui->animateScrolling->setChecked(settings.value("AnimateScrolling", true).toBool()); ui->printEBackground->setChecked(settings.value("PrintElementBackground", true).toBool()); ui->wheelScroll->setValue(settings.value("wheelScrollLines", qApp->wheelScrollLines()).toInt()); @@ -891,6 +892,7 @@ void Preferences::saveSettings() settings.setValue("JavaScriptCanAccessClipboard", ui->jscanAccessClipboard->isChecked()); settings.setValue("IncludeLinkInFocusChain", ui->linksInFocusChain->isChecked()); settings.setValue("zoomTextOnly", ui->zoomTextOnly->isChecked()); + settings.setValue("CaretBrowsing", ui->caretBrowsing->isChecked()); settings.setValue("AnimateScrolling", ui->animateScrolling->isChecked()); settings.setValue("PrintElementBackground", ui->printEBackground->isChecked()); settings.setValue("wheelScrollLines", ui->wheelScroll->value()); diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index 440580636..5483b3dac 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -1061,6 +1061,13 @@ + + + + Enable caret browsing + + +