/* ============================================================ * The rekonq project * ============================================================ * SPDX-License-Identifier: GPL-2.0-or-later * Copyright (C) 2013 by Andrea Diamantini * SPDX-License-Identifier: GPL-3.0-only * Copyright (C) 2022 aqua * ============================================================ * Description: Main Window class * ============================================================ */ #include "rekonqwindow.h" #include "application.hpp" #include "settings/settingsdialog.h" #include "taskmanager.h" #include "ui_rekonqwindow.h" #include RekonqWindow::RekonqWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::RekonqWindow) { ui->setupUi(this); connect(ui->tabs, &QTabBar::currentChanged, this, [this](int index) { auto *view = ui->tabs->view(index); Q_CHECK_PTR(view); ui->views->setCurrentWidget(view); ui->urlBar->setCurrentView(view); }); connect(ui->tabs, &TabBar::removeView, this, [this](RekonqView *view) { ui->views->removeWidget(view); }); // connect actions connect(ui->actionSettings, &QAction::triggered, this, [this]() { (new SettingsDialog(Application::instance()->settings(), this))->show(); }); connect(ui->actionTaskManager, &QAction::triggered, this, [this]() { (new TaskManager(this))->show(); }); connect(ui->newTab, &QToolButton::clicked, this, [this]() { Application::instance()->newView(QUrl("http://duckduckgo.com"), this); }); } RekonqWindow::~RekonqWindow() { delete ui; } void RekonqWindow::addView(RekonqView *view) { Q_CHECK_PTR(view); ui->views->addWidget(view); ui->tabs->addTab(view); connect(view, &RekonqView::urlChanged, ui->urlBar, &UrlBar::setUrl); connect(view, &RekonqView::titleChanged, [this, view](const QString &title) { const auto index = ui->views->indexOf(view); ui->tabs->setTabText(index, view->title()); }); connect(view, &RekonqView::loadStarted, ui->urlBar, &UrlBar::loadStarted); connect(view, &RekonqView::loadProgress, ui->urlBar, &UrlBar::loadProgress); connect(view, &RekonqView::loadFinished, ui->urlBar, &UrlBar::loadFinished); } /* void RekonqWindow::init() { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QVBoxLayout *l = new QVBoxLayout(this); l->setMargin(0); l->setSpacing(0); if (ReKonfig::showBookmarksPanel()) showBookmarksPanel(true); if (ReKonfig::showHistoryPanel()) showHistoryPanel(true); _splitter->addWidget(_tabWidget); _tabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); l->addWidget(_splitter); // fix focus handling setFocusProxy(_tabWidget); // signals connect(_tabWidget, SIGNAL(closeWindow()), this, SLOT(close())); connect(_tabWidget, SIGNAL(windowTitleChanged(QString)), this, SLOT(setWindowTitle(QString))); } // -------------------------------------------------------------------------------------------------- TabWidget *RekonqWindow::tabWidget() { return _tabWidget; } TabBar *RekonqWindow::tabBar() { return _tabWidget->tabBar(); } WebWindow *RekonqWindow::currentWebWindow() const { return _tabWidget->currentWebWindow(); } bool RekonqWindow::isPrivateBrowsingMode() { return _tabWidget->isPrivateBrowsingWindowMode(); } // -------------------------------------------------------------------------------------------------- void RekonqWindow::loadUrl(const KUrl &url, Rekonq::OpenType type, TabHistory *history) { switch (type) { case Rekonq::NewWindow: case Rekonq::NewPrivateWindow: case Rekonq::WebApp: rApp->loadUrl(url, type); return; case Rekonq::NewTab: case Rekonq::NewBackGroundTab: case Rekonq::NewFocusedTab: case Rekonq::CurrentTab: default: _tabWidget->loadUrl(url, type, history); break; }; } void RekonqWindow::showBookmarksPanel(bool on) { if (on) { if (_bookmarksPanel.isNull()) { _bookmarksPanel = new BookmarksPanel(i18n("Bookmarks Panel"), this); connect(_bookmarksPanel.data(), SIGNAL(openUrl(KUrl,Rekonq::OpenType)), this, SLOT(loadUrl(KUrl,Rekonq::OpenType))); QAction *a = _tabWidget->actionByName(QL1S("show_bookmarks_panel")); connect(_bookmarksPanel.data(), SIGNAL(visibilityChanged(bool)), a, SLOT(setChecked(bool))); } _splitter->insertWidget(0, _bookmarksPanel.data()); _bookmarksPanel.data()->show(); } else { _bookmarksPanel.data()->hide(); delete _bookmarksPanel.data(); _bookmarksPanel.clear(); } } void RekonqWindow::showHistoryPanel(bool on) { if (on) { if (_historyPanel.isNull()) { _historyPanel = new HistoryPanel(i18n("History Panel"), this); connect(_historyPanel.data(), SIGNAL(openUrl(KUrl,Rekonq::OpenType)), this, SLOT(loadUrl(KUrl,Rekonq::OpenType))); QAction *a = _tabWidget->actionByName(QL1S("show_history_panel")); connect(_historyPanel.data(), SIGNAL(visibilityChanged(bool)), a, SLOT(setChecked(bool))); } _splitter->insertWidget(0, _historyPanel.data()); _historyPanel.data()->show(); } else { _historyPanel.data()->hide(); delete _historyPanel.data(); _historyPanel.clear(); } } */