diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-08-28 17:36:28 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-09-05 23:07:42 +0300 |
commit | 72190e0977c0e352e5055e6f65bf2095efa77805 (patch) | |
tree | 6f13302e39141ed6c7ff5f382d310e7273c379d8 /src | |
parent | Remove source_location (diff) | |
download | rekonq-72190e0977c0e352e5055e6f65bf2095efa77805.tar.xz |
Add actions to RekonqView
- back, forward, refresh, reload
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/application.cpp | 2 | ||||
-rw-r--r-- | src/rekonqwindow.cpp | 112 | ||||
-rw-r--r-- | src/rekonqwindow.hpp (renamed from src/rekonqwindow.h) | 11 | ||||
-rw-r--r-- | src/rekonqwindow.ui | 66 | ||||
-rw-r--r-- | src/tabbar/tabbar.cpp | 1 | ||||
-rw-r--r-- | src/tabbar/tabbar.h | 6 | ||||
-rw-r--r-- | src/taskmanager.cpp | 2 | ||||
-rw-r--r-- | src/test/rview_fake.h | 6 |
9 files changed, 142 insertions, 66 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 75905f36..cc197ee3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,7 @@ set(rekonq_SRCS #---------------------------------------- main.cpp application.cpp application_instance.cpp application.hpp #---------------------------------------- - rekonqwindow.cpp rekonqwindow.h rekonqwindow.ui + rekonqwindow.cpp rekonqwindow.hpp rekonqwindow.ui taskmanager.cpp taskmanager.h taskmanager.ui #---------------------------------------- plugins/rplugininterface.hpp diff --git a/src/application.cpp b/src/application.cpp index d18c0231..944d6ea1 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -12,7 +12,7 @@ #include "application.hpp" #include "plugins/pluginloader.h" #include "plugins/rplugininterface.hpp" -#include "rekonqwindow.h" +#include "rekonqwindow.hpp" #include "settings/settings.hpp" #include "settings/settingsdialog.h" #include <QDir> diff --git a/src/rekonqwindow.cpp b/src/rekonqwindow.cpp index 4f3e57f1..094dc1ff 100644 --- a/src/rekonqwindow.cpp +++ b/src/rekonqwindow.cpp @@ -5,15 +5,14 @@ * Copyright (C) 2013 by Andrea Diamantini <adjam7 at gmail dot com> * SPDX-License-Identifier: GPL-3.0-only * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net> - * ============================================================ - * Description: Main Window class * ============================================================ */ -#include "rekonqwindow.h" +#include "rekonqwindow.hpp" #include "application.hpp" #include "settings/settingsdialog.h" #include "taskmanager.h" #include "ui_rekonqwindow.h" +#include <rsettings.hpp> #include <rview.hpp> RekonqWindow::RekonqWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::RekonqWindow) @@ -29,8 +28,21 @@ RekonqWindow::RekonqWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::Re }); connect(ui->tabs, &TabBar::removeView, this, [this](RekonqView *view) { ui->views->removeWidget(view); }); + connect(ui->back, &QToolButton::clicked, this, [this]() { currentView()->back(); }); + connect(ui->forward, &QToolButton::clicked, this, [this]() { currentView()->forward(); }); + connect(ui->refresh, &QToolButton::clicked, this, [this]() { currentView()->refresh(); }); + connect(ui->home, &QToolButton::clicked, this, [this]() { loadUrl(QUrl()); }); + // connect menu actions // file menu + connect(ui->actionNewTab, &QAction::triggered, this, [this]() { + auto *app = Application::instance(); + Q_CHECK_PTR(app); + auto newTabUrl = app->settings()->value("newtab").toUrl(); + loadUrl(newTabUrl, rekonq::NewFocusedTab); + }); + connect(ui->actionCloseTab, &QAction::triggered, this, + [this]() { emit ui->tabs->tabCloseRequested(ui->tabs->currentIndex()); }); connect(ui->actionQuit, &QAction::triggered, qApp, &QApplication::quit); // edit menu // view menu @@ -49,79 +61,73 @@ RekonqWindow::RekonqWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::Re RekonqWindow::~RekonqWindow() { delete ui; } -void RekonqWindow::addView(RekonqView *view) +// -------------------------------------------------------------------------------------------------- + +RekonqView *RekonqWindow::currentView() +{ + auto *view = ui->tabs->view(ui->tabs->currentIndex()); + Q_CHECK_PTR(view); + return view; +} + +int RekonqWindow::addView(RekonqView *view) { Q_CHECK_PTR(view); ui->views->addWidget(view); - ui->tabs->addTab(view); - connect(view, &RekonqView::urlChanged, ui->urlBar, &UrlBar::setUrl); + const auto index = ui->tabs->addTab(view); + connect(view, &RekonqView::urlChanged, [this, view](const QUrl &url) { + if (view == currentView()) ui->urlBar->setUrl(url); + }); connect(view, &RekonqView::titleChanged, [this, view](const QString &title) { - const auto index = ui->views->indexOf(view); - ui->tabs->setTabText(index, view->title()); + const auto idx = ui->views->indexOf(view); + ui->tabs->setTabText(idx, title); + }); + connect(view, &RekonqView::iconChanged, [this, view](const QIcon &icon) { + const auto idx = ui->views->indexOf(view); + ui->tabs->setTabIcon(idx, icon); }); 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))); + return index; } -// -------------------------------------------------------------------------------------------------- - - -TabWidget *RekonqWindow::tabWidget() +void RekonqWindow::loadUrl(const QUrl &url, rekonq::OpenType type) { - return _tabWidget; -} - - -TabBar *RekonqWindow::tabBar() -{ - return _tabWidget->tabBar(); -} - - -WebWindow *RekonqWindow::currentWebWindow() const -{ - return _tabWidget->currentWebWindow(); + switch (type) { + case rekonq::CurrentTab: + currentView()->load(url); + break; + case rekonq::NewTab: + Application::instance()->newView(url, this); + break; + case rekonq::NewFocusedTab: + ui->tabs->setCurrentView(Application::instance()->newView(url, this)); + break; + case rekonq::NewBackGroundTab: + break; + case rekonq::NewWindow: + break; + case rekonq::NewPrivateWindow: + break; + case rekonq::WebApp: + Application::instance()->newView(url, nullptr); + break; + } } +// -------------------------------------------------------------------------------------------------- +/* bool RekonqWindow::isPrivateBrowsingMode() { return _tabWidget->isPrivateBrowsingWindowMode(); } -// -------------------------------------------------------------------------------------------------- void RekonqWindow::loadUrl(const KUrl &url, Rekonq::OpenType type, TabHistory *history) diff --git a/src/rekonqwindow.h b/src/rekonqwindow.hpp index e6316819..ba1fd70f 100644 --- a/src/rekonqwindow.h +++ b/src/rekonqwindow.hpp @@ -34,20 +34,15 @@ class RekonqWindow : public QMainWindow { public: explicit RekonqWindow(QWidget *parent = nullptr); - // explicit RekonqWindow(WebPage *pg, QWidget *parent = 0); ~RekonqWindow() override; - // TabWidget *tabWidget(); - // TabBar *tabBar(); - // WebWindow *currentWebWindow() const; + [[nodiscard]] RekonqView *currentView(); // bool isPrivateBrowsingMode(); -private: - // void init(); - public slots: - void addView(RekonqView *view); + int addView(RekonqView *view); + void loadUrl(const QUrl &url, rekonq::OpenType type = rekonq::CurrentTab); // void loadUrl(const KUrl &, Rekonq::OpenType type = Rekonq::CurrentTab, TabHistory *history = 0); private slots: diff --git a/src/rekonqwindow.ui b/src/rekonqwindow.ui index 9e3986e1..323a500a 100644 --- a/src/rekonqwindow.ui +++ b/src/rekonqwindow.ui @@ -22,9 +22,16 @@ </item> <item> <widget class="QToolButton" name="newTab"> + <property name="styleSheet"> + <string notr="true">border: none;</string> + </property> <property name="text"> <string>Add Tab</string> </property> + <property name="icon"> + <iconset theme="document-new"> + <normaloff>.</normaloff>.</iconset> + </property> </widget> </item> </layout> @@ -36,6 +43,10 @@ <property name="text"> <string>Back</string> </property> + <property name="icon"> + <iconset theme="go-previous"> + <normaloff>.</normaloff>.</iconset> + </property> </widget> </item> <item> @@ -43,6 +54,32 @@ <property name="text"> <string>Forward</string> </property> + <property name="icon"> + <iconset theme="go-next"> + <normaloff>.</normaloff>.</iconset> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="refresh"> + <property name="text"> + <string>Reload</string> + </property> + <property name="icon"> + <iconset theme="view-refresh"> + <normaloff>.</normaloff>.</iconset> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="home"> + <property name="text"> + <string>Home</string> + </property> + <property name="icon"> + <iconset theme="go-home"> + <normaloff>.</normaloff>.</iconset> + </property> </widget> </item> <item> @@ -53,6 +90,10 @@ <property name="text"> <string>Load</string> </property> + <property name="icon"> + <iconset theme="bookmarks"> + <normaloff>.</normaloff>.</iconset> + </property> </widget> </item> <item> @@ -60,6 +101,10 @@ <property name="text"> <string>Menu</string> </property> + <property name="icon"> + <iconset theme="preferences"> + <normaloff>.</normaloff>.</iconset> + </property> </widget> </item> </layout> @@ -75,13 +120,16 @@ <x>0</x> <y>0</y> <width>800</width> - <height>22</height> + <height>30</height> </rect> </property> <widget class="QMenu" name="menuFile"> <property name="title"> <string>File</string> </property> + <addaction name="actionNewTab"/> + <addaction name="actionCloseTab"/> + <addaction name="separator"/> <addaction name="actionQuit"/> </widget> <widget class="QMenu" name="menuEdit"> @@ -159,6 +207,22 @@ <string>About Qt</string> </property> </action> + <action name="actionNewTab"> + <property name="text"> + <string>New Tab</string> + </property> + <property name="shortcut"> + <string>Ctrl+T</string> + </property> + </action> + <action name="actionCloseTab"> + <property name="text"> + <string>Close Tab</string> + </property> + <property name="shortcut"> + <string>Ctrl+W</string> + </property> + </action> </widget> <customwidgets> <customwidget> diff --git a/src/tabbar/tabbar.cpp b/src/tabbar/tabbar.cpp index c8624bda..9bb05d43 100644 --- a/src/tabbar/tabbar.cpp +++ b/src/tabbar/tabbar.cpp @@ -15,7 +15,6 @@ static inline QByteArray highlightPropertyName(int index) return QByteArray("hAnim").append(QByteArray::number(index)); } - // ------------------------------------------------------------------------------------ TabBar::TabBar(QWidget *parent) : QTabBar(parent) diff --git a/src/tabbar/tabbar.h b/src/tabbar/tabbar.h index c305d1b5..077255a4 100644 --- a/src/tabbar/tabbar.h +++ b/src/tabbar/tabbar.h @@ -29,6 +29,12 @@ public: QRect tabTextRect(int index); */ + void setCurrentView(RekonqView *view) + { + const auto index = m_views.indexOf(view); + setCurrentIndex(index); + } + signals: void removeView(RekonqView *); diff --git a/src/taskmanager.cpp b/src/taskmanager.cpp index ef1f44fb..6f90bf89 100644 --- a/src/taskmanager.cpp +++ b/src/taskmanager.cpp @@ -10,7 +10,7 @@ #include "taskmanager.h" #include "application.hpp" #include "plugins/pluginloader.h" -#include "rekonqwindow.h" +#include "rekonqwindow.hpp" #include "ui_taskmanager.h" TaskManager::TaskManager(QWidget *parent) : QDialog(parent), ui(new Ui::TaskManager) diff --git a/src/test/rview_fake.h b/src/test/rview_fake.h index 33685e7c..ebebe977 100644 --- a/src/test/rview_fake.h +++ b/src/test/rview_fake.h @@ -26,6 +26,12 @@ public: QString title() const override; QUrl url() const override; +public slots: + void back() override {} + void forward() override {} + void refresh() override {} + void reload() override {} + private: Ui::RekonqView_fake *ui; }; |