1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

NavigationBar: Add support for loading layout from config

There is no ui to configure it for now.
This commit is contained in:
David Rosca 2018-01-04 20:34:10 +01:00
parent 2e7a77a6b4
commit d380d54ef8
5 changed files with 144 additions and 148 deletions

View File

@ -576,10 +576,6 @@ void BrowserWindow::loadSettings()
//Browser Window settings //Browser Window settings
settings.beginGroup("Browser-View-Settings"); settings.beginGroup("Browser-View-Settings");
bool showStatusBar = settings.value("showStatusBar", false).toBool(); bool showStatusBar = settings.value("showStatusBar", false).toBool();
bool showReloadButton = settings.value("showReloadButton", true).toBool();
bool showHomeButton = settings.value("showHomeButton", true).toBool();
bool showBackForwardButtons = settings.value("showBackForwardButtons", true).toBool();
bool showAddTabButton = settings.value("showAddTabButton", false).toBool();
bool showWebSearchBar = settings.value("showWebSearchBar", true).toBool(); bool showWebSearchBar = settings.value("showWebSearchBar", true).toBool();
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();
@ -620,12 +616,6 @@ void BrowserWindow::loadSettings()
#endif #endif
m_navigationToolbar->setSuperMenuVisible(!showMenuBar); m_navigationToolbar->setSuperMenuVisible(!showMenuBar);
m_navigationToolbar->buttonReloadStop()->setVisible(showReloadButton);
m_navigationToolbar->buttonHome()->setVisible(showHomeButton);
m_navigationToolbar->buttonBack()->setVisible(showBackForwardButtons);
m_navigationToolbar->buttonForward()->setVisible(showBackForwardButtons);
m_navigationToolbar->webSearchBar()->setVisible(showWebSearchBar);
m_navigationToolbar->buttonAddTab()->setVisible(showAddTabButton);
} }
void BrowserWindow::goForward() void BrowserWindow::goForward()

View File

@ -37,6 +37,25 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QStyleOption> #include <QStyleOption>
static QString titleForUrl(QString title, const QUrl &url)
{
if (title.isEmpty()) {
title = url.toString(QUrl::RemoveFragment);
}
if (title.isEmpty()) {
return NavigationBar::tr("Empty Page");
}
return QzTools::truncatedText(title, 40);
}
static QIcon iconForPage(const QUrl &url, const QIcon &sIcon)
{
QIcon icon;
icon.addPixmap(url.scheme() == QL1S("qupzilla") ? QIcon(QSL(":icons/qupzilla.png")).pixmap(16) : IconProvider::iconForUrl(url).pixmap(16));
icon.addPixmap(sIcon.pixmap(16), QIcon::Active);
return icon;
}
NavigationBar::NavigationBar(BrowserWindow* window) NavigationBar::NavigationBar(BrowserWindow* window)
: QWidget(window) : QWidget(window)
, m_window(window) , m_window(window)
@ -71,24 +90,26 @@ NavigationBar::NavigationBar(BrowserWindow* window)
backNextLayout->setSpacing(0); backNextLayout->setSpacing(0);
backNextLayout->addWidget(m_buttonBack); backNextLayout->addWidget(m_buttonBack);
backNextLayout->addWidget(m_buttonForward); backNextLayout->addWidget(m_buttonForward);
QWidget *backNextWidget = new QWidget(this);
backNextWidget->setLayout(backNextLayout);
m_reloadStop = new ReloadStopButton(this); m_reloadStop = new ReloadStopButton(this);
m_buttonHome = new ToolButton(this); ToolButton *buttonHome = new ToolButton(this);
m_buttonHome->setObjectName("navigation-button-home"); buttonHome->setObjectName("navigation-button-home");
m_buttonHome->setToolTip(tr("Home")); buttonHome->setToolTip(tr("Home"));
m_buttonHome->setToolButtonStyle(Qt::ToolButtonIconOnly); buttonHome->setToolButtonStyle(Qt::ToolButtonIconOnly);
m_buttonHome->setToolbarButtonLook(true); buttonHome->setToolbarButtonLook(true);
m_buttonHome->setAutoRaise(true); buttonHome->setAutoRaise(true);
m_buttonHome->setFocusPolicy(Qt::NoFocus); buttonHome->setFocusPolicy(Qt::NoFocus);
m_buttonAddTab = new ToolButton(this); ToolButton *buttonAddTab = new ToolButton(this);
m_buttonAddTab->setObjectName("navigation-button-addtab"); buttonAddTab->setObjectName("navigation-button-addtab");
m_buttonAddTab->setToolTip(tr("New Tab")); buttonAddTab->setToolTip(tr("New Tab"));
m_buttonAddTab->setToolButtonStyle(Qt::ToolButtonIconOnly); buttonAddTab->setToolButtonStyle(Qt::ToolButtonIconOnly);
m_buttonAddTab->setToolbarButtonLook(true); buttonAddTab->setToolbarButtonLook(true);
m_buttonAddTab->setAutoRaise(true); buttonAddTab->setAutoRaise(true);
m_buttonAddTab->setFocusPolicy(Qt::NoFocus); buttonAddTab->setFocusPolicy(Qt::NoFocus);
m_menuBack = new Menu(this); m_menuBack = new Menu(this);
m_menuBack->setCloseOnMiddleClick(true); m_menuBack->setCloseOnMiddleClick(true);
@ -119,12 +140,11 @@ NavigationBar::NavigationBar(BrowserWindow* window)
m_navigationSplitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); m_navigationSplitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
m_navigationSplitter->setCollapsible(0, false); m_navigationSplitter->setCollapsible(0, false);
m_layout->addLayout(backNextLayout); addWidget(backNextWidget, QSL("button-backforward"));
m_layout->addWidget(m_reloadStop); addWidget(m_reloadStop, QSL("button-reloadstop"));
m_layout->addWidget(m_buttonHome); addWidget(buttonHome, QSL("button-home"));
m_layout->addWidget(m_buttonAddTab); addWidget(buttonAddTab, QSL("button-addtab"));
m_layout->addWidget(m_navigationSplitter); addWidget(m_navigationSplitter, QSL("locationbar"));
m_layout->addWidget(m_supMenu);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
@ -138,11 +158,11 @@ NavigationBar::NavigationBar(BrowserWindow* window)
connect(m_reloadStop, SIGNAL(stopClicked()), this, SLOT(stop())); connect(m_reloadStop, SIGNAL(stopClicked()), this, SLOT(stop()));
connect(m_reloadStop, SIGNAL(reloadClicked()), this, SLOT(reload())); connect(m_reloadStop, SIGNAL(reloadClicked()), this, SLOT(reload()));
connect(m_buttonHome, SIGNAL(clicked()), m_window, SLOT(goHome())); connect(buttonHome, SIGNAL(clicked()), m_window, SLOT(goHome()));
connect(m_buttonHome, SIGNAL(middleMouseClicked()), m_window, SLOT(goHomeInNewTab())); connect(buttonHome, SIGNAL(middleMouseClicked()), m_window, SLOT(goHomeInNewTab()));
connect(m_buttonHome, SIGNAL(controlClicked()), m_window, SLOT(goHomeInNewTab())); connect(buttonHome, SIGNAL(controlClicked()), m_window, SLOT(goHomeInNewTab()));
connect(m_buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab())); connect(buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab()));
connect(m_buttonAddTab, SIGNAL(middleMouseClicked()), m_window->tabWidget(), SLOT(addTabFromClipboard())); connect(buttonAddTab, SIGNAL(middleMouseClicked()), m_window->tabWidget(), SLOT(addTabFromClipboard()));
} }
void NavigationBar::setSplitterSizes(int locationBar, int websearchBar) void NavigationBar::setSplitterSizes(int locationBar, int websearchBar)
@ -195,6 +215,17 @@ void NavigationBar::setLayoutSpacing(int spacing)
m_layout->setSpacing(spacing); m_layout->setSpacing(spacing);
} }
void NavigationBar::addWidget(QWidget *widget, const QString &id)
{
m_widgets[id] = widget;
reloadLayout();
}
void NavigationBar::removeWidget(const QString &id)
{
m_widgets.remove(id);
}
void NavigationBar::aboutToShowHistoryBackMenu() void NavigationBar::aboutToShowHistoryBackMenu()
{ {
if (!m_menuBack || !m_window->weView()) { if (!m_menuBack || !m_window->weView()) {
@ -277,6 +308,48 @@ void NavigationBar::contextMenuRequested(const QPoint &pos)
menu.exec(mapToGlobal(pos)); menu.exec(mapToGlobal(pos));
} }
void NavigationBar::reloadLayout()
{
const QStringList defaultIds = {
QSL("button-backforward"),
QSL("button-reloadstop"),
QSL("button-home"),
QSL("locationbar")
};
QStringList ids = Settings().value(QSL("NavigationBar/layout"), defaultIds).toStringList();
ids.removeDuplicates();
if (!ids.contains(QSL("locationbar"))) {
ids.append(QSL("locationbar"));
}
while (m_layout->count() != 0) {
QLayoutItem *item = m_layout->takeAt(0);
if (!item) {
continue;
}
QWidget *widget = item->widget();
if (!widget) {
continue;
}
widget->setParent(nullptr);
}
for (QWidget *widget : m_widgets) {
widget->hide();
}
for (const QString &id : qAsConst(ids)) {
QWidget *widget = m_widgets.value(id);
if (widget) {
m_layout->addWidget(widget);
widget->show();
}
}
m_layout->addWidget(m_supMenu);
}
void NavigationBar::loadHistoryIndex() void NavigationBar::loadHistoryIndex()
{ {
QWebEngineHistory* history = m_window->weView()->page()->history(); QWebEngineHistory* history = m_window->weView()->page()->history();
@ -355,27 +428,6 @@ void NavigationBar::goForwardInNewTab()
loadHistoryItemInNewTab(history->forwardItem()); loadHistoryItemInNewTab(history->forwardItem());
} }
QString NavigationBar::titleForUrl(QString title, const QUrl &url)
{
if (title.isEmpty()) {
title = url.toString(QUrl::RemoveFragment);
}
if (title.isEmpty()) {
return tr("Empty Page");
}
return QzTools::truncatedText(title, 40);
}
QIcon NavigationBar::iconForPage(const QUrl &url, const QIcon &sIcon)
{
QIcon icon;
icon.addPixmap(url.scheme() == QL1S("falkon") ? QIcon(QSL(":icons/qupzilla.png")).pixmap(16) : IconProvider::iconForUrl(url).pixmap(16));
icon.addPixmap(sIcon.pixmap(16), QIcon::Active);
return icon;
}
void NavigationBar::loadHistoryItem(const QWebEngineHistoryItem &item) void NavigationBar::loadHistoryItem(const QWebEngineHistoryItem &item)
{ {
m_window->weView()->page()->history()->goToItem(item); m_window->weView()->page()->history()->goToItem(item);

View File

@ -47,11 +47,6 @@ public:
void showReloadButton(); void showReloadButton();
void showStopButton(); void showStopButton();
ToolButton* buttonBack() { return m_buttonBack; }
ToolButton* buttonForward() { return m_buttonForward; }
ToolButton* buttonHome() { return m_buttonHome; }
ToolButton* buttonAddTab() { return m_buttonAddTab; }
ReloadStopButton* buttonReloadStop() { return m_reloadStop; }
WebSearchBar* webSearchBar() { return m_searchLine; } WebSearchBar* webSearchBar() { return m_searchLine; }
QSplitter* splitter() { return m_navigationSplitter; } QSplitter* splitter() { return m_navigationSplitter; }
@ -63,7 +58,8 @@ public:
int layoutSpacing() const; int layoutSpacing() const;
void setLayoutSpacing(int spacing); void setLayoutSpacing(int spacing);
signals: void addWidget(QWidget *widget, const QString &id);
void removeWidget(const QString &id);
public slots: public slots:
void refreshHistory(); void refreshHistory();
@ -86,27 +82,23 @@ private slots:
void contextMenuRequested(const QPoint &pos); void contextMenuRequested(const QPoint &pos);
private: private:
QString titleForUrl(QString title, const QUrl &url); void reloadLayout();
QIcon iconForPage(const QUrl &url, const QIcon &sIcon);
void loadHistoryItem(const QWebEngineHistoryItem &item); void loadHistoryItem(const QWebEngineHistoryItem &item);
void loadHistoryItemInNewTab(const QWebEngineHistoryItem &item); void loadHistoryItemInNewTab(const QWebEngineHistoryItem &item);
BrowserWindow* m_window; BrowserWindow* m_window;
QHBoxLayout* m_layout; QHBoxLayout* m_layout;
QSplitter* m_navigationSplitter; QSplitter* m_navigationSplitter;
ToolButton* m_buttonBack; WebSearchBar* m_searchLine;
ToolButton* m_buttonForward;
ToolButton* m_buttonHome;
ToolButton* m_buttonAddTab;
ToolButton* m_supMenu; ToolButton* m_supMenu;
ReloadStopButton* m_reloadStop;
Menu* m_menuBack; Menu* m_menuBack;
Menu* m_menuForward; Menu* m_menuForward;
ToolButton* m_buttonBack;
ToolButton* m_buttonForward;
ReloadStopButton* m_reloadStop;
WebSearchBar* m_searchLine; QHash<QString, QWidget*> m_widgets;
}; };
#endif // NAVIGATIONBAR_H #endif // NAVIGATIONBAR_H

View File

@ -216,10 +216,6 @@ Preferences::Preferences(BrowserWindow* window)
connect(ui->instantBookmarksToolbar, SIGNAL(toggled(bool)), ui->showBookmarksToolbar, SLOT(setDisabled(bool))); connect(ui->instantBookmarksToolbar, SIGNAL(toggled(bool)), ui->showBookmarksToolbar, SLOT(setDisabled(bool)));
connect(ui->showBookmarksToolbar, SIGNAL(toggled(bool)), ui->instantBookmarksToolbar, SLOT(setDisabled(bool))); connect(ui->showBookmarksToolbar, SIGNAL(toggled(bool)), ui->instantBookmarksToolbar, SLOT(setDisabled(bool)));
ui->showNavigationToolbar->setChecked(settings.value("showNavigationToolbar", true).toBool()); ui->showNavigationToolbar->setChecked(settings.value("showNavigationToolbar", true).toBool());
ui->showHome->setChecked(settings.value("showHomeButton", true).toBool());
ui->showBackForward->setChecked(settings.value("showBackForwardButtons", true).toBool());
ui->showAddTabButton->setChecked(settings.value("showAddTabButton", false).toBool());
ui->showReloadStopButtons->setChecked(settings.value("showReloadButton", true).toBool());
ui->showWebSearchBar->setChecked(settings.value("showWebSearchBar", true).toBool()); ui->showWebSearchBar->setChecked(settings.value("showWebSearchBar", true).toBool());
int currentSettingsPage = settings.value("settingsDialogPage", 0).toInt(0); int currentSettingsPage = settings.value("settingsDialogPage", 0).toInt(0);
settings.endGroup(); settings.endGroup();
@ -906,11 +902,7 @@ void Preferences::saveSettings()
settings.setValue("instantBookmarksToolbar", ui->instantBookmarksToolbar->isChecked()); settings.setValue("instantBookmarksToolbar", ui->instantBookmarksToolbar->isChecked());
settings.setValue("showBookmarksToolbar", ui->showBookmarksToolbar->isChecked()); settings.setValue("showBookmarksToolbar", ui->showBookmarksToolbar->isChecked());
settings.setValue("showNavigationToolbar", ui->showNavigationToolbar->isChecked()); settings.setValue("showNavigationToolbar", ui->showNavigationToolbar->isChecked());
settings.setValue("showHomeButton", ui->showHome->isChecked());
settings.setValue("showBackForwardButtons", ui->showBackForward->isChecked());
settings.setValue("showWebSearchBar", ui->showWebSearchBar->isChecked()); settings.setValue("showWebSearchBar", ui->showWebSearchBar->isChecked());
settings.setValue("showAddTabButton", ui->showAddTabButton->isChecked());
settings.setValue("showReloadButton", ui->showReloadStopButtons->isChecked());
settings.endGroup(); settings.endGroup();
//TABS //TABS

View File

@ -542,42 +542,6 @@
<string>Advanced options</string> <string>Advanced options</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_16"> <layout class="QGridLayout" name="gridLayout_16">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_18">
<property name="text">
<string>&lt;b&gt;Browser Window&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1"> <item row="1" column="1">
<layout class="QGridLayout" name="gridLayout_7"> <layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0"> <item row="0" column="0">
@ -610,6 +574,26 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_18">
<property name="text">
<string>&lt;b&gt;Browser Window&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_8"> <widget class="QLabel" name="label_8">
<property name="text"> <property name="text">
@ -617,21 +601,30 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QCheckBox" name="showHome"> <widget class="QCheckBox" name="showWebSearchBar">
<property name="text"> <property name="text">
<string>Show Home button</string> <string>Show web search bar</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QCheckBox" name="showBackForward">
<property name="text">
<string>Show Back / Forward buttons</string>
</property>
</widget>
</item>
<item row="9" column="1">
<spacer name="verticalSpacer_12"> <spacer name="verticalSpacer_12">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -644,27 +637,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="1">
<widget class="QCheckBox" name="showAddTabButton">
<property name="text">
<string>Show Add Tab button</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="showWebSearchBar">
<property name="text">
<string>Show web search bar</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="showReloadStopButtons">
<property name="text">
<string>Show Reload / Stop buttons</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
@ -2757,7 +2729,6 @@
<tabstop>preferredLanguages</tabstop> <tabstop>preferredLanguages</tabstop>
<tabstop>userStyleSheet</tabstop> <tabstop>userStyleSheet</tabstop>
<tabstop>chooseUserStylesheet</tabstop> <tabstop>chooseUserStylesheet</tabstop>
<tabstop>showBackForward</tabstop>
<tabstop>allowCache</tabstop> <tabstop>allowCache</tabstop>
<tabstop>cacheMB</tabstop> <tabstop>cacheMB</tabstop>
<tabstop>saveHistory</tabstop> <tabstop>saveHistory</tabstop>
@ -2768,7 +2739,6 @@
<tabstop>systemProxy</tabstop> <tabstop>systemProxy</tabstop>
<tabstop>showStatusbar</tabstop> <tabstop>showStatusbar</tabstop>
<tabstop>showNavigationToolbar</tabstop> <tabstop>showNavigationToolbar</tabstop>
<tabstop>showHome</tabstop>
<tabstop>showBookmarksToolbar</tabstop> <tabstop>showBookmarksToolbar</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>