1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

[SBI_Icons] Added Zoom Widget to StatusBarIcons plugin

Closes #1197
This commit is contained in:
nowrep 2014-03-29 15:49:49 +01:00
parent d6625c60fb
commit a059c005ff
14 changed files with 202 additions and 57 deletions

View File

@ -17,6 +17,7 @@
* ============================================================ */
#include "qzsettings.h"
#include "settings.h"
#include "webview.h"
QzSettings::QzSettings()
{
@ -44,7 +45,7 @@ void QzSettings::loadSettings()
settings.endGroup();
settings.beginGroup("Web-Browser-Settings");
defaultZoom = settings.value("DefaultZoom", 100).toInt();
defaultZoomLevel = settings.value("DefaultZoomLevel", WebView::zoomLevels().indexOf(100)).toInt();
loadTabsOnActivation = settings.value("LoadTabsOnActivation", true).toBool();
autoOpenProtocols = settings.value("AutomaticallyOpenProtocols", QStringList()).toStringList();
blockedProtocols = settings.value("BlockOpeningProtocols", QStringList()).toStringList();

View File

@ -47,7 +47,7 @@ public:
bool searchWithDefaultEngine;
// Web-Browser-Settings
int defaultZoom;
int defaultZoomLevel;
bool loadTabsOnActivation;
bool allowJsGeometryChange;
bool allowJsHideMenuBar;

View File

@ -274,7 +274,7 @@ Preferences::Preferences(BrowserWindow* window, QWidget* parent)
ui->searchWithDefaultEngine->setChecked(settings.value("SearchWithDefaultEngine", false).toBool());
settings.endGroup();
//BROWSING
// BROWSING
settings.beginGroup("Web-Browser-Settings");
ui->allowPlugins->setChecked(settings.value("allowFlash", true).toBool());
ui->allowJavaScript->setChecked(settings.value("allowJavaScript", true).toBool());
@ -287,10 +287,14 @@ Preferences::Preferences(BrowserWindow* window, QWidget* parent)
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());
ui->defaultZoom->setValue(settings.value("DefaultZoom", 100).toInt());
ui->xssAuditing->setChecked(settings.value("XSSAuditing", false).toBool());
ui->formsUndoRedo->setChecked(settings.value("enableFormsUndoRedo", false).toBool());
foreach (int level, WebView::zoomLevels()) {
ui->defaultZoomLevel->addItem(QString("%1%").arg(level));
}
ui->defaultZoomLevel->setCurrentIndex(settings.value("DefaultZoomLevel", WebView::zoomLevels().indexOf(100)).toInt());
//Cache
ui->pagesInCache->setValue(settings.value("maximumCachedPages", 3).toInt());
connect(ui->pagesInCache, SIGNAL(valueChanged(int)), this, SLOT(pageCacheValueChanged(int)));
@ -978,7 +982,7 @@ void Preferences::saveSettings()
settings.setValue("DoNotTrack", ui->doNotTrack->isChecked());
settings.setValue("CheckUpdates", ui->checkUpdates->isChecked());
settings.setValue("LoadTabsOnActivation", ui->dontLoadTabsUntilSelected->isChecked());
settings.setValue("DefaultZoom", ui->defaultZoom->value());
settings.setValue("DefaultZoomLevel", ui->defaultZoomLevel->currentIndex());
settings.setValue("XSSAuditing", ui->xssAuditing->isChecked());
settings.setValue("enableFormsUndoRedo", ui->formsUndoRedo->isChecked());
#ifdef Q_OS_WIN

View File

@ -1219,20 +1219,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="defaultZoom">
<property name="suffix">
<string notr="true"> %</string>
</property>
<property name="minimum">
<number>30</number>
</property>
<property name="maximum">
<number>300</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
<widget class="QComboBox" name="defaultZoomLevel"/>
</item>
<item>
<spacer name="horizontalSpacer_12">
@ -2777,7 +2764,6 @@
<tabstop>tabWidget</tabstop>
<tabstop>allowPlugins</tabstop>
<tabstop>wheelScroll</tabstop>
<tabstop>defaultZoom</tabstop>
<tabstop>fontStandard</tabstop>
<tabstop>fontFixed</tabstop>
<tabstop>fontSerif</tabstop>

View File

@ -53,7 +53,6 @@
WebView::WebView(QWidget* parent)
: QWebView(parent)
, m_currentZoom(100)
, m_isLoading(false)
, m_progress(0)
, m_clickedFrame(0)
@ -72,8 +71,8 @@ WebView::WebView(QWidget* parent)
connect(this, SIGNAL(iconChanged()), this, SLOT(slotIconChanged()));
connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(slotUrlChanged(QUrl)));
// Zoom levels same as in firefox
m_zoomLevels << 30 << 50 << 67 << 80 << 90 << 100 << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300;
m_zoomLevels = zoomLevels();
m_currentZoomLevel = m_zoomLevels.indexOf(100);
#if QTWEBKIT_TO_2_3
installEventFilter(this);
@ -158,10 +157,12 @@ void WebView::setPage(QWebPage* page)
QWebView::setPage(page);
m_page = qobject_cast<WebPage*>(page);
setZoom(qzSettings->defaultZoom);
connect(m_page, SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)), this, SLOT(frameStateChanged()));
connect(m_page, SIGNAL(privacyChanged(bool)), this, SIGNAL(privacyChanged(bool)));
// Set default zoom level
zoomReset();
mApp->plugins()->emitWebPageCreated(m_page);
// Set white background by default.
@ -232,6 +233,17 @@ QWebElement WebView::activeElement() const
return page()->mainFrame()->hitTestContent(activeRect.center()).element();
}
int WebView::zoomLevel() const
{
return m_currentZoomLevel;
}
void WebView::setZoomLevel(int level)
{
m_currentZoomLevel = level;
applyZoom();
}
bool WebView::onBeforeUnload()
{
const QString res = page()->mainFrame()->evaluateJavaScript("window.onbeforeunload(new Event(\"beforeunload\"))").toString();
@ -243,12 +255,14 @@ bool WebView::onBeforeUnload()
return true;
}
// static
bool WebView::isUrlValid(const QUrl &url)
{
// Valid url must have scheme and actually contains something (therefore scheme:// is invalid)
return url.isValid() && !url.scheme().isEmpty() && (!url.host().isEmpty() || !url.path().isEmpty() || url.hasQuery());
}
// static
QUrl WebView::guessUrlFromString(const QString &string)
{
QString trimmedString = string.trimmed();
@ -284,6 +298,14 @@ QUrl WebView::guessUrlFromString(const QString &string)
return QUrl();
}
// static
QList<int> WebView::zoomLevels()
{
return QList<int>() << 30 << 40 << 50 << 67 << 80 << 90 << 100
<< 110 << 120 << 133 << 150 << 170 << 200
<< 220 << 233 << 250 << 270 << 285 << 300;
}
void WebView::addNotification(QWidget* notif)
{
emit showNotification(notif);
@ -291,35 +313,33 @@ void WebView::addNotification(QWidget* notif)
void WebView::applyZoom()
{
setZoomFactor(qreal(m_currentZoom) / 100.0);
setZoomFactor(qreal(m_zoomLevels.at(m_currentZoomLevel)) / 100.0);
emit zoomLevelChanged(m_currentZoomLevel);
}
void WebView::zoomIn()
{
int i = m_zoomLevels.indexOf(m_currentZoom);
if (i < m_zoomLevels.count() - 1) {
m_currentZoom = m_zoomLevels[i + 1];
if (m_currentZoomLevel < m_zoomLevels.count() - 1) {
m_currentZoomLevel++;
applyZoom();
}
applyZoom();
}
void WebView::zoomOut()
{
int i = m_zoomLevels.indexOf(m_currentZoom);
if (i > 0) {
m_currentZoom = m_zoomLevels[i - 1];
if (m_currentZoomLevel > 0) {
m_currentZoomLevel--;
applyZoom();
}
applyZoom();
}
void WebView::zoomReset()
{
m_currentZoom = 100;
applyZoom();
if (m_currentZoomLevel != qzSettings->defaultZoomLevel) {
m_currentZoomLevel = qzSettings->defaultZoomLevel;
applyZoom();
}
}
void WebView::editUndo()
@ -1464,12 +1484,6 @@ void WebView::resizeEvent(QResizeEvent* event)
emit viewportResized(page()->viewportSize());
}
void WebView::setZoom(int zoom)
{
m_currentZoom = zoom;
applyZoom();
}
///
// This function was taken and modified from QTestBrowser to fix bug #33 with flightradar24.com
// You can find original source and copyright here:

View File

@ -42,7 +42,6 @@ public:
void setPage(QWebPage* page);
void load(const LoadRequest &request);
bool loadingError() const;
bool isLoading() const;
@ -52,6 +51,10 @@ public:
bool hasRss() const;
QWebElement activeElement() const;
// Set zoom level (0 - 17)
int zoomLevel() const;
void setZoomLevel(int level);
// Executes window.onbeforeunload, returns true if view can be closed
bool onBeforeUnload();
@ -62,12 +65,14 @@ public:
static bool isUrlValid(const QUrl &url);
static QUrl guessUrlFromString(const QString &string);
static QList<int> zoomLevels();
signals:
void viewportResized(QSize);
void showNotification(QWidget*);
void privacyChanged(bool);
void rssChanged(bool);
void zoomLevelChanged(int);
public slots:
void zoomIn();
@ -147,7 +152,6 @@ protected:
void keyReleaseEvent(QKeyEvent* event);
void resizeEvent(QResizeEvent* event);
void setZoom(int zoom);
void applyZoom();
QUrl lastUrl();
@ -172,7 +176,7 @@ private slots:
private:
QList<int> m_zoomLevels;
int m_currentZoom;
int m_currentZoomLevel;
QIcon m_siteIcon;
QUrl m_siteIconUrl;

View File

@ -11,7 +11,8 @@ SOURCES += statusbariconsplugin.cpp \
sbi_networkicondialog.cpp \
sbi_networkmanager.cpp \
sbi_settingsdialog.cpp \
sbi_icon.cpp
sbi_icon.cpp \
sbi_zoomwidget.cpp
HEADERS += statusbariconsplugin.h \
sbi_iconsmanager.h \
@ -23,7 +24,8 @@ HEADERS += statusbariconsplugin.h \
sbi_networkicondialog.h \
sbi_networkmanager.h \
sbi_settingsdialog.h \
sbi_icon.h
sbi_icon.h \
sbi_zoomwidget.h
RESOURCES += statusbaricons.qrc

View File

@ -18,6 +18,7 @@
#include "sbi_iconsmanager.h"
#include "sbi_imagesicon.h"
#include "sbi_javascripticon.h"
#include "sbi_zoomwidget.h"
#include "sbi_networkicon.h"
#include "sbi_networkmanager.h"
#include "browserwindow.h"
@ -31,6 +32,7 @@ SBI_IconsManager::SBI_IconsManager(const QString &settingsPath, QObject* parent)
, m_showImagesIcon(false)
, m_showJavaScriptIcon(false)
, m_showNetworkIcon(false)
, m_showZoomWidget(false)
, m_networkManager(0)
{
loadSettings();
@ -43,6 +45,7 @@ void SBI_IconsManager::loadSettings()
m_showImagesIcon = settings.value("showImagesIcon", true).toBool();
m_showJavaScriptIcon = settings.value("showJavaScriptIcon", true).toBool();
m_showNetworkIcon = settings.value("showNetworkIcon", true).toBool();
m_showZoomWidget = settings.value("showZoomWidget", true).toBool();
settings.endGroup();
}
@ -53,7 +56,7 @@ bool SBI_IconsManager::showImagesIcon() const
void SBI_IconsManager::setShowImagesIcon(bool show)
{
QSettings settings(m_settingsPath + "extensions.ini", QSettings::IniFormat);
QSettings settings(m_settingsPath + QL1S("extensions.ini"), QSettings::IniFormat);
settings.setValue("StatusBarIcons/showImagesIcon", show);
m_showImagesIcon = show;
@ -66,7 +69,7 @@ bool SBI_IconsManager::showJavaScriptIcon() const
void SBI_IconsManager::setShowJavaScriptIcon(bool show)
{
QSettings settings(m_settingsPath + "extensions.ini", QSettings::IniFormat);
QSettings settings(m_settingsPath + QL1S("extensions.ini"), QSettings::IniFormat);
settings.setValue("StatusBarIcons/showJavaScriptIcon", show);
m_showJavaScriptIcon = show;
@ -79,12 +82,25 @@ bool SBI_IconsManager::showNetworkIcon() const
void SBI_IconsManager::setShowNetworkIcon(bool show)
{
QSettings settings(m_settingsPath + "extensions.ini", QSettings::IniFormat);
QSettings settings(m_settingsPath + QL1S("extensions.ini"), QSettings::IniFormat);
settings.setValue("StatusBarIcons/showNetworkIcon", show);
m_showNetworkIcon = show;
}
bool SBI_IconsManager::showZoomWidget() const
{
return m_showZoomWidget;
}
void SBI_IconsManager::setShowZoomWidget(bool show)
{
QSettings settings(m_settingsPath + QL1S("extensions.ini"), QSettings::IniFormat);
settings.setValue("StatusBarIcons/showZoomWidget", show);
m_showZoomWidget = show;
}
void SBI_IconsManager::reloadIcons()
{
QHashIterator<BrowserWindow*, QWidgetList> it(m_windows);
@ -129,6 +145,12 @@ void SBI_IconsManager::mainWindowCreated(BrowserWindow* window)
window->statusBar()->addPermanentWidget(w);
m_windows[window].append(w);
}
if (m_showZoomWidget) {
SBI_ZoomWidget* w = new SBI_ZoomWidget(window);
window->statusBar()->addPermanentWidget(w);
m_windows[window].append(w);
}
}
void SBI_IconsManager::mainWindowDeleted(BrowserWindow* window)

View File

@ -42,6 +42,9 @@ public:
bool showNetworkIcon() const;
void setShowNetworkIcon(bool show);
bool showZoomWidget() const;
void setShowZoomWidget(bool show);
void reloadIcons();
void destroyIcons();
@ -56,6 +59,7 @@ private:
bool m_showImagesIcon;
bool m_showJavaScriptIcon;
bool m_showNetworkIcon;
bool m_showZoomWidget;
QHash<BrowserWindow*, QWidgetList> m_windows;
SBI_NetworkManager* m_networkManager;

View File

@ -29,6 +29,7 @@ SBI_SettingsDialog::SBI_SettingsDialog(SBI_IconsManager* manager, QWidget* paren
ui->showImagesIcon->setChecked(m_manager->showImagesIcon());
ui->showJavaScriptIcon->setChecked(m_manager->showJavaScriptIcon());
ui->showNetworkIcon->setChecked(m_manager->showNetworkIcon());
ui->showZoomWidget->setChecked(m_manager->showZoomWidget());
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(saveSettings()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
@ -39,6 +40,7 @@ void SBI_SettingsDialog::saveSettings()
m_manager->setShowImagesIcon(ui->showImagesIcon->isChecked());
m_manager->setShowJavaScriptIcon(ui->showJavaScriptIcon->isChecked());
m_manager->setShowNetworkIcon(ui->showNetworkIcon->isChecked());
m_manager->setShowZoomWidget(ui->showZoomWidget->isChecked());
m_manager->reloadIcons();
close();

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>345</width>
<height>186</height>
<width>343</width>
<height>204</height>
</rect>
</property>
<property name="windowTitle">
@ -112,6 +112,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showZoomWidget">
<property name="text">
<string>Zoom widget</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -0,0 +1,59 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "sbi_zoomwidget.h"
#include "tabbedwebview.h"
#include "browserwindow.h"
#include "tabwidget.h"
SBI_ZoomWidget::SBI_ZoomWidget(BrowserWindow* parent)
: QSlider(parent)
, m_window(parent)
{
setOrientation(Qt::Horizontal);
setFixedWidth(100);
setMaximumHeight(20);
setPageStep(2);
setSingleStep(1);
setRange(0, WebView::zoomLevels().count() - 1);
connect(this, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
connect(m_window->tabWidget(), SIGNAL(currentChanged(int)), this, SLOT(currentViewChanged()));
currentViewChanged();
}
void SBI_ZoomWidget::valueChanged(int value)
{
TabbedWebView* view = m_window->weView();
if (view) {
view->setZoomLevel(value);
setToolTip(tr("Zoom: %1%").arg(view->zoomFactor() * 100));
}
}
void SBI_ZoomWidget::currentViewChanged()
{
TabbedWebView* view = m_window->weView();
if (view) {
connect(view, SIGNAL(zoomLevelChanged(int)), this, SLOT(setValue(int)));
setValue(view->zoomLevel());
}
}

View File

@ -0,0 +1,40 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef SBI_ZOOMWIDGET_H
#define SBI_ZOOMWIDGET_H
#include <QSlider>
class BrowserWindow;
class SBI_ZoomWidget : public QSlider
{
Q_OBJECT
public:
explicit SBI_ZoomWidget(BrowserWindow* parent = 0);
private slots:
void valueChanged(int value);
void currentViewChanged();
private:
BrowserWindow* m_window;
};
#endif // SBI_ZOOMWIDGET_H

View File

@ -34,8 +34,8 @@ PluginSpec StatusBarIconsPlugin::pluginSpec()
PluginSpec spec;
spec.name = "StatusBar Icons";
spec.info = "Icons in statusbar providing various actions";
spec.description = "Adds additional icons to statusbar";
spec.version = "0.1.6";
spec.description = "Adds additional icons and zoom widget to statusbar";
spec.version = "0.2.0";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":sbi/data/icon.png");
spec.hasSettings = true;