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:
parent
2e7a77a6b4
commit
d380d54ef8
@ -576,10 +576,6 @@ void BrowserWindow::loadSettings()
|
||||
//Browser Window settings
|
||||
settings.beginGroup("Browser-View-Settings");
|
||||
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 showBookmarksToolbar = settings.value("showBookmarksToolbar", true).toBool();
|
||||
bool showNavigationToolbar = settings.value("showNavigationToolbar", true).toBool();
|
||||
@ -620,12 +616,6 @@ void BrowserWindow::loadSettings()
|
||||
#endif
|
||||
|
||||
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()
|
||||
|
@ -37,6 +37,25 @@
|
||||
#include <QMouseEvent>
|
||||
#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)
|
||||
: QWidget(window)
|
||||
, m_window(window)
|
||||
@ -71,24 +90,26 @@ NavigationBar::NavigationBar(BrowserWindow* window)
|
||||
backNextLayout->setSpacing(0);
|
||||
backNextLayout->addWidget(m_buttonBack);
|
||||
backNextLayout->addWidget(m_buttonForward);
|
||||
QWidget *backNextWidget = new QWidget(this);
|
||||
backNextWidget->setLayout(backNextLayout);
|
||||
|
||||
m_reloadStop = new ReloadStopButton(this);
|
||||
|
||||
m_buttonHome = new ToolButton(this);
|
||||
m_buttonHome->setObjectName("navigation-button-home");
|
||||
m_buttonHome->setToolTip(tr("Home"));
|
||||
m_buttonHome->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
m_buttonHome->setToolbarButtonLook(true);
|
||||
m_buttonHome->setAutoRaise(true);
|
||||
m_buttonHome->setFocusPolicy(Qt::NoFocus);
|
||||
ToolButton *buttonHome = new ToolButton(this);
|
||||
buttonHome->setObjectName("navigation-button-home");
|
||||
buttonHome->setToolTip(tr("Home"));
|
||||
buttonHome->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
buttonHome->setToolbarButtonLook(true);
|
||||
buttonHome->setAutoRaise(true);
|
||||
buttonHome->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
m_buttonAddTab = new ToolButton(this);
|
||||
m_buttonAddTab->setObjectName("navigation-button-addtab");
|
||||
m_buttonAddTab->setToolTip(tr("New Tab"));
|
||||
m_buttonAddTab->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
m_buttonAddTab->setToolbarButtonLook(true);
|
||||
m_buttonAddTab->setAutoRaise(true);
|
||||
m_buttonAddTab->setFocusPolicy(Qt::NoFocus);
|
||||
ToolButton *buttonAddTab = new ToolButton(this);
|
||||
buttonAddTab->setObjectName("navigation-button-addtab");
|
||||
buttonAddTab->setToolTip(tr("New Tab"));
|
||||
buttonAddTab->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
buttonAddTab->setToolbarButtonLook(true);
|
||||
buttonAddTab->setAutoRaise(true);
|
||||
buttonAddTab->setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
m_menuBack = new Menu(this);
|
||||
m_menuBack->setCloseOnMiddleClick(true);
|
||||
@ -119,12 +140,11 @@ NavigationBar::NavigationBar(BrowserWindow* window)
|
||||
m_navigationSplitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
m_navigationSplitter->setCollapsible(0, false);
|
||||
|
||||
m_layout->addLayout(backNextLayout);
|
||||
m_layout->addWidget(m_reloadStop);
|
||||
m_layout->addWidget(m_buttonHome);
|
||||
m_layout->addWidget(m_buttonAddTab);
|
||||
m_layout->addWidget(m_navigationSplitter);
|
||||
m_layout->addWidget(m_supMenu);
|
||||
addWidget(backNextWidget, QSL("button-backforward"));
|
||||
addWidget(m_reloadStop, QSL("button-reloadstop"));
|
||||
addWidget(buttonHome, QSL("button-home"));
|
||||
addWidget(buttonAddTab, QSL("button-addtab"));
|
||||
addWidget(m_navigationSplitter, QSL("locationbar"));
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
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(reloadClicked()), this, SLOT(reload()));
|
||||
connect(m_buttonHome, SIGNAL(clicked()), m_window, SLOT(goHome()));
|
||||
connect(m_buttonHome, SIGNAL(middleMouseClicked()), m_window, SLOT(goHomeInNewTab()));
|
||||
connect(m_buttonHome, SIGNAL(controlClicked()), m_window, SLOT(goHomeInNewTab()));
|
||||
connect(m_buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab()));
|
||||
connect(m_buttonAddTab, SIGNAL(middleMouseClicked()), m_window->tabWidget(), SLOT(addTabFromClipboard()));
|
||||
connect(buttonHome, SIGNAL(clicked()), m_window, SLOT(goHome()));
|
||||
connect(buttonHome, SIGNAL(middleMouseClicked()), m_window, SLOT(goHomeInNewTab()));
|
||||
connect(buttonHome, SIGNAL(controlClicked()), m_window, SLOT(goHomeInNewTab()));
|
||||
connect(buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab()));
|
||||
connect(buttonAddTab, SIGNAL(middleMouseClicked()), m_window->tabWidget(), SLOT(addTabFromClipboard()));
|
||||
}
|
||||
|
||||
void NavigationBar::setSplitterSizes(int locationBar, int websearchBar)
|
||||
@ -195,6 +215,17 @@ void NavigationBar::setLayoutSpacing(int 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()
|
||||
{
|
||||
if (!m_menuBack || !m_window->weView()) {
|
||||
@ -277,6 +308,48 @@ void NavigationBar::contextMenuRequested(const QPoint &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()
|
||||
{
|
||||
QWebEngineHistory* history = m_window->weView()->page()->history();
|
||||
@ -355,27 +428,6 @@ void NavigationBar::goForwardInNewTab()
|
||||
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)
|
||||
{
|
||||
m_window->weView()->page()->history()->goToItem(item);
|
||||
|
@ -47,11 +47,6 @@ public:
|
||||
void showReloadButton();
|
||||
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; }
|
||||
QSplitter* splitter() { return m_navigationSplitter; }
|
||||
|
||||
@ -63,7 +58,8 @@ public:
|
||||
int layoutSpacing() const;
|
||||
void setLayoutSpacing(int spacing);
|
||||
|
||||
signals:
|
||||
void addWidget(QWidget *widget, const QString &id);
|
||||
void removeWidget(const QString &id);
|
||||
|
||||
public slots:
|
||||
void refreshHistory();
|
||||
@ -86,27 +82,23 @@ private slots:
|
||||
void contextMenuRequested(const QPoint &pos);
|
||||
|
||||
private:
|
||||
QString titleForUrl(QString title, const QUrl &url);
|
||||
QIcon iconForPage(const QUrl &url, const QIcon &sIcon);
|
||||
|
||||
void reloadLayout();
|
||||
void loadHistoryItem(const QWebEngineHistoryItem &item);
|
||||
void loadHistoryItemInNewTab(const QWebEngineHistoryItem &item);
|
||||
|
||||
BrowserWindow* m_window;
|
||||
|
||||
QHBoxLayout* m_layout;
|
||||
QSplitter* m_navigationSplitter;
|
||||
ToolButton* m_buttonBack;
|
||||
ToolButton* m_buttonForward;
|
||||
ToolButton* m_buttonHome;
|
||||
ToolButton* m_buttonAddTab;
|
||||
WebSearchBar* m_searchLine;
|
||||
ToolButton* m_supMenu;
|
||||
ReloadStopButton* m_reloadStop;
|
||||
|
||||
Menu* m_menuBack;
|
||||
Menu* m_menuForward;
|
||||
ToolButton* m_buttonBack;
|
||||
ToolButton* m_buttonForward;
|
||||
ReloadStopButton* m_reloadStop;
|
||||
|
||||
WebSearchBar* m_searchLine;
|
||||
QHash<QString, QWidget*> m_widgets;
|
||||
};
|
||||
|
||||
#endif // NAVIGATIONBAR_H
|
||||
|
@ -216,10 +216,6 @@ Preferences::Preferences(BrowserWindow* window)
|
||||
connect(ui->instantBookmarksToolbar, SIGNAL(toggled(bool)), ui->showBookmarksToolbar, SLOT(setDisabled(bool)));
|
||||
connect(ui->showBookmarksToolbar, SIGNAL(toggled(bool)), ui->instantBookmarksToolbar, SLOT(setDisabled(bool)));
|
||||
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());
|
||||
int currentSettingsPage = settings.value("settingsDialogPage", 0).toInt(0);
|
||||
settings.endGroup();
|
||||
@ -906,11 +902,7 @@ void Preferences::saveSettings()
|
||||
settings.setValue("instantBookmarksToolbar", ui->instantBookmarksToolbar->isChecked());
|
||||
settings.setValue("showBookmarksToolbar", ui->showBookmarksToolbar->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("showAddTabButton", ui->showAddTabButton->isChecked());
|
||||
settings.setValue("showReloadButton", ui->showReloadStopButtons->isChecked());
|
||||
settings.endGroup();
|
||||
|
||||
//TABS
|
||||
|
@ -542,42 +542,6 @@
|
||||
<string>Advanced options</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_16">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_18">
|
||||
<property name="text">
|
||||
<string><b>Browser Window</b></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">
|
||||
<layout class="QGridLayout" name="gridLayout_7">
|
||||
<item row="0" column="0">
|
||||
@ -610,6 +574,26 @@
|
||||
</item>
|
||||
</layout>
|
||||
</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><b>Browser Window</b></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
@ -617,21 +601,30 @@
|
||||
</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="3" column="1">
|
||||
<widget class="QCheckBox" name="showHome">
|
||||
<widget class="QCheckBox" name="showWebSearchBar">
|
||||
<property name="text">
|
||||
<string>Show Home button</string>
|
||||
<string>Show web search bar</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -644,27 +637,6 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</widget>
|
||||
</widget>
|
||||
@ -2757,7 +2729,6 @@
|
||||
<tabstop>preferredLanguages</tabstop>
|
||||
<tabstop>userStyleSheet</tabstop>
|
||||
<tabstop>chooseUserStylesheet</tabstop>
|
||||
<tabstop>showBackForward</tabstop>
|
||||
<tabstop>allowCache</tabstop>
|
||||
<tabstop>cacheMB</tabstop>
|
||||
<tabstop>saveHistory</tabstop>
|
||||
@ -2768,7 +2739,6 @@
|
||||
<tabstop>systemProxy</tabstop>
|
||||
<tabstop>showStatusbar</tabstop>
|
||||
<tabstop>showNavigationToolbar</tabstop>
|
||||
<tabstop>showHome</tabstop>
|
||||
<tabstop>showBookmarksToolbar</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
|
Loading…
Reference in New Issue
Block a user