diff --git a/src/lib/other/qzsettings.cpp b/src/lib/other/qzsettings.cpp
index ca1550102..fae5390bc 100644
--- a/src/lib/other/qzsettings.cpp
+++ b/src/lib/other/qzsettings.cpp
@@ -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();
diff --git a/src/lib/other/qzsettings.h b/src/lib/other/qzsettings.h
index fc9ca1cbb..8c0e316a0 100644
--- a/src/lib/other/qzsettings.h
+++ b/src/lib/other/qzsettings.h
@@ -47,7 +47,7 @@ public:
bool searchWithDefaultEngine;
// Web-Browser-Settings
- int defaultZoom;
+ int defaultZoomLevel;
bool loadTabsOnActivation;
bool allowJsGeometryChange;
bool allowJsHideMenuBar;
diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp
index bf66a2b3f..809641c58 100644
--- a/src/lib/preferences/preferences.cpp
+++ b/src/lib/preferences/preferences.cpp
@@ -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
diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui
index aa11b4d52..4a5ffd91e 100644
--- a/src/lib/preferences/preferences.ui
+++ b/src/lib/preferences/preferences.ui
@@ -1219,20 +1219,7 @@
-
-
-
- %
-
-
- 30
-
-
- 300
-
-
- 100
-
-
+
-
@@ -2777,7 +2764,6 @@
tabWidget
allowPlugins
wheelScroll
- defaultZoom
fontStandard
fontFixed
fontSerif
diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp
index 67dfeea18..44360e3c9 100644
--- a/src/lib/webview/webview.cpp
+++ b/src/lib/webview/webview.cpp
@@ -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(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 WebView::zoomLevels()
+{
+ return QList() << 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:
diff --git a/src/lib/webview/webview.h b/src/lib/webview/webview.h
index 55161f878..5ef2b22e4 100644
--- a/src/lib/webview/webview.h
+++ b/src/lib/webview/webview.h
@@ -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 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 m_zoomLevels;
- int m_currentZoom;
+ int m_currentZoomLevel;
QIcon m_siteIcon;
QUrl m_siteIconUrl;
diff --git a/src/plugins/StatusBarIcons/StatusBarIcons.pro b/src/plugins/StatusBarIcons/StatusBarIcons.pro
index 864f5e8c9..cedceb8a6 100644
--- a/src/plugins/StatusBarIcons/StatusBarIcons.pro
+++ b/src/plugins/StatusBarIcons/StatusBarIcons.pro
@@ -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
diff --git a/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp b/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp
index 3dd110dbb..6eaeabdb8 100644
--- a/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp
+++ b/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp
@@ -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 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)
diff --git a/src/plugins/StatusBarIcons/sbi_iconsmanager.h b/src/plugins/StatusBarIcons/sbi_iconsmanager.h
index 19c89c8ca..175528e2c 100644
--- a/src/plugins/StatusBarIcons/sbi_iconsmanager.h
+++ b/src/plugins/StatusBarIcons/sbi_iconsmanager.h
@@ -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 m_windows;
SBI_NetworkManager* m_networkManager;
diff --git a/src/plugins/StatusBarIcons/sbi_settingsdialog.cpp b/src/plugins/StatusBarIcons/sbi_settingsdialog.cpp
index ca6ffcfe3..25cf2ede7 100644
--- a/src/plugins/StatusBarIcons/sbi_settingsdialog.cpp
+++ b/src/plugins/StatusBarIcons/sbi_settingsdialog.cpp
@@ -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();
diff --git a/src/plugins/StatusBarIcons/sbi_settingsdialog.ui b/src/plugins/StatusBarIcons/sbi_settingsdialog.ui
index 262c5eda9..a8bd45530 100644
--- a/src/plugins/StatusBarIcons/sbi_settingsdialog.ui
+++ b/src/plugins/StatusBarIcons/sbi_settingsdialog.ui
@@ -6,8 +6,8 @@
0
0
- 345
- 186
+ 343
+ 204
@@ -112,6 +112,13 @@
+ -
+
+
+ Zoom widget
+
+
+
-
diff --git a/src/plugins/StatusBarIcons/sbi_zoomwidget.cpp b/src/plugins/StatusBarIcons/sbi_zoomwidget.cpp
new file mode 100644
index 000000000..3da8d9115
--- /dev/null
+++ b/src/plugins/StatusBarIcons/sbi_zoomwidget.cpp
@@ -0,0 +1,59 @@
+/* ============================================================
+* StatusBarIcons - Extra icons in statusbar for QupZilla
+* Copyright (C) 2014 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 "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());
+ }
+}
diff --git a/src/plugins/StatusBarIcons/sbi_zoomwidget.h b/src/plugins/StatusBarIcons/sbi_zoomwidget.h
new file mode 100644
index 000000000..086ff483c
--- /dev/null
+++ b/src/plugins/StatusBarIcons/sbi_zoomwidget.h
@@ -0,0 +1,40 @@
+/* ============================================================
+* StatusBarIcons - Extra icons in statusbar for QupZilla
+* Copyright (C) 2014 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 SBI_ZOOMWIDGET_H
+#define SBI_ZOOMWIDGET_H
+
+#include
+
+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
diff --git a/src/plugins/StatusBarIcons/statusbariconsplugin.cpp b/src/plugins/StatusBarIcons/statusbariconsplugin.cpp
index c5162752b..9e675294d 100644
--- a/src/plugins/StatusBarIcons/statusbariconsplugin.cpp
+++ b/src/plugins/StatusBarIcons/statusbariconsplugin.cpp
@@ -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 ";
spec.icon = QPixmap(":sbi/data/icon.png");
spec.hasSettings = true;