2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2018-01-04 18:29:04 +01:00
|
|
|
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
|
2011-09-23 22:06:21 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2011-09-11 19:15:06 +02:00
|
|
|
#include "navigationbar.h"
|
|
|
|
#include "toolbutton.h"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "mainapplication.h"
|
2011-09-11 19:15:06 +02:00
|
|
|
#include "iconprovider.h"
|
|
|
|
#include "websearchbar.h"
|
|
|
|
#include "reloadstopbutton.h"
|
2011-12-14 22:30:05 +01:00
|
|
|
#include "enhancedmenu.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "tabbedwebview.h"
|
2012-04-03 19:28:12 +02:00
|
|
|
#include "webpage.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2014-03-20 09:11:19 +01:00
|
|
|
#include "qztools.h"
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2014-02-12 13:50:06 +01:00
|
|
|
#include <QTimer>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QSplitter>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QStackedWidget>
|
2015-01-27 11:01:52 +01:00
|
|
|
#include <QWebEngineHistory>
|
2013-02-09 14:08:12 +01:00
|
|
|
#include <QMouseEvent>
|
2013-04-27 12:57:13 +02:00
|
|
|
#include <QStyleOption>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2018-01-04 20:34:10 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
NavigationBar::NavigationBar(BrowserWindow* window)
|
|
|
|
: QWidget(window)
|
|
|
|
, m_window(window)
|
2011-09-11 19:15:06 +02:00
|
|
|
{
|
2014-03-30 16:38:34 +02:00
|
|
|
setObjectName(QSL("navigationbar"));
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
m_layout = new QHBoxLayout(this);
|
2013-04-26 23:11:24 +02:00
|
|
|
m_layout->setMargin(style()->pixelMetric(QStyle::PM_ToolBarItemMargin, 0, this));
|
|
|
|
m_layout->setSpacing(style()->pixelMetric(QStyle::PM_ToolBarItemSpacing, 0, this));
|
2011-09-11 19:15:06 +02:00
|
|
|
setLayout(m_layout);
|
|
|
|
|
2011-12-04 20:09:44 +01:00
|
|
|
m_buttonBack = new ToolButton(this);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_buttonBack->setObjectName("navigation-button-back");
|
|
|
|
m_buttonBack->setToolTip(tr("Back"));
|
|
|
|
m_buttonBack->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
2014-04-19 13:46:23 +02:00
|
|
|
m_buttonBack->setToolbarButtonLook(true);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_buttonBack->setAutoRaise(true);
|
|
|
|
m_buttonBack->setEnabled(false);
|
2012-01-08 12:38:02 +01:00
|
|
|
m_buttonBack->setFocusPolicy(Qt::NoFocus);
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2014-04-19 13:10:20 +02:00
|
|
|
m_buttonForward = new ToolButton(this);
|
|
|
|
m_buttonForward->setObjectName("navigation-button-next");
|
|
|
|
m_buttonForward->setToolTip(tr("Forward"));
|
|
|
|
m_buttonForward->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
2014-04-19 13:46:23 +02:00
|
|
|
m_buttonForward->setToolbarButtonLook(true);
|
2014-04-19 13:10:20 +02:00
|
|
|
m_buttonForward->setAutoRaise(true);
|
|
|
|
m_buttonForward->setEnabled(false);
|
|
|
|
m_buttonForward->setFocusPolicy(Qt::NoFocus);
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
QHBoxLayout* backNextLayout = new QHBoxLayout();
|
2011-12-18 13:15:56 +01:00
|
|
|
backNextLayout->setContentsMargins(0, 0, 0, 0);
|
2011-09-11 19:15:06 +02:00
|
|
|
backNextLayout->setSpacing(0);
|
|
|
|
backNextLayout->addWidget(m_buttonBack);
|
2014-04-19 13:10:20 +02:00
|
|
|
backNextLayout->addWidget(m_buttonForward);
|
2018-01-04 20:34:10 +01:00
|
|
|
QWidget *backNextWidget = new QWidget(this);
|
|
|
|
backNextWidget->setLayout(backNextLayout);
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2011-12-04 20:09:44 +01:00
|
|
|
m_reloadStop = new ReloadStopButton(this);
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2018-01-04 20:34:10 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2011-12-12 18:07:07 +01:00
|
|
|
m_menuBack = new Menu(this);
|
2014-02-10 21:34:46 +01:00
|
|
|
m_menuBack->setCloseOnMiddleClick(true);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_buttonBack->setMenu(m_menuBack);
|
2014-04-19 13:10:20 +02:00
|
|
|
connect(m_buttonBack, SIGNAL(aboutToShowMenu()), this, SLOT(aboutToShowHistoryBackMenu()));
|
|
|
|
|
2011-12-12 18:07:07 +01:00
|
|
|
m_menuForward = new Menu(this);
|
2014-02-10 21:34:46 +01:00
|
|
|
m_menuForward->setCloseOnMiddleClick(true);
|
2014-04-19 13:10:20 +02:00
|
|
|
m_buttonForward->setMenu(m_menuForward);
|
|
|
|
connect(m_buttonForward, SIGNAL(aboutToShowMenu()), this, SLOT(aboutToShowHistoryNextMenu()));
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
m_supMenu = new ToolButton(this);
|
|
|
|
m_supMenu->setObjectName("navigation-button-supermenu");
|
|
|
|
m_supMenu->setPopupMode(QToolButton::InstantPopup);
|
2014-04-19 13:46:23 +02:00
|
|
|
m_supMenu->setToolbarButtonLook(true);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_supMenu->setToolTip(tr("Main Menu"));
|
|
|
|
m_supMenu->setAutoRaise(true);
|
2012-03-04 14:25:52 +01:00
|
|
|
m_supMenu->setFocusPolicy(Qt::NoFocus);
|
2014-02-19 22:07:21 +01:00
|
|
|
m_supMenu->setMenu(m_window->superMenu());
|
2013-03-08 21:01:55 +01:00
|
|
|
m_supMenu->setShowMenuInside(true);
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
m_searchLine = new WebSearchBar(m_window);
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
m_navigationSplitter = new QSplitter(this);
|
2014-02-19 22:07:21 +01:00
|
|
|
m_navigationSplitter->addWidget(m_window->tabWidget()->locationBars());
|
2011-09-11 19:15:06 +02:00
|
|
|
m_navigationSplitter->addWidget(m_searchLine);
|
|
|
|
|
|
|
|
m_navigationSplitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
|
|
|
m_navigationSplitter->setCollapsible(0, false);
|
|
|
|
|
2018-01-04 20:34:10 +01:00
|
|
|
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"));
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2013-02-09 14:08:12 +01:00
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
|
|
|
|
2011-10-29 23:01:17 +02:00
|
|
|
connect(m_buttonBack, SIGNAL(clicked()), this, SLOT(goBack()));
|
2011-12-12 18:30:08 +01:00
|
|
|
connect(m_buttonBack, SIGNAL(middleMouseClicked()), this, SLOT(goBackInNewTab()));
|
2012-02-08 14:40:21 +01:00
|
|
|
connect(m_buttonBack, SIGNAL(controlClicked()), this, SLOT(goBackInNewTab()));
|
2014-04-19 13:10:20 +02:00
|
|
|
connect(m_buttonForward, SIGNAL(clicked()), this, SLOT(goForward()));
|
|
|
|
connect(m_buttonForward, SIGNAL(middleMouseClicked()), this, SLOT(goForwardInNewTab()));
|
|
|
|
connect(m_buttonForward, SIGNAL(controlClicked()), this, SLOT(goForwardInNewTab()));
|
2011-12-12 18:30:08 +01:00
|
|
|
|
2014-04-19 13:10:20 +02:00
|
|
|
connect(m_reloadStop, SIGNAL(stopClicked()), this, SLOT(stop()));
|
|
|
|
connect(m_reloadStop, SIGNAL(reloadClicked()), this, SLOT(reload()));
|
2018-01-04 20:34:10 +01:00
|
|
|
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()));
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
|
|
|
|
2011-10-17 09:57:07 +02:00
|
|
|
void NavigationBar::setSplitterSizes(int locationBar, int websearchBar)
|
|
|
|
{
|
|
|
|
QList<int> sizes;
|
|
|
|
|
|
|
|
if (locationBar == 0) {
|
|
|
|
int splitterWidth = m_navigationSplitter->width();
|
|
|
|
sizes << (int)((double)splitterWidth * .80) << (int)((double)splitterWidth * .20);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 09:57:07 +02:00
|
|
|
sizes << locationBar << websearchBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_navigationSplitter->setSizes(sizes);
|
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
void NavigationBar::showReloadButton()
|
|
|
|
{
|
|
|
|
m_reloadStop->showReloadButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::showStopButton()
|
|
|
|
{
|
|
|
|
m_reloadStop->showStopButton();
|
|
|
|
}
|
|
|
|
|
2013-03-08 21:01:55 +01:00
|
|
|
void NavigationBar::setSuperMenuVisible(bool visible)
|
|
|
|
{
|
|
|
|
m_supMenu->setVisible(visible);
|
|
|
|
}
|
|
|
|
|
2013-04-27 13:51:08 +02:00
|
|
|
int NavigationBar::layoutMargin() const
|
|
|
|
{
|
|
|
|
return m_layout->margin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::setLayoutMargin(int margin)
|
|
|
|
{
|
|
|
|
m_layout->setMargin(margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
int NavigationBar::layoutSpacing() const
|
|
|
|
{
|
|
|
|
return m_layout->spacing();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::setLayoutSpacing(int spacing)
|
|
|
|
{
|
|
|
|
m_layout->setSpacing(spacing);
|
|
|
|
}
|
|
|
|
|
2018-01-04 20:34:10 +01:00
|
|
|
void NavigationBar::addWidget(QWidget *widget, const QString &id)
|
|
|
|
{
|
|
|
|
m_widgets[id] = widget;
|
|
|
|
reloadLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::removeWidget(const QString &id)
|
|
|
|
{
|
|
|
|
m_widgets.remove(id);
|
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
void NavigationBar::aboutToShowHistoryBackMenu()
|
|
|
|
{
|
2014-02-19 22:07:21 +01:00
|
|
|
if (!m_menuBack || !m_window->weView()) {
|
2011-09-11 19:15:06 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
m_menuBack->clear();
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->history();
|
2011-10-29 23:01:17 +02:00
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
int curindex = history->currentItemIndex();
|
|
|
|
int count = 0;
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
for (int i = curindex - 1; i >= 0; i--) {
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistoryItem item = history->itemAt(i);
|
2013-03-13 11:54:58 +01:00
|
|
|
if (item.isValid()) {
|
2011-12-16 19:07:36 +01:00
|
|
|
QString title = titleForUrl(item.title(), item.url());
|
2011-12-12 18:07:07 +01:00
|
|
|
|
2014-03-07 18:03:42 +01:00
|
|
|
const QIcon icon = iconForPage(item.url(), IconProvider::standardIcon(QStyle::SP_ArrowBack));
|
2012-04-01 10:48:50 +02:00
|
|
|
Action* act = new Action(icon, title);
|
2011-12-12 18:07:07 +01:00
|
|
|
act->setData(i);
|
2014-03-20 09:11:19 +01:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(loadHistoryIndex()));
|
|
|
|
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(loadHistoryIndexInNewTab()));
|
2011-12-12 18:07:07 +01:00
|
|
|
m_menuBack->addAction(act);
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
2011-10-29 23:01:17 +02:00
|
|
|
|
|
|
|
count++;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (count == 20) {
|
2011-09-11 19:15:06 +02:00
|
|
|
break;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
2011-10-29 23:01:17 +02:00
|
|
|
|
|
|
|
m_menuBack->addSeparator();
|
|
|
|
m_menuBack->addAction(tr("Clear history"), this, SLOT(clearHistory()));
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::aboutToShowHistoryNextMenu()
|
|
|
|
{
|
2014-02-19 22:07:21 +01:00
|
|
|
if (!m_menuForward || !m_window->weView()) {
|
2011-09-11 19:15:06 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
m_menuForward->clear();
|
2011-10-29 23:01:17 +02:00
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->history();
|
2011-09-11 19:15:06 +02:00
|
|
|
int curindex = history->currentItemIndex();
|
|
|
|
int count = 0;
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
for (int i = curindex + 1; i < history->count(); i++) {
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistoryItem item = history->itemAt(i);
|
2013-03-13 11:54:58 +01:00
|
|
|
if (item.isValid()) {
|
2011-12-16 19:07:36 +01:00
|
|
|
QString title = titleForUrl(item.title(), item.url());
|
2011-12-12 18:07:07 +01:00
|
|
|
|
2014-03-07 18:03:42 +01:00
|
|
|
const QIcon icon = iconForPage(item.url(), IconProvider::standardIcon(QStyle::SP_ArrowForward));
|
2012-04-01 10:48:50 +02:00
|
|
|
Action* act = new Action(icon, title);
|
2011-12-12 18:07:07 +01:00
|
|
|
act->setData(i);
|
2014-03-20 09:11:19 +01:00
|
|
|
connect(act, SIGNAL(triggered()), this, SLOT(loadHistoryIndex()));
|
|
|
|
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(loadHistoryIndexInNewTab()));
|
2011-12-12 18:07:07 +01:00
|
|
|
m_menuForward->addAction(act);
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
2011-10-29 23:01:17 +02:00
|
|
|
|
|
|
|
count++;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (count == 20) {
|
2011-09-11 19:15:06 +02:00
|
|
|
break;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
2011-10-29 23:01:17 +02:00
|
|
|
|
|
|
|
m_menuForward->addSeparator();
|
|
|
|
m_menuForward->addAction(tr("Clear history"), this, SLOT(clearHistory()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::clearHistory()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->page()->history();
|
2011-10-29 23:01:17 +02:00
|
|
|
history->clear();
|
|
|
|
refreshHistory();
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
|
|
|
|
2013-02-09 14:08:12 +01:00
|
|
|
void NavigationBar::contextMenuRequested(const QPoint &pos)
|
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
QMenu menu;
|
|
|
|
m_window->createToolbarsMenu(&menu);
|
|
|
|
menu.exec(mapToGlobal(pos));
|
2013-02-09 14:08:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 20:34:10 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-03-20 09:11:19 +01:00
|
|
|
void NavigationBar::loadHistoryIndex()
|
2011-09-11 19:15:06 +02:00
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->page()->history();
|
2011-12-12 18:07:07 +01:00
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2014-03-20 09:11:19 +01:00
|
|
|
loadHistoryItem(history->itemAt(action->data().toInt()));
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 09:11:19 +01:00
|
|
|
void NavigationBar::loadHistoryIndexInNewTab(int index)
|
2011-12-12 18:07:07 +01:00
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2011-12-12 18:30:08 +01:00
|
|
|
index = action->data().toInt();
|
|
|
|
}
|
2011-12-12 18:07:07 +01:00
|
|
|
|
2011-12-12 18:30:08 +01:00
|
|
|
if (index == -1) {
|
|
|
|
return;
|
2011-12-12 18:07:07 +01:00
|
|
|
}
|
2011-12-12 18:30:08 +01:00
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->page()->history();
|
2014-03-20 09:11:19 +01:00
|
|
|
loadHistoryItemInNewTab(history->itemAt(index));
|
2011-12-12 18:07:07 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
void NavigationBar::refreshHistory()
|
|
|
|
{
|
2014-03-13 17:06:08 +01:00
|
|
|
if (mApp->isClosing() || !m_window->weView()) {
|
2011-09-11 19:15:06 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->page()->history();
|
2012-04-04 13:21:53 +02:00
|
|
|
m_buttonBack->setEnabled(history->canGoBack());
|
2014-04-19 13:10:20 +02:00
|
|
|
m_buttonForward->setEnabled(history->canGoForward());
|
2011-10-29 23:01:17 +02:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
void NavigationBar::stop()
|
|
|
|
{
|
|
|
|
m_window->action(QSL("View/Stop"))->trigger();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::reload()
|
|
|
|
{
|
|
|
|
m_window->action(QSL("View/Reload"))->trigger();
|
|
|
|
}
|
|
|
|
|
2011-10-29 23:01:17 +02:00
|
|
|
void NavigationBar::goBack()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->page()->history();
|
2012-04-04 13:21:53 +02:00
|
|
|
history->back();
|
2011-12-12 18:30:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::goBackInNewTab()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->page()->history();
|
2011-12-12 18:30:08 +01:00
|
|
|
|
2012-04-04 13:21:53 +02:00
|
|
|
if (!history->canGoBack()) {
|
2011-12-12 18:30:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-20 09:11:19 +01:00
|
|
|
loadHistoryItemInNewTab(history->backItem());
|
2011-10-29 23:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::goForward()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->page()->history();
|
2012-04-04 13:21:53 +02:00
|
|
|
history->forward();
|
2011-12-12 18:30:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NavigationBar::goForwardInNewTab()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView()->page()->history();
|
2011-12-12 18:30:08 +01:00
|
|
|
|
2012-04-04 13:21:53 +02:00
|
|
|
if (!history->canGoForward()) {
|
2011-12-12 18:30:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-20 09:11:19 +01:00
|
|
|
loadHistoryItemInNewTab(history->forwardItem());
|
|
|
|
}
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
void NavigationBar::loadHistoryItem(const QWebEngineHistoryItem &item)
|
2014-03-20 09:11:19 +01:00
|
|
|
{
|
|
|
|
m_window->weView()->page()->history()->goToItem(item);
|
|
|
|
|
|
|
|
refreshHistory();
|
|
|
|
}
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
void NavigationBar::loadHistoryItemInNewTab(const QWebEngineHistoryItem &item)
|
2014-03-20 09:11:19 +01:00
|
|
|
{
|
|
|
|
TabWidget* tabWidget = m_window->tabWidget();
|
|
|
|
int tabIndex = tabWidget->duplicateTab(tabWidget->currentIndex());
|
|
|
|
|
2015-01-27 11:01:52 +01:00
|
|
|
QWebEngineHistory* history = m_window->weView(tabIndex)->page()->history();
|
2014-03-20 09:11:19 +01:00
|
|
|
history->goToItem(item);
|
|
|
|
|
|
|
|
if (qzSettings->newTabPosition == Qz::NT_SelectedTab) {
|
|
|
|
tabWidget->setCurrentIndex(tabIndex);
|
2011-12-12 18:30:08 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|