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

BrowserWindow: Save sidebar for each window

Allows to have different sidebar on each window.
This commit is contained in:
David Rosca 2018-01-02 18:42:40 +01:00
parent 1de32182c1
commit 1aa4b41151
4 changed files with 38 additions and 29 deletions

View File

@ -375,7 +375,8 @@ void BrowserWindow::setupUi()
QSL("LocationBarWidth"), QSL("LocationBarWidth"),
QSL("WebSearchBarWidth"), QSL("WebSearchBarWidth"),
QSL("SideBarWidth"), QSL("SideBarWidth"),
QSL("WebViewWidth") QSL("WebViewWidth"),
QSL("SideBar")
}; };
for (const QString &key : keys) { for (const QString &key : keys) {
if (settings.contains(key)) { if (settings.contains(key)) {
@ -532,13 +533,14 @@ void BrowserWindow::createEncodingSubMenu(const QString &name, QStringList &code
QHash<QString, QVariant> BrowserWindow::saveUiState() QHash<QString, QVariant> BrowserWindow::saveUiState()
{ {
saveSideBarWidth(); saveSideBarSettings();
QHash<QString, QVariant> state; QHash<QString, QVariant> state;
state[QSL("LocationBarWidth")] = m_navigationToolbar->splitter()->sizes().at(0); state[QSL("LocationBarWidth")] = m_navigationToolbar->splitter()->sizes().at(0);
state[QSL("WebSearchBarWidth")] = m_navigationToolbar->splitter()->sizes().at(1); state[QSL("WebSearchBarWidth")] = m_navigationToolbar->splitter()->sizes().at(1);
state[QSL("SideBarWidth")] = m_sideBarWidth; state[QSL("SideBarWidth")] = m_sideBarWidth;
state[QSL("WebViewWidth")] = m_webViewWidth; state[QSL("WebViewWidth")] = m_webViewWidth;
state[QSL("SideBar")] = m_sideBarManager->activeSideBar();
return state; return state;
} }
@ -550,6 +552,16 @@ void BrowserWindow::restoreUiState(const QHash<QString, QVariant> &state)
m_sideBarWidth = state.value(QSL("SideBarWidth"), 250).toInt(); m_sideBarWidth = state.value(QSL("SideBarWidth"), 250).toInt();
m_webViewWidth = state.value(QSL("WebViewWidth"), 2000).toInt(); m_webViewWidth = state.value(QSL("WebViewWidth"), 2000).toInt();
if (m_sideBar) {
m_mainSplitter->setSizes({m_sideBarWidth, m_webViewWidth});
}
const QString activeSideBar = state.value(QSL("SideBar")).toString();
if (activeSideBar.isEmpty() && m_sideBar) {
m_sideBar->close();
} else {
m_sideBarManager->showSideBar(activeSideBar, false);
}
} }
void BrowserWindow::loadSettings() void BrowserWindow::loadSettings()
@ -572,7 +584,6 @@ void BrowserWindow::loadSettings()
bool showBookmarksToolbar = settings.value("showBookmarksToolbar", true).toBool(); bool showBookmarksToolbar = settings.value("showBookmarksToolbar", true).toBool();
bool showNavigationToolbar = settings.value("showNavigationToolbar", true).toBool(); bool showNavigationToolbar = settings.value("showNavigationToolbar", true).toBool();
bool showMenuBar = settings.value("showMenubar", false).toBool(); bool showMenuBar = settings.value("showMenubar", false).toBool();
const QString activeSideBar = settings.value("SideBar", "None").toString();
// Make sure both menubar and navigationbar are not hidden // Make sure both menubar and navigationbar are not hidden
// Fixes #781 // Fixes #781
@ -615,8 +626,6 @@ void BrowserWindow::loadSettings()
m_navigationToolbar->buttonForward()->setVisible(showBackForwardButtons); m_navigationToolbar->buttonForward()->setVisible(showBackForwardButtons);
m_navigationToolbar->webSearchBar()->setVisible(showWebSearchBar); m_navigationToolbar->webSearchBar()->setVisible(showWebSearchBar);
m_navigationToolbar->buttonAddTab()->setVisible(showAddTabButton); m_navigationToolbar->buttonAddTab()->setVisible(showAddTabButton);
m_sideBarManager->showSideBar(activeSideBar, false);
} }
void BrowserWindow::goForward() void BrowserWindow::goForward()
@ -833,21 +842,21 @@ SideBar* BrowserWindow::addSideBar()
m_mainSplitter->insertWidget(0, m_sideBar.data()); m_mainSplitter->insertWidget(0, m_sideBar.data());
m_mainSplitter->setCollapsible(0, false); m_mainSplitter->setCollapsible(0, false);
m_mainSplitter->setSizes(QList<int>() << m_sideBarWidth << m_webViewWidth); m_mainSplitter->setSizes({m_sideBarWidth, m_webViewWidth});
return m_sideBar.data(); return m_sideBar.data();
} }
void BrowserWindow::saveSideBarWidth() void BrowserWindow::saveSideBarSettings()
{ {
if (!m_sideBar) { if (m_sideBar) {
return; // That +1 is important here, without it, the sidebar width would
// decrease by 1 pixel every close
m_sideBarWidth = m_mainSplitter->sizes().at(0) + 1;
m_webViewWidth = width() - m_sideBarWidth;
} }
// That +1 is important here, without it, the sidebar width would Settings().setValue(QSL("Browser-View-Settings/SideBar"), m_sideBarManager->activeSideBar());
// decrease by 1 pixel every close
m_sideBarWidth = m_mainSplitter->sizes().at(0) + 1;
m_webViewWidth = width() - m_sideBarWidth;
} }
void BrowserWindow::toggleShowMenubar() void BrowserWindow::toggleShowMenubar()

View File

@ -101,7 +101,7 @@ public:
void removeActions(const QList<QAction*> &actions); void removeActions(const QList<QAction*> &actions);
SideBar* addSideBar(); SideBar* addSideBar();
void saveSideBarWidth(); void saveSideBarSettings();
TabbedWebView* weView() const; TabbedWebView* weView() const;
TabbedWebView* weView(int index) const; TabbedWebView* weView(int index) const;

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* Falkon - Qt web browser * Falkon - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -92,6 +92,11 @@ SideBarManager::SideBarManager(BrowserWindow* parent)
{ {
} }
QString SideBarManager::activeSideBar() const
{
return m_activeBar;
}
void SideBarManager::createMenu(QMenu* menu) void SideBarManager::createMenu(QMenu* menu)
{ {
m_window->removeActions(menu->actions()); m_window->removeActions(menu->actions());
@ -145,7 +150,7 @@ void SideBarManager::slotShowSideBar()
void SideBarManager::showSideBar(const QString &id, bool toggle) void SideBarManager::showSideBar(const QString &id, bool toggle)
{ {
if (id == QLatin1String("None")) { if (id.isEmpty() || id == QL1S("None")) {
return; return;
} }
@ -158,10 +163,8 @@ void SideBarManager::showSideBar(const QString &id, bool toggle)
return; return;
} }
m_sideBar.data()->close(); m_sideBar.data()->close();
m_activeBar = "None"; m_activeBar.clear();
m_window->saveSideBarSettings();
Settings settings;
settings.setValue("Browser-View-Settings/SideBar", m_activeBar);
return; return;
} }
@ -183,9 +186,7 @@ void SideBarManager::showSideBar(const QString &id, bool toggle)
} }
m_activeBar = id; m_activeBar = id;
m_window->saveSideBarSettings();
Settings settings;
settings.setValue("Browser-View-Settings/SideBar", m_activeBar);
} }
void SideBarManager::sideBarRemoved(const QString &id) void SideBarManager::sideBarRemoved(const QString &id)
@ -201,10 +202,7 @@ void SideBarManager::closeSideBar()
if (mApp->isClosing()) { if (mApp->isClosing()) {
return; return;
} }
m_activeBar = "None";
Settings settings; m_activeBar.clear();
settings.setValue("Browser-View-Settings/SideBar", m_activeBar); m_window->saveSideBarSettings();
m_window->saveSideBarWidth();
} }

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* Falkon - Qt web browser * Falkon - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -60,6 +60,8 @@ class FALKON_EXPORT SideBarManager : public QObject
public: public:
explicit SideBarManager(BrowserWindow* parent); explicit SideBarManager(BrowserWindow* parent);
QString activeSideBar() const;
void createMenu(QMenu* menu); void createMenu(QMenu* menu);
void showSideBar(const QString &id, bool toggle = true); void showSideBar(const QString &id, bool toggle = true);