diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 5c4e7c5bd..d0172d335 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -122,6 +122,7 @@ set(SRCS ${SRCS} navigation/locationbarpopup.cpp navigation/navigationbar.cpp navigation/navigationbartoolbutton.cpp + navigation/navigationbarconfigdialog.cpp navigation/navigationcontainer.cpp navigation/reloadstopbutton.cpp navigation/siteicon.cpp @@ -252,6 +253,7 @@ qt5_wrap_ui(SRCS downloads/downloadmanager.ui downloads/downloadoptionsdialog.ui history/historymanager.ui + navigation/navigationbarconfigdialog.ui network/sslerrordialog.ui notifications/desktopnotification.ui opensearch/editsearchengine.ui diff --git a/src/lib/app/settings.cpp b/src/lib/app/settings.cpp index f85adf251..7f6991308 100644 --- a/src/lib/app/settings.cpp +++ b/src/lib/app/settings.cpp @@ -51,6 +51,11 @@ bool Settings::contains(const QString &key) const return s_settings->contains(key); } +void Settings::remove(const QString &key) +{ + s_settings->remove(key); +} + void Settings::setValue(const QString &key, const QVariant &defaultValue) { s_settings->setValue(key, defaultValue); diff --git a/src/lib/app/settings.h b/src/lib/app/settings.h index 5939a9877..d6d172f41 100644 --- a/src/lib/app/settings.h +++ b/src/lib/app/settings.h @@ -39,6 +39,7 @@ public: static QzSettings* staticSettings(); bool contains(const QString &key) const; + void remove(const QString &key); void setValue(const QString &key, const QVariant &defaultValue = QVariant()); QVariant value(const QString &key, const QVariant &defaultValue = QVariant()); diff --git a/src/lib/navigation/navigationbar.cpp b/src/lib/navigation/navigationbar.cpp index f429224b3..673b929a0 100644 --- a/src/lib/navigation/navigationbar.cpp +++ b/src/lib/navigation/navigationbar.cpp @@ -30,6 +30,7 @@ #include "qztools.h" #include "abstractbuttoninterface.h" #include "navigationbartoolbutton.h" +#include "navigationbarconfigdialog.h" #include #include @@ -176,15 +177,16 @@ NavigationBar::NavigationBar(BrowserWindow* window) connect(buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab())); connect(buttonAddTab, SIGNAL(middleMouseClicked()), m_window->tabWidget(), SLOT(addTabFromClipboard())); - loadSettings(); connect(mApp, &MainApplication::settingsReloaded, this, &NavigationBar::loadSettings); addWidget(backNextWidget, QSL("button-backforward"), tr("Back and Forward buttons")); addWidget(m_reloadStop, QSL("button-reloadstop"), tr("Reload button")); addWidget(buttonHome, QSL("button-home"), tr("Home 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")); + + loadSettings(); } void NavigationBar::setSplitterSizes(int locationBar, int websearchBar) @@ -398,11 +400,15 @@ void NavigationBar::contextMenuRequested(const QPoint &pos) { QMenu menu; m_window->createToolbarsMenu(&menu); + menu.addSeparator(); + menu.addAction(IconProvider::settingsIcon(), tr("Configure Toolbar"), this, SLOT(openConfigurationDialog())); menu.exec(mapToGlobal(pos)); } void NavigationBar::openConfigurationDialog() { + NavigationBarConfigDialog *dialog = new NavigationBarConfigDialog(this); + dialog->show(); } void NavigationBar::toolActionActivated() @@ -453,16 +459,25 @@ void NavigationBar::loadSettings() Settings settings; settings.beginGroup(QSL("NavigationBar")); m_layoutIds = settings.value(QSL("Layout"), defaultIds).toStringList(); + m_searchLine->setVisible(settings.value(QSL("ShowSearchBar"), true).toBool()); settings.endGroup(); m_layoutIds.removeDuplicates(); if (!m_layoutIds.contains(QSL("locationbar"))) { m_layoutIds.append(QSL("locationbar")); } + + reloadLayout(); } void NavigationBar::reloadLayout() { + if (m_widgets.isEmpty()) { + return; + } + + setUpdatesEnabled(false); + // Clear layout while (m_layout->count() != 0) { QLayoutItem *item = m_layout->takeAt(0); @@ -491,6 +506,8 @@ void NavigationBar::reloadLayout() } m_layout->addWidget(m_supMenu); + + setUpdatesEnabled(true); } void NavigationBar::loadHistoryIndex() diff --git a/src/lib/navigation/navigationbar.h b/src/lib/navigation/navigationbar.h index 85a2e35e2..aebc62b05 100644 --- a/src/lib/navigation/navigationbar.h +++ b/src/lib/navigation/navigationbar.h @@ -118,6 +118,8 @@ private: QStringList m_layoutIds; QHash m_widgets; + + friend class NavigationBarConfigDialog; }; #endif // NAVIGATIONBAR_H diff --git a/src/lib/navigation/navigationbarconfigdialog.cpp b/src/lib/navigation/navigationbarconfigdialog.cpp new file mode 100644 index 000000000..01a4b6905 --- /dev/null +++ b/src/lib/navigation/navigationbarconfigdialog.cpp @@ -0,0 +1,123 @@ +/* ============================================================ +* QupZilla - Qt web browser +* Copyright (C) 2018 David Rosca +* +* 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 . +* ============================================================ */ +#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(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; + } +} diff --git a/src/lib/navigation/navigationbarconfigdialog.h b/src/lib/navigation/navigationbarconfigdialog.h new file mode 100644 index 000000000..25ae06df3 --- /dev/null +++ b/src/lib/navigation/navigationbarconfigdialog.h @@ -0,0 +1,47 @@ +/* ============================================================ +* QupZilla - Qt web browser +* Copyright (C) 2018 David Rosca +* +* 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 . +* ============================================================ */ +#pragma once + +#include + +#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; +}; diff --git a/src/lib/navigation/navigationbarconfigdialog.ui b/src/lib/navigation/navigationbarconfigdialog.ui new file mode 100644 index 000000000..8c56580b6 --- /dev/null +++ b/src/lib/navigation/navigationbarconfigdialog.ui @@ -0,0 +1,97 @@ + + + NavigationBarConfigDialog + + + + 0 + 0 + 674 + 466 + + + + Configure Toolbar + + + + 50 + + + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults + + + + + + + true + + + true + + + QAbstractItemView::DragDrop + + + Qt::MoveAction + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + Show search bar + + + + + + + true + + + QAbstractItemView::DragDrop + + + Qt::MoveAction + + + + + + + Available items: + + + + + + + Current items: + + + + + + + +