Allows to change layout of navigation bar and hide/show search bar.remotes/origin/Falkon/3.0
parent
4c494ebfb0
commit
4a4d5b72ad
8 changed files with 296 additions and 2 deletions
@ -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; |
||||
} |
||||
} |
||||
@ -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; |
||||
}; |
||||
@ -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