mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-14 02:52:12 +01:00
Add NavigationBarConfigDialog
Allows to change layout of navigation bar and hide/show search bar.
This commit is contained in:
parent
4c494ebfb0
commit
4a4d5b72ad
|
@ -122,6 +122,7 @@ set(SRCS ${SRCS}
|
||||||
navigation/locationbarpopup.cpp
|
navigation/locationbarpopup.cpp
|
||||||
navigation/navigationbar.cpp
|
navigation/navigationbar.cpp
|
||||||
navigation/navigationbartoolbutton.cpp
|
navigation/navigationbartoolbutton.cpp
|
||||||
|
navigation/navigationbarconfigdialog.cpp
|
||||||
navigation/navigationcontainer.cpp
|
navigation/navigationcontainer.cpp
|
||||||
navigation/reloadstopbutton.cpp
|
navigation/reloadstopbutton.cpp
|
||||||
navigation/siteicon.cpp
|
navigation/siteicon.cpp
|
||||||
|
@ -252,6 +253,7 @@ qt5_wrap_ui(SRCS
|
||||||
downloads/downloadmanager.ui
|
downloads/downloadmanager.ui
|
||||||
downloads/downloadoptionsdialog.ui
|
downloads/downloadoptionsdialog.ui
|
||||||
history/historymanager.ui
|
history/historymanager.ui
|
||||||
|
navigation/navigationbarconfigdialog.ui
|
||||||
network/sslerrordialog.ui
|
network/sslerrordialog.ui
|
||||||
notifications/desktopnotification.ui
|
notifications/desktopnotification.ui
|
||||||
opensearch/editsearchengine.ui
|
opensearch/editsearchengine.ui
|
||||||
|
|
|
@ -51,6 +51,11 @@ bool Settings::contains(const QString &key) const
|
||||||
return s_settings->contains(key);
|
return s_settings->contains(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Settings::remove(const QString &key)
|
||||||
|
{
|
||||||
|
s_settings->remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
void Settings::setValue(const QString &key, const QVariant &defaultValue)
|
void Settings::setValue(const QString &key, const QVariant &defaultValue)
|
||||||
{
|
{
|
||||||
s_settings->setValue(key, defaultValue);
|
s_settings->setValue(key, defaultValue);
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
static QzSettings* staticSettings();
|
static QzSettings* staticSettings();
|
||||||
|
|
||||||
bool contains(const QString &key) const;
|
bool contains(const QString &key) const;
|
||||||
|
void remove(const QString &key);
|
||||||
|
|
||||||
void setValue(const QString &key, const QVariant &defaultValue = QVariant());
|
void setValue(const QString &key, const QVariant &defaultValue = QVariant());
|
||||||
QVariant value(const QString &key, const QVariant &defaultValue = QVariant());
|
QVariant value(const QString &key, const QVariant &defaultValue = QVariant());
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "qztools.h"
|
#include "qztools.h"
|
||||||
#include "abstractbuttoninterface.h"
|
#include "abstractbuttoninterface.h"
|
||||||
#include "navigationbartoolbutton.h"
|
#include "navigationbartoolbutton.h"
|
||||||
|
#include "navigationbarconfigdialog.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
|
@ -176,15 +177,16 @@ NavigationBar::NavigationBar(BrowserWindow* window)
|
||||||
connect(buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab()));
|
connect(buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab()));
|
||||||
connect(buttonAddTab, SIGNAL(middleMouseClicked()), m_window->tabWidget(), SLOT(addTabFromClipboard()));
|
connect(buttonAddTab, SIGNAL(middleMouseClicked()), m_window->tabWidget(), SLOT(addTabFromClipboard()));
|
||||||
|
|
||||||
loadSettings();
|
|
||||||
connect(mApp, &MainApplication::settingsReloaded, this, &NavigationBar::loadSettings);
|
connect(mApp, &MainApplication::settingsReloaded, this, &NavigationBar::loadSettings);
|
||||||
|
|
||||||
addWidget(backNextWidget, QSL("button-backforward"), tr("Back and Forward buttons"));
|
addWidget(backNextWidget, QSL("button-backforward"), tr("Back and Forward buttons"));
|
||||||
addWidget(m_reloadStop, QSL("button-reloadstop"), tr("Reload button"));
|
addWidget(m_reloadStop, QSL("button-reloadstop"), tr("Reload button"));
|
||||||
addWidget(buttonHome, QSL("button-home"), tr("Home button"));
|
addWidget(buttonHome, QSL("button-home"), tr("Home button"));
|
||||||
addWidget(buttonAddTab, QSL("button-addtab"), tr("Add tab button"));
|
addWidget(buttonAddTab, QSL("button-addtab"), tr("Add tab button"));
|
||||||
addWidget(m_navigationSplitter, QSL("locationbar"), tr("Address and Search Bar"));
|
addWidget(m_navigationSplitter, QSL("locationbar"), tr("Address and Search bar"));
|
||||||
addWidget(buttonTools, QSL("button-tools"), tr("Tools button"));
|
addWidget(buttonTools, QSL("button-tools"), tr("Tools button"));
|
||||||
|
|
||||||
|
loadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationBar::setSplitterSizes(int locationBar, int websearchBar)
|
void NavigationBar::setSplitterSizes(int locationBar, int websearchBar)
|
||||||
|
@ -398,11 +400,15 @@ void NavigationBar::contextMenuRequested(const QPoint &pos)
|
||||||
{
|
{
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
m_window->createToolbarsMenu(&menu);
|
m_window->createToolbarsMenu(&menu);
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addAction(IconProvider::settingsIcon(), tr("Configure Toolbar"), this, SLOT(openConfigurationDialog()));
|
||||||
menu.exec(mapToGlobal(pos));
|
menu.exec(mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationBar::openConfigurationDialog()
|
void NavigationBar::openConfigurationDialog()
|
||||||
{
|
{
|
||||||
|
NavigationBarConfigDialog *dialog = new NavigationBarConfigDialog(this);
|
||||||
|
dialog->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationBar::toolActionActivated()
|
void NavigationBar::toolActionActivated()
|
||||||
|
@ -453,16 +459,25 @@ void NavigationBar::loadSettings()
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.beginGroup(QSL("NavigationBar"));
|
settings.beginGroup(QSL("NavigationBar"));
|
||||||
m_layoutIds = settings.value(QSL("Layout"), defaultIds).toStringList();
|
m_layoutIds = settings.value(QSL("Layout"), defaultIds).toStringList();
|
||||||
|
m_searchLine->setVisible(settings.value(QSL("ShowSearchBar"), true).toBool());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
m_layoutIds.removeDuplicates();
|
m_layoutIds.removeDuplicates();
|
||||||
if (!m_layoutIds.contains(QSL("locationbar"))) {
|
if (!m_layoutIds.contains(QSL("locationbar"))) {
|
||||||
m_layoutIds.append(QSL("locationbar"));
|
m_layoutIds.append(QSL("locationbar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reloadLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationBar::reloadLayout()
|
void NavigationBar::reloadLayout()
|
||||||
{
|
{
|
||||||
|
if (m_widgets.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpdatesEnabled(false);
|
||||||
|
|
||||||
// Clear layout
|
// Clear layout
|
||||||
while (m_layout->count() != 0) {
|
while (m_layout->count() != 0) {
|
||||||
QLayoutItem *item = m_layout->takeAt(0);
|
QLayoutItem *item = m_layout->takeAt(0);
|
||||||
|
@ -491,6 +506,8 @@ void NavigationBar::reloadLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_layout->addWidget(m_supMenu);
|
m_layout->addWidget(m_supMenu);
|
||||||
|
|
||||||
|
setUpdatesEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationBar::loadHistoryIndex()
|
void NavigationBar::loadHistoryIndex()
|
||||||
|
|
|
@ -118,6 +118,8 @@ private:
|
||||||
|
|
||||||
QStringList m_layoutIds;
|
QStringList m_layoutIds;
|
||||||
QHash<QString, WidgetData> m_widgets;
|
QHash<QString, WidgetData> m_widgets;
|
||||||
|
|
||||||
|
friend class NavigationBarConfigDialog;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAVIGATIONBAR_H
|
#endif // NAVIGATIONBAR_H
|
||||||
|
|
123
src/lib/navigation/navigationbarconfigdialog.cpp
Normal file
123
src/lib/navigation/navigationbarconfigdialog.cpp
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - Qt web browser
|
||||||
|
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#include "navigationbarconfigdialog.h"
|
||||||
|
#include "ui_navigationbarconfigdialog.h"
|
||||||
|
#include "navigationbar.h"
|
||||||
|
#include "toolbutton.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "websearchbar.h"
|
||||||
|
|
||||||
|
NavigationBarConfigDialog::NavigationBarConfigDialog(NavigationBar *navigationBar)
|
||||||
|
: QDialog(navigationBar)
|
||||||
|
, ui(new Ui::NavigationBarConfigDialog)
|
||||||
|
, m_navigationBar(navigationBar)
|
||||||
|
{
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &NavigationBarConfigDialog::buttonClicked);
|
||||||
|
|
||||||
|
loadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigationBarConfigDialog::loadSettings()
|
||||||
|
{
|
||||||
|
auto createItem = [this](const NavigationBar::WidgetData &data) {
|
||||||
|
QListWidgetItem *item = new QListWidgetItem();
|
||||||
|
item->setText(data.name);
|
||||||
|
item->setData(Qt::UserRole + 10, data.id);
|
||||||
|
#if 0
|
||||||
|
// XXX: Crashes in Qt on items drag&drop...
|
||||||
|
ToolButton *button = qobject_cast<ToolButton*>(data.widget);
|
||||||
|
if (button) {
|
||||||
|
item->setIcon(button->icon());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return item;
|
||||||
|
};
|
||||||
|
|
||||||
|
ui->currentItems->clear();
|
||||||
|
for (const QString &id : qAsConst(m_navigationBar->m_layoutIds)) {
|
||||||
|
ui->currentItems->addItem(createItem(m_navigationBar->m_widgets.value(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->availableItems->clear();
|
||||||
|
for (const NavigationBar::WidgetData &data : qAsConst(m_navigationBar->m_widgets)) {
|
||||||
|
if (!m_navigationBar->m_layoutIds.contains(data.id)) {
|
||||||
|
ui->availableItems->addItem(createItem(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->showSearchBar->setChecked(m_navigationBar->webSearchBar()->isVisible());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigationBarConfigDialog::saveSettings()
|
||||||
|
{
|
||||||
|
QStringList ids;
|
||||||
|
for (int i = 0; i < ui->currentItems->count(); ++i) {
|
||||||
|
ids.append(ui->currentItems->item(i)->data(Qt::UserRole + 10).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings settings;
|
||||||
|
settings.beginGroup(QSL("NavigationBar"));
|
||||||
|
settings.setValue(QSL("Layout"), ids);
|
||||||
|
settings.setValue(QSL("ShowSearchBar"), ui->showSearchBar->isChecked());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
mApp->reloadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigationBarConfigDialog::resetToDefaults()
|
||||||
|
{
|
||||||
|
Settings settings;
|
||||||
|
settings.beginGroup(QSL("NavigationBar"));
|
||||||
|
settings.remove(QSL("Layout"));
|
||||||
|
settings.remove(QSL("ShowSearchBar"));
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
mApp->reloadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigationBarConfigDialog::buttonClicked(QAbstractButton *button)
|
||||||
|
{
|
||||||
|
switch (ui->buttonBox->buttonRole(button)) {
|
||||||
|
case QDialogButtonBox::ApplyRole:
|
||||||
|
saveSettings();
|
||||||
|
loadSettings();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QDialogButtonBox::RejectRole:
|
||||||
|
close();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QDialogButtonBox::ResetRole:
|
||||||
|
resetToDefaults();
|
||||||
|
loadSettings();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QDialogButtonBox::AcceptRole:
|
||||||
|
saveSettings();
|
||||||
|
close();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
47
src/lib/navigation/navigationbarconfigdialog.h
Normal file
47
src/lib/navigation/navigationbarconfigdialog.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/* ============================================================
|
||||||
|
* QupZilla - Qt web browser
|
||||||
|
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
#include "qzcommon.h"
|
||||||
|
|
||||||
|
class QAbstractButton;
|
||||||
|
|
||||||
|
class NavigationBar;
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class NavigationBarConfigDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class QUPZILLA_EXPORT NavigationBarConfigDialog : public QDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit NavigationBarConfigDialog(NavigationBar *navigationBar);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void loadSettings();
|
||||||
|
void saveSettings();
|
||||||
|
void resetToDefaults();
|
||||||
|
|
||||||
|
void buttonClicked(QAbstractButton *button);
|
||||||
|
|
||||||
|
Ui::NavigationBarConfigDialog* ui;
|
||||||
|
NavigationBar *m_navigationBar;
|
||||||
|
};
|
97
src/lib/navigation/navigationbarconfigdialog.ui
Normal file
97
src/lib/navigation/navigationbarconfigdialog.ui
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>NavigationBarConfigDialog</class>
|
||||||
|
<widget class="QDialog" name="NavigationBarConfigDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>674</width>
|
||||||
|
<height>466</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Configure Toolbar</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<property name="horizontalSpacing">
|
||||||
|
<number>50</number>
|
||||||
|
</property>
|
||||||
|
<item row="4" column="0" colspan="2">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QListWidget" name="currentItems">
|
||||||
|
<property name="acceptDrops">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="dragEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="dragDropMode">
|
||||||
|
<enum>QAbstractItemView::DragDrop</enum>
|
||||||
|
</property>
|
||||||
|
<property name="defaultDropAction">
|
||||||
|
<enum>Qt::MoveAction</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>10</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="showSearchBar">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show search bar</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QListWidget" name="availableItems">
|
||||||
|
<property name="dragEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="dragDropMode">
|
||||||
|
<enum>QAbstractItemView::DragDrop</enum>
|
||||||
|
</property>
|
||||||
|
<property name="defaultDropAction">
|
||||||
|
<enum>Qt::MoveAction</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Available items:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Current items:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user