File indexing completed on 2024-05-12 04:58:09

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "navigationbar.h"
0019 #include "toolbutton.h"
0020 #include "browserwindow.h"
0021 #include "mainapplication.h"
0022 #include "iconprovider.h"
0023 #include "websearchbar.h"
0024 #include "reloadstopbutton.h"
0025 #include "enhancedmenu.h"
0026 #include "tabwidget.h"
0027 #include "tabbedwebview.h"
0028 #include "webpage.h"
0029 #include "qzsettings.h"
0030 #include "qztools.h"
0031 #include "abstractbuttoninterface.h"
0032 #include "navigationbartoolbutton.h"
0033 #include "navigationbarconfigdialog.h"
0034 
0035 #include <QTimer>
0036 #include <QSplitter>
0037 #include <QHBoxLayout>
0038 #include <QStackedWidget>
0039 #include <QWebEngineHistory>
0040 #include <QMouseEvent>
0041 #include <QStyleOption>
0042 
0043 static QString titleForUrl(QString title, const QUrl &url)
0044 {
0045     if (title.isEmpty()) {
0046         title = url.toString(QUrl::RemoveFragment);
0047     }
0048     if (title.isEmpty()) {
0049         return NavigationBar::tr("Empty Page");
0050     }
0051     return QzTools::truncatedText(title, 40);
0052 }
0053 
0054 static QIcon iconForPage(const QUrl &url, const QIcon &sIcon)
0055 {
0056     QIcon icon;
0057     icon.addPixmap(IconProvider::iconForUrl(url).pixmap(16));
0058     icon.addPixmap(sIcon.pixmap(16), QIcon::Active);
0059     return icon;
0060 }
0061 
0062 NavigationBar::NavigationBar(BrowserWindow* window)
0063     : QWidget(window)
0064     , m_window(window)
0065 {
0066     setObjectName(QSL("navigationbar"));
0067 
0068     m_layout = new QHBoxLayout(this);
0069     auto contentsMargin = style()->pixelMetric(QStyle::PM_ToolBarItemMargin, nullptr, this)
0070                         + style()->pixelMetric(QStyle::PM_ToolBarFrameWidth, nullptr, this);
0071     m_layout->setContentsMargins(contentsMargin, contentsMargin, contentsMargin, contentsMargin);
0072     m_layout->setSpacing(style()->pixelMetric(QStyle::PM_ToolBarItemSpacing, nullptr, this));
0073     setLayout(m_layout);
0074 
0075     m_buttonBack = new ToolButton(this);
0076     m_buttonBack->setObjectName("navigation-button-back");
0077     m_buttonBack->setToolTip(tr("Back"));
0078     m_buttonBack->setToolButtonStyle(Qt::ToolButtonIconOnly);
0079     m_buttonBack->setToolbarButtonLook(true);
0080     m_buttonBack->setShowMenuOnRightClick(true);
0081     m_buttonBack->setAutoRaise(true);
0082     m_buttonBack->setEnabled(false);
0083     m_buttonBack->setFocusPolicy(Qt::NoFocus);
0084 
0085     m_buttonForward = new ToolButton(this);
0086     m_buttonForward->setObjectName("navigation-button-next");
0087     m_buttonForward->setToolTip(tr("Forward"));
0088     m_buttonForward->setToolButtonStyle(Qt::ToolButtonIconOnly);
0089     m_buttonForward->setToolbarButtonLook(true);
0090     m_buttonForward->setShowMenuOnRightClick(true);
0091     m_buttonForward->setAutoRaise(true);
0092     m_buttonForward->setEnabled(false);
0093     m_buttonForward->setFocusPolicy(Qt::NoFocus);
0094 
0095     auto* backNextLayout = new QHBoxLayout();
0096     backNextLayout->setContentsMargins(0, 0, 0, 0);
0097     backNextLayout->setSpacing(0);
0098     backNextLayout->addWidget(m_buttonBack);
0099     backNextLayout->addWidget(m_buttonForward);
0100     auto *backNextWidget = new QWidget(this);
0101     backNextWidget->setLayout(backNextLayout);
0102 
0103     m_reloadStop = new ReloadStopButton(this);
0104 
0105     auto *buttonHome = new ToolButton(this);
0106     buttonHome->setObjectName("navigation-button-home");
0107     buttonHome->setToolTip(tr("Home"));
0108     buttonHome->setToolButtonStyle(Qt::ToolButtonIconOnly);
0109     buttonHome->setToolbarButtonLook(true);
0110     buttonHome->setAutoRaise(true);
0111     buttonHome->setFocusPolicy(Qt::NoFocus);
0112 
0113     auto *buttonAddTab = new ToolButton(this);
0114     buttonAddTab->setObjectName("navigation-button-addtab");
0115     buttonAddTab->setToolTip(tr("New Tab"));
0116     buttonAddTab->setToolButtonStyle(Qt::ToolButtonIconOnly);
0117     buttonAddTab->setToolbarButtonLook(true);
0118     buttonAddTab->setAutoRaise(true);
0119     buttonAddTab->setFocusPolicy(Qt::NoFocus);
0120 
0121     m_menuBack = new Menu(this);
0122     m_menuBack->setCloseOnMiddleClick(true);
0123     m_buttonBack->setMenu(m_menuBack);
0124     connect(m_buttonBack, &ToolButton::aboutToShowMenu, this, &NavigationBar::aboutToShowHistoryBackMenu);
0125 
0126     m_menuForward = new Menu(this);
0127     m_menuForward->setCloseOnMiddleClick(true);
0128     m_buttonForward->setMenu(m_menuForward);
0129     connect(m_buttonForward, &ToolButton::aboutToShowMenu, this, &NavigationBar::aboutToShowHistoryNextMenu);
0130 
0131     auto *buttonTools = new ToolButton(this);
0132     buttonTools->setObjectName("navigation-button-tools");
0133     buttonTools->setPopupMode(QToolButton::InstantPopup);
0134     buttonTools->setToolbarButtonLook(true);
0135     buttonTools->setToolTip(tr("Tools"));
0136     buttonTools->setAutoRaise(true);
0137     buttonTools->setFocusPolicy(Qt::NoFocus);
0138     buttonTools->setShowMenuInside(true);
0139 
0140     m_menuTools = new Menu(this);
0141     buttonTools->setMenu(m_menuTools);
0142     connect(buttonTools, &ToolButton::aboutToShowMenu, this, &NavigationBar::aboutToShowToolsMenu);
0143 
0144     m_supMenu = new ToolButton(this);
0145     m_supMenu->setObjectName("navigation-button-supermenu");
0146     m_supMenu->setPopupMode(QToolButton::InstantPopup);
0147     m_supMenu->setToolbarButtonLook(true);
0148     m_supMenu->setToolTip(tr("Main Menu"));
0149     m_supMenu->setAutoRaise(true);
0150     m_supMenu->setFocusPolicy(Qt::NoFocus);
0151     m_supMenu->setMenu(m_window->superMenu());
0152     m_supMenu->setShowMenuInside(true);
0153 
0154     m_searchLine = new WebSearchBar(m_window);
0155 
0156     m_navigationSplitter = new QSplitter(this);
0157     m_navigationSplitter->addWidget(m_window->tabWidget()->locationBars());
0158     m_navigationSplitter->addWidget(m_searchLine);
0159 
0160     m_navigationSplitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
0161     m_navigationSplitter->setCollapsible(0, false);
0162 
0163     m_exitFullscreen = new ToolButton(this);
0164     m_exitFullscreen->setObjectName("navigation-button-exitfullscreen");
0165     m_exitFullscreen->setToolTip(tr("Exit Fullscreen"));
0166     m_exitFullscreen->setToolButtonStyle(Qt::ToolButtonIconOnly);
0167     m_exitFullscreen->setToolbarButtonLook(true);
0168     m_exitFullscreen->setFocusPolicy(Qt::NoFocus);
0169     m_exitFullscreen->setAutoRaise(true);
0170     m_exitFullscreen->setVisible(false);
0171 
0172     setContextMenuPolicy(Qt::CustomContextMenu);
0173     connect(this, &QWidget::customContextMenuRequested, this, &NavigationBar::contextMenuRequested);
0174 
0175     connect(m_buttonBack, &QAbstractButton::clicked, this, &NavigationBar::goBack);
0176     connect(m_buttonBack, &ToolButton::middleMouseClicked, this, &NavigationBar::goBackInNewTab);
0177     connect(m_buttonBack, &ToolButton::controlClicked, this, &NavigationBar::goBackInNewTab);
0178     connect(m_buttonForward, &QAbstractButton::clicked, this, &NavigationBar::goForward);
0179     connect(m_buttonForward, &ToolButton::middleMouseClicked, this, &NavigationBar::goForwardInNewTab);
0180     connect(m_buttonForward, &ToolButton::controlClicked, this, &NavigationBar::goForwardInNewTab);
0181 
0182     connect(m_reloadStop, &ReloadStopButton::stopClicked, this, &NavigationBar::stop);
0183     connect(m_reloadStop, &ReloadStopButton::reloadClicked, this, &NavigationBar::reload);
0184     connect(buttonHome, &QAbstractButton::clicked, m_window, &BrowserWindow::goHome);
0185     connect(buttonHome, &ToolButton::middleMouseClicked, m_window, &BrowserWindow::goHomeInNewTab);
0186     connect(buttonHome, &ToolButton::controlClicked, m_window, &BrowserWindow::goHomeInNewTab);
0187     connect(buttonAddTab, &QAbstractButton::clicked, m_window, &BrowserWindow::addTab);
0188     connect(buttonAddTab, &ToolButton::middleMouseClicked, m_window->tabWidget(), &TabWidget::addTabFromClipboard);
0189     connect(m_exitFullscreen, &QAbstractButton::clicked, m_window, &BrowserWindow::toggleFullScreen);
0190 
0191     addWidget(backNextWidget, QSL("button-backforward"), tr("Back and Forward buttons"));
0192     addWidget(m_reloadStop, QSL("button-reloadstop"), tr("Reload button"));
0193     addWidget(buttonHome, QSL("button-home"), tr("Home button"));
0194     addWidget(buttonAddTab, QSL("button-addtab"), tr("Add tab button"));
0195     addWidget(m_navigationSplitter, QSL("locationbar"), tr("Address and Search bar"));
0196     addWidget(buttonTools, QSL("button-tools"), tr("Tools button"));
0197     addWidget(m_exitFullscreen, QSL("button-exitfullscreen"), tr("Exit Fullscreen button"));
0198 
0199     loadSettings();
0200 }
0201 
0202 NavigationBar::~NavigationBar()
0203 {
0204     setCurrentView(nullptr);
0205 }
0206 
0207 void NavigationBar::setSplitterSizes(int locationBar, int websearchBar)
0208 {
0209     QList<int> sizes;
0210 
0211     if (locationBar == 0) {
0212         int splitterWidth = m_navigationSplitter->width();
0213         sizes << (int)((double)splitterWidth * .80) << (int)((double)splitterWidth * .20);
0214     }
0215     else {
0216         sizes << locationBar << websearchBar;
0217     }
0218 
0219     m_navigationSplitter->setSizes(sizes);
0220 }
0221 
0222 void NavigationBar::setCurrentView(TabbedWebView *view)
0223 {
0224     for (const WidgetData &data : std::as_const(m_widgets)) {
0225         if (data.button) {
0226             data.button->setWebView(view);
0227         }
0228     }
0229 
0230     if (!view) {
0231         return;
0232     }
0233 
0234     auto connectPageActions = [this](QWebEnginePage *page) {
0235         auto updateButton = [](ToolButton *button, QAction *action) {
0236             button->setEnabled(action->isEnabled());
0237         };
0238         auto updateBackButton = std::bind(updateButton, m_buttonBack, page->action(QWebEnginePage::Back));
0239         auto updateForwardButton = std::bind(updateButton, m_buttonForward, page->action(QWebEnginePage::Forward));
0240 
0241         updateBackButton();
0242         updateForwardButton();
0243 
0244         disconnect(m_backConnection);
0245         disconnect(m_forwardConnection);
0246         m_backConnection = connect(page->action(QWebEnginePage::Back), &QAction::changed, this, updateBackButton);
0247         m_forwardConnection = connect(page->action(QWebEnginePage::Forward), &QAction::changed, this, updateForwardButton);
0248     };
0249 
0250     connectPageActions(view->page());
0251     connect(view, &TabbedWebView::pageChanged, this, connectPageActions);
0252 }
0253 
0254 void NavigationBar::showReloadButton()
0255 {
0256     m_reloadStop->showReloadButton();
0257 }
0258 
0259 void NavigationBar::showStopButton()
0260 {
0261     m_reloadStop->showStopButton();
0262 }
0263 
0264 void NavigationBar::enterFullScreen()
0265 {
0266     if (m_layout->indexOf(m_exitFullscreen) != -1) {
0267         m_exitFullscreen->show();
0268     }
0269 }
0270 
0271 void NavigationBar::leaveFullScreen()
0272 {
0273     if (m_layout->indexOf(m_exitFullscreen) != -1) {
0274         m_exitFullscreen->hide();
0275     }
0276 }
0277 
0278 void NavigationBar::setSuperMenuVisible(bool visible)
0279 {
0280     m_supMenu->setVisible(visible);
0281 }
0282 
0283 int NavigationBar::layoutMargin() const
0284 {
0285     // NOTE: This assumes margins are always the same.
0286     return m_layout->contentsMargins().left();
0287 }
0288 
0289 void NavigationBar::setLayoutMargin(int margin)
0290 {
0291     m_layout->setContentsMargins(margin, margin, margin, margin);
0292 }
0293 
0294 int NavigationBar::layoutSpacing() const
0295 {
0296     return m_layout->spacing();
0297 }
0298 
0299 void NavigationBar::setLayoutSpacing(int spacing)
0300 {
0301     m_layout->setSpacing(spacing);
0302 }
0303 
0304 void NavigationBar::addWidget(QWidget *widget, const QString &id, const QString &name)
0305 {
0306     if (!widget || id.isEmpty() || name.isEmpty()) {
0307         return;
0308     }
0309 
0310     WidgetData data;
0311     data.id = id;
0312     data.name = name;
0313     data.widget = widget;
0314     m_widgets[id] = data;
0315 
0316     reloadLayout();
0317 }
0318 
0319 void NavigationBar::removeWidget(const QString &id)
0320 {
0321     if (!m_widgets.contains(id)) {
0322         return;
0323     }
0324 
0325     m_widgets.remove(id);
0326     reloadLayout();
0327 }
0328 
0329 void NavigationBar::addToolButton(AbstractButtonInterface *button)
0330 {
0331     if (!button || !button->isValid()) {
0332         return;
0333     }
0334 
0335     auto *toolButton = new NavigationBarToolButton(button, this);
0336     toolButton->setProperty("button-id", button->id());
0337     connect(toolButton, &NavigationBarToolButton::visibilityChangeRequested, this, [=]() {
0338         if (m_layout->indexOf(toolButton) != -1) {
0339             toolButton->updateVisibility();
0340         }
0341     });
0342 
0343     WidgetData data;
0344     data.id = button->id();
0345     data.name = button->name();
0346     data.widget = toolButton;
0347     data.button = button;
0348     m_widgets[data.id] = data;
0349 
0350     data.button->setWebView(m_window->weView());
0351 
0352     reloadLayout();
0353 }
0354 
0355 void NavigationBar::removeToolButton(AbstractButtonInterface *button)
0356 {
0357     if (!button || !m_widgets.contains(button->id())) {
0358         return;
0359     }
0360 
0361     delete m_widgets.take(button->id()).widget;
0362 }
0363 
0364 void NavigationBar::aboutToShowHistoryBackMenu()
0365 {
0366     if (!m_menuBack || !m_window->weView()) {
0367         return;
0368     }
0369     m_menuBack->clear();
0370     QWebEngineHistory* history = m_window->weView()->history();
0371 
0372     int curindex = history->currentItemIndex();
0373     int count = 0;
0374 
0375     for (int i = curindex - 1; i >= 0; i--) {
0376         QWebEngineHistoryItem item = history->itemAt(i);
0377         if (item.isValid()) {
0378             QString title = titleForUrl(item.title(), item.url());
0379 
0380             const QIcon icon = iconForPage(item.url(), IconProvider::standardIcon(QStyle::SP_ArrowBack));
0381             auto* act = new Action(icon, title);
0382             act->setData(i);
0383             connect(act, &QAction::triggered, this, &NavigationBar::loadHistoryIndex);
0384             connect(act, SIGNAL(ctrlTriggered()), this, SLOT(loadHistoryIndexInNewTab()));
0385             m_menuBack->addAction(act);
0386         }
0387 
0388         count++;
0389         if (count == 20) {
0390             break;
0391         }
0392     }
0393 
0394     m_menuBack->addSeparator();
0395     m_menuBack->addAction(QIcon::fromTheme(QSL("edit-clear")), tr("Clear history"), this, &NavigationBar::clearHistory);
0396 }
0397 
0398 void NavigationBar::aboutToShowHistoryNextMenu()
0399 {
0400     if (!m_menuForward || !m_window->weView()) {
0401         return;
0402     }
0403     m_menuForward->clear();
0404 
0405     QWebEngineHistory* history = m_window->weView()->history();
0406     int curindex = history->currentItemIndex();
0407     int count = 0;
0408 
0409     for (int i = curindex + 1; i < history->count(); i++) {
0410         QWebEngineHistoryItem item = history->itemAt(i);
0411         if (item.isValid()) {
0412             QString title = titleForUrl(item.title(), item.url());
0413 
0414             const QIcon icon = iconForPage(item.url(), IconProvider::standardIcon(QStyle::SP_ArrowForward));
0415             auto* act = new Action(icon, title);
0416             act->setData(i);
0417             connect(act, &QAction::triggered, this, &NavigationBar::loadHistoryIndex);
0418             connect(act, SIGNAL(ctrlTriggered()), this, SLOT(loadHistoryIndexInNewTab()));
0419             m_menuForward->addAction(act);
0420         }
0421 
0422         count++;
0423         if (count == 20) {
0424             break;
0425         }
0426     }
0427 
0428     m_menuForward->addSeparator();
0429     m_menuForward->addAction(QIcon::fromTheme(QSL("edit-clear")), tr("Clear history"), this, &NavigationBar::clearHistory);
0430 }
0431 
0432 void NavigationBar::aboutToShowToolsMenu()
0433 {
0434     m_menuTools->clear();
0435 
0436     m_window->createToolbarsMenu(m_menuTools->addMenu(tr("Toolbars")));
0437     m_window->createSidebarsMenu(m_menuTools->addMenu(tr("Sidebar")));
0438     m_menuTools->addSeparator();
0439 
0440     for (const WidgetData &data : std::as_const(m_widgets)) {
0441         AbstractButtonInterface *button = data.button;
0442         if (button && (!button->isVisible() || !m_layoutIds.contains(data.id))) {
0443             QString title = button->title();
0444             if (!button->badgeText().isEmpty()) {
0445                 title.append(QSL(" (%1)").arg(button->badgeText()));
0446             }
0447             m_menuTools->addAction(button->icon(), title, this, &NavigationBar::toolActionActivated)->setData(data.id);
0448         }
0449     }
0450 
0451     m_menuTools->addSeparator();
0452     m_menuTools->addAction(IconProvider::settingsIcon(), tr("Configure Toolbar"), this, &NavigationBar::openConfigurationDialog);
0453 }
0454 
0455 void NavigationBar::clearHistory()
0456 {
0457     QWebEngineHistory* history = m_window->weView()->page()->history();
0458     history->clear();
0459 }
0460 
0461 void NavigationBar::contextMenuRequested(const QPoint &pos)
0462 {
0463     QMenu menu;
0464     m_window->createToolbarsMenu(&menu);
0465     menu.addSeparator();
0466     menu.addAction(IconProvider::settingsIcon(), tr("Configure Toolbar"), this, &NavigationBar::openConfigurationDialog);
0467     menu.exec(mapToGlobal(pos));
0468 }
0469 
0470 void NavigationBar::openConfigurationDialog()
0471 {
0472     auto *dialog = new NavigationBarConfigDialog(this);
0473     dialog->show();
0474 }
0475 
0476 void NavigationBar::toolActionActivated()
0477 {
0478     auto *act = qobject_cast<QAction*>(sender());
0479     if (!act) {
0480         return;
0481     }
0482     const QString id = act->data().toString();
0483     if (!m_widgets.contains(id)) {
0484         return;
0485     }
0486     WidgetData data = m_widgets.value(id);
0487     if (!data.button) {
0488         return;
0489     }
0490     auto *buttonTools = qobject_cast<ToolButton*>(m_widgets.value(QSL("button-tools")).widget);
0491     if (!buttonTools) {
0492         return;
0493     }
0494 
0495     auto *c = new AbstractButtonInterface::ClickController;
0496     c->visualParent = buttonTools;
0497     c->popupPosition = [=](const QSize &size) {
0498         QPoint pos = buttonTools->mapToGlobal(buttonTools->rect().bottomRight());
0499         if (QApplication::isRightToLeft()) {
0500             pos.setX(pos.x() - buttonTools->rect().width());
0501         } else {
0502             pos.setX(pos.x() - size.width());
0503         }
0504         c->popupOpened = true;
0505         return pos;
0506     };
0507     c->popupClosed = [=]() {
0508         buttonTools->setDown(false);
0509         delete c;
0510     };
0511     Q_EMIT data.button->clicked(c);
0512     if (c->popupOpened) {
0513         buttonTools->setDown(true);
0514     } else {
0515         c->popupClosed();
0516     }
0517 }
0518 
0519 void NavigationBar::loadSettings()
0520 {
0521     const QStringList defaultIds = {
0522         QSL("button-backforward"),
0523         QSL("button-reloadstop"),
0524         QSL("button-home"),
0525         QSL("locationbar"),
0526         QSL("button-downloads"),
0527         QSL("adblock-icon"),
0528         QSL("button-tools")
0529     };
0530 
0531     Settings settings;
0532     settings.beginGroup(QSL("NavigationBar"));
0533     m_layoutIds = settings.value(QSL("Layout"), defaultIds).toStringList();
0534     m_searchLine->setVisible(settings.value(QSL("ShowSearchBar"), true).toBool());
0535     settings.endGroup();
0536 
0537     m_layoutIds.removeDuplicates();
0538     m_layoutIds.removeAll(QString());
0539     if (!m_layoutIds.contains(QSL("locationbar"))) {
0540         m_layoutIds.append(QSL("locationbar"));
0541     }
0542 
0543     reloadLayout();
0544 }
0545 
0546 void NavigationBar::reloadLayout()
0547 {
0548     if (m_widgets.isEmpty()) {
0549         return;
0550     }
0551 
0552     setUpdatesEnabled(false);
0553 
0554     // Clear layout
0555     while (m_layout->count() != 0) {
0556         QLayoutItem *item = m_layout->takeAt(0);
0557         if (!item) {
0558             continue;
0559         }
0560         QWidget *widget = item->widget();
0561         if (!widget) {
0562             continue;
0563         }
0564         widget->setParent(nullptr);
0565     }
0566 
0567     // Hide all widgets
0568     for (const WidgetData &data : m_widgets) {
0569         data.widget->hide();
0570     }
0571 
0572     // Add widgets to layout
0573     for (const QString &id : std::as_const(m_layoutIds)) {
0574         const WidgetData data = m_widgets.value(id);
0575         if (data.widget) {
0576             m_layout->addWidget(data.widget);
0577             auto *button = qobject_cast<NavigationBarToolButton*>(data.widget);
0578             if (button) {
0579                 button->updateVisibility();
0580             } else {
0581                 data.widget->show();
0582             }
0583         }
0584     }
0585 
0586     m_layout->addWidget(m_supMenu);
0587 
0588     // Make sure search bar is visible
0589     if (m_searchLine->isVisible() && m_navigationSplitter->sizes().at(1) == 0) {
0590         const int locationBarSize = m_navigationSplitter->sizes().at(0);
0591         setSplitterSizes(locationBarSize - 50, 50);
0592     }
0593 
0594     if (m_window->isFullScreen()) {
0595         enterFullScreen();
0596     } else {
0597         leaveFullScreen();
0598     }
0599 
0600     setUpdatesEnabled(true);
0601 }
0602 
0603 void NavigationBar::loadHistoryIndex()
0604 {
0605     QWebEngineHistory* history = m_window->weView()->page()->history();
0606 
0607     if (auto* action = qobject_cast<QAction*>(sender())) {
0608         loadHistoryItem(history->itemAt(action->data().toInt()));
0609     }
0610 }
0611 
0612 void NavigationBar::loadHistoryIndexInNewTab(int index)
0613 {
0614     if (auto* action = qobject_cast<QAction*>(sender())) {
0615         index = action->data().toInt();
0616     }
0617 
0618     if (index == -1) {
0619         return;
0620     }
0621 
0622     QWebEngineHistory* history = m_window->weView()->page()->history();
0623     loadHistoryItemInNewTab(history->itemAt(index));
0624 }
0625 
0626 void NavigationBar::stop()
0627 {
0628     m_window->action(QSL("View/Stop"))->trigger();
0629 }
0630 
0631 void NavigationBar::reload()
0632 {
0633     m_window->action(QSL("View/Reload"))->trigger();
0634 }
0635 
0636 void NavigationBar::goBack()
0637 {
0638     auto view = m_window->weView();
0639     view->setFocus();
0640     view->back();
0641 }
0642 
0643 void NavigationBar::goBackInNewTab()
0644 {
0645     QWebEngineHistory* history = m_window->weView()->page()->history();
0646 
0647     if (!history->canGoBack()) {
0648         return;
0649     }
0650 
0651     loadHistoryItemInNewTab(history->backItem());
0652 }
0653 
0654 void NavigationBar::goForward()
0655 {
0656     auto view = m_window->weView();
0657     view->setFocus();
0658     view->forward();
0659 }
0660 
0661 void NavigationBar::goForwardInNewTab()
0662 {
0663     QWebEngineHistory* history = m_window->weView()->page()->history();
0664 
0665     if (!history->canGoForward()) {
0666         return;
0667     }
0668 
0669     loadHistoryItemInNewTab(history->forwardItem());
0670 }
0671 
0672 void NavigationBar::loadHistoryItem(const QWebEngineHistoryItem &item)
0673 {
0674     m_window->weView()->page()->history()->goToItem(item);
0675 }
0676 
0677 void NavigationBar::loadHistoryItemInNewTab(const QWebEngineHistoryItem &item)
0678 {
0679     TabWidget* tabWidget = m_window->tabWidget();
0680     int tabIndex = tabWidget->duplicateTab(tabWidget->currentIndex());
0681 
0682     QWebEngineHistory* history = m_window->weView(tabIndex)->page()->history();
0683     history->goToItem(item);
0684 
0685     if (qzSettings->newTabPosition == Qz::NT_SelectedTab) {
0686         tabWidget->setCurrentIndex(tabIndex);
0687     }
0688 
0689 }