summaryrefslogtreecommitdiff
path: root/src/panels/navigationtoolbar.cpp
blob: 950efaadfc0240750672bb8a1ac1aba42f4200c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* ============================================================
 *     The rekonq project
 * ============================================================
 * SPDX-License-Identifier: GPL-3.0-only
 * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
 * ============================================================ */

#include "navigationtoolbar.hpp"

NavigationToolBar::NavigationToolBar(QWidget *parent) : QToolBar(parent), urlBar(new UrlBar(this))
{
  auto *backAction = addAction(QIcon::fromTheme("go-previous"), "Back", this, [this]() { m_view->back(); });
  backAction->setObjectName("actionBack");
  auto *forwardAction = addAction(QIcon::fromTheme("go-next"), "Forward", this, [this]() { m_view->forward(); });
  forwardAction->setObjectName("actionForward");
  auto *refreshAction = addAction(QIcon::fromTheme("view-refresh"), "Refresh", this, [this]() { m_view->refresh(); });
  refreshAction->setObjectName("actionRefresh");
  addAction(QIcon::fromTheme("go-home"), "Home", this,
            [this]() { emit loadUrl(rekonq::HomePage, rekonq::CurrentTab); });
  // TODO homeAction->setObjectName("actionHome");

  addWidget(urlBar);
  connect(urlBar, &QLineEdit::returnPressed, this,
          [this]() { emit loadRequestedUrl(QUrl::fromUserInput(urlBar->text()), rekonq::CurrentTab); });

  auto *actionFocusUrlBar = new QAction(parent);
  actionFocusUrlBar->setShortcut({"F6"});
  connect(actionFocusUrlBar, &QAction::triggered, urlBar, [this]() {
    urlBar->setFocus();
    urlBar->selectAll();
  });
  parent->addAction(actionFocusUrlBar);
}

void NavigationToolBar::setCurrentView(RekonqView *view)
{
  Q_CHECK_PTR(view);
  m_view = view;

  disconnect(urlChanged_conn);
  disconnect(loadStarted_conn);
  disconnect(loadProgress_conn);
  disconnect(loadFinished_conn);

  urlChanged_conn = connect(view, &RekonqView::urlChanged, urlBar, &UrlBar::setUrl);
  loadStarted_conn = connect(view, &RekonqView::loadStarted, urlBar, &UrlBar::loadStarted);
  loadProgress_conn = connect(view, &RekonqView::loadProgress, urlBar, &UrlBar::loadProgress);
  loadFinished_conn = connect(view, &RekonqView::loadFinished, urlBar, &UrlBar::loadFinished);

  urlBar->setCurrentView(view);
}