1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Using static variables to store settings of WebView and LocationBar.

- in its own WebViewSettings and LocationBarSettings classes
- because we don̈́'t want to load settings on every creation of new
  tab
This commit is contained in:
nowrep 2012-01-24 19:58:20 +01:00
parent 16526b0177
commit fc13958953
14 changed files with 62 additions and 47 deletions

View File

@ -44,6 +44,8 @@
#include "speeddial.h"
#include "webpage.h"
#include "settings.h"
#include "locationbarsettings.h"
#include "webviewsettings.h"
#ifdef Q_WS_WIN
#define DEFAULT_CHECK_UPDATES true
@ -316,7 +318,6 @@ void MainApplication::loadSettings()
int maxCachedPages = settings.value("maximumCachedPages", 3).toInt();
int scrollingLines = settings.value("wheelScrollLines", wheelScrollLines()).toInt();
QUrl userStyleSheet = QUrl::fromLocalFile(settings.value("userStyleSheet", "").toString());
m_defaultZoom = settings.value("DefaultZoom", 100).toInt();
WebPage::UserAgent = settings.value("UserAgent", "").toString();
settings.endGroup();
@ -373,6 +374,9 @@ void MainApplication::loadSettings()
if (m_downloadManager) {
m_downloadManager->loadSettings();
}
LocationBarSettings::loadSettings();
WebViewSettings::loadSettings();
}
void MainApplication::reloadSettings()

View File

@ -82,7 +82,6 @@ public:
inline int windowCount() { return m_mainWindows.count(); }
bool checkSettingsDir();
int defaultZoom() { return m_defaultZoom; }
void togglePrivateBrowsingMode(bool state);
@ -155,7 +154,6 @@ private:
QString m_activeProfil;
QString m_activeLanguage;
QString m_activeThemePath;
int m_defaultZoom;
bool m_isClosing;
bool m_isStateChanged;

View File

@ -52,7 +52,6 @@
#include "adblockicon.h"
#include "closedtabsmanager.h"
#include "statusbarmessage.h"
#include "locationbarsettings.h"
#include "browsinglibrary.h"
#include "navigationbar.h"
#include "pagescreen.h"
@ -616,7 +615,6 @@ void QupZilla::receiveMessage(Qz::AppMessageType mes, bool state)
case Qz::AM_ReloadSettings:
loadSettings();
m_tabWidget->loadSettings();
LocationBarSettings::instance()->loadSettings();
break;
case Qz::AM_HistoryStateChanged:

View File

@ -41,7 +41,6 @@ LocationBar::LocationBar(QupZilla* mainClass)
: LineEdit()
, p_QupZilla(mainClass)
, m_webView(0)
, m_locationBarSettings(LocationBarSettings::instance())
, m_menu(new QMenu(this))
, m_pasteAndGoAction(0)
, m_clearAction(0)
@ -355,7 +354,7 @@ void LocationBar::focusOutEvent(QFocusEvent* e)
void LocationBar::mouseDoubleClickEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton && m_locationBarSettings->selectAllOnDoubleClick) {
if (event->button() == Qt::LeftButton && LocationBarSettings::selectAllOnDoubleClick) {
selectAll();
}
else {
@ -365,7 +364,7 @@ void LocationBar::mouseDoubleClickEvent(QMouseEvent* event)
void LocationBar::mousePressEvent(QMouseEvent* event)
{
if (cursorPosition() == 0 && m_locationBarSettings->selectAllOnClick) {
if (cursorPosition() == 0 && LocationBarSettings::selectAllOnClick) {
selectAll();
return;
}
@ -420,7 +419,7 @@ void LocationBar::keyReleaseEvent(QKeyEvent* event)
{
QString localDomain = tr(".co.uk", "Append domain name on ALT + Enter = Should be different for every country");
if (event->key() == Qt::Key_Alt && m_holdingAlt && m_locationBarSettings->addCountryWithAlt &&
if (event->key() == Qt::Key_Alt && m_holdingAlt && LocationBarSettings::addCountryWithAlt &&
!text().endsWith(localDomain) && !text().endsWith("/")) {
setText(text().append(localDomain));
}

View File

@ -39,7 +39,6 @@ class LocationCompleter;
class ClickableLabel;
class BookmarkIcon;
class TabbedWebView;
class LocationBarSettings;
class SiteIcon;
class GoIcon;
class RssIcon;
@ -100,7 +99,6 @@ private:
QupZilla* p_QupZilla;
TabbedWebView* m_webView;
LocationCompleter* m_locationCompleter;
LocationBarSettings* m_locationBarSettings;
QMenu* m_menu;
QAction* m_pasteAndGoAction;

View File

@ -19,7 +19,6 @@
#include "mainapplication.h"
#include "settings.h"
LocationBarSettings* LocationBarSettings::s_instance = 0;
bool LocationBarSettings::selectAllOnDoubleClick = false;
bool LocationBarSettings::selectAllOnClick = false;
bool LocationBarSettings::addCountryWithAlt = false;
@ -29,14 +28,6 @@ LocationBarSettings::LocationBarSettings()
loadSettings();
}
LocationBarSettings* LocationBarSettings::instance()
{
if (!s_instance) {
s_instance = new LocationBarSettings();
}
return s_instance;
}
void LocationBarSettings::loadSettings()
{
Settings settings;

View File

@ -23,15 +23,10 @@ class LocationBarSettings
public:
LocationBarSettings();
static LocationBarSettings* instance();
static void loadSettings();
static bool selectAllOnDoubleClick;
static bool selectAllOnClick;
static bool addCountryWithAlt;
private:
static LocationBarSettings* s_instance;
};
#endif // LOCATIONBARSETTINGS_H

View File

@ -192,7 +192,8 @@ SOURCES += main.cpp\
popupwindow/popupwindow.cpp \
popupwindow/popuplocationbar.cpp \
webview/tabbedwebview.cpp \
webview/webview.cpp
webview/webview.cpp \
webview/webviewsettings.cpp
HEADERS += \
3rdparty/qtwin.h \
@ -324,7 +325,8 @@ HEADERS += \
popupwindow/popuplocationbar.h \
webview/tabbedwebview.h \
webview/webview.h \
app/qz_namespace.h
app/qz_namespace.h \
webview/webviewsettings.h
FORMS += \
preferences/autofillmanager.ui \

View File

@ -26,9 +26,6 @@ void PopupWebView::setWebPage(PopupWebPage* page)
m_page = page;
m_page->setParent(this);
setPage(m_page);
// Set default zoom
setZoom(mApp->defaultZoom());
}
PopupWebPage* PopupWebView::webPage()

View File

@ -78,9 +78,6 @@ void TabbedWebView::setWebPage(WebPage* page)
connect(m_page, SIGNAL(linkHovered(QString, QString, QString)), this, SLOT(linkHovered(QString, QString, QString)));
connect(m_page, SIGNAL(windowCloseRequested()), this, SLOT(closeView()));
// Set default zoom
setZoom(mApp->defaultZoom());
}
void TabbedWebView::slotIconChanged()

View File

@ -30,6 +30,7 @@
#include "browsinglibrary.h"
#include "bookmarksmanager.h"
#include "settings.h"
#include "webviewsettings.h"
WebView::WebView(QWidget* parent)
: QWebView(parent)
@ -39,8 +40,6 @@ WebView::WebView(QWidget* parent)
, m_clickedFrame(0)
, m_actionsHaveImages(false)
{
loadSettings();
connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished()));
@ -53,14 +52,6 @@ WebView::WebView(QWidget* parent)
qApp->installEventFilter(this);
}
void WebView::loadSettings()
{
Settings settings;
settings.beginGroup("Browser-Tabs-Settings");
m_newTabAfterActive = settings.value("newTabAfterActive", true).toBool();
settings.endGroup();
}
QIcon WebView::icon() const
{
if (url().scheme() == "qupzilla") {
@ -104,6 +95,13 @@ QUrl WebView::url() const
return returnUrl;
}
void WebView::setPage(QWebPage *page)
{
QWebView::setPage(page);
setZoom(WebViewSettings::defaultZoom);
}
void WebView::load(const QUrl &url)
{
if (url.scheme() == "javascript") {
@ -389,7 +387,7 @@ void WebView::openUrlInSelectedTab()
void WebView::openUrlInBackgroundTab()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
openUrlInNewTab(action->data().toUrl(), m_newTabAfterActive ? Qz::NT_NotSelectedTab : Qz::NT_CleanTab);
openUrlInNewTab(action->data().toUrl(), WebViewSettings::newTabAfterActive ? Qz::NT_NotSelectedTab : Qz::NT_CleanTab);
}
}
@ -819,7 +817,7 @@ void WebView::mouseReleaseEvent(QMouseEvent* event)
QUrl link = frame->hitTestContent(event->pos()).linkUrl();
if (m_clickedUrl == link && event->modifiers() == Qt::ControlModifier) {
if (isUrlValid(link)) {
openUrlInNewTab(link, m_newTabAfterActive ? Qz::NT_NotSelectedTab : Qz::NT_CleanTab);
openUrlInNewTab(link, WebViewSettings::newTabAfterActive ? Qz::NT_NotSelectedTab : Qz::NT_CleanTab);
event->accept();
return;
}

View File

@ -39,7 +39,8 @@ public:
QString title() const;
QUrl url() const;
void loadSettings();
void setPage(QWebPage *page);
bool isLoading() const;
int loadProgress() const;
@ -146,7 +147,6 @@ private:
QWebFrame* m_clickedFrame;
QUrl m_clickedUrl;
bool m_actionsHaveImages;
bool m_newTabAfterActive;
QList<QTouchEvent::TouchPoint> m_touchPoints;
};

View File

@ -0,0 +1,23 @@
#include "webviewsettings.h"
#include "settings.h"
int WebViewSettings::defaultZoom = 100;
bool WebViewSettings::newTabAfterActive = true;
WebViewSettings::WebViewSettings()
{
}
void WebViewSettings::loadSettings()
{
Settings settings;
settings.beginGroup("Browser-Tabs-Settings");
newTabAfterActive = settings.value("newTabAfterActive", true).toBool();
settings.endGroup();
settings.beginGroup("Web-Browser-Settings");
defaultZoom = settings.value("DefaultZoom", 100).toInt();
settings.endGroup();
}

View File

@ -0,0 +1,15 @@
#ifndef WEBVIEWSETTINGS_H
#define WEBVIEWSETTINGS_H
class WebViewSettings
{
public:
WebViewSettings();
static void loadSettings();
static int defaultZoom;
static bool newTabAfterActive;
};
#endif // WEBVIEWSETTINGS_H