aboutsummaryrefslogtreecommitdiff
path: root/src/widgets/webviewtabbar.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-12-19 10:14:22 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-12-19 10:14:22 +0100
commitc1ad1be5924eb28bf6c32b049098fe24bbbb9e4e (patch)
tree7cc5ab0e600496279ab575a99a6a0b97c0d6f854 /src/widgets/webviewtabbar.cpp
parentSome bugfixes (diff)
downloadsmolbote-c1ad1be5924eb28bf6c32b049098fe24bbbb9e4e.tar.xz
Bug fixes
Switching between tabs should work properly now. Refactored MainWindowTabBar (was WebViewTabBar)
Diffstat (limited to 'src/widgets/webviewtabbar.cpp')
-rw-r--r--src/widgets/webviewtabbar.cpp159
1 files changed, 0 insertions, 159 deletions
diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp
deleted file mode 100644
index 81851f3..0000000
--- a/src/widgets/webviewtabbar.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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/>.
- **
- ******************************************************************************/
-
-#include "webviewtabbar.h"
-#include <QAction>
-#include <QContextMenuEvent>
-#include <QMenu>
-#include <settings/configuration.h>
-#include <QShortcut>
-
-WebViewTabBar::WebViewTabBar(const std::shared_ptr<Configuration> &config, WebEngineProfile *profile, QWidget *parent) :
- QTabBar(parent)
-{
- m_profile = profile;
-
- setElideMode(Qt::ElideRight);
- setTabsClosable(true);
- setMovable(true);
- setContextMenuPolicy(Qt::DefaultContextMenu);
- connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(removeTab(int)));
- connect(this, SIGNAL(currentChanged(int)), this, SLOT(handleCurrentChanged(int)));
- connect(this, SIGNAL(tabMoved(int,int)), this, SLOT(updateVectorArrangement(int,int)));
-
- QShortcut *tabCloseShortcut = new QShortcut(this);
- tabCloseShortcut->setKey(QKeySequence(QString::fromStdString(config->value<std::string>("browser.shortcuts.tabClose").value())));
- connect(tabCloseShortcut, &QShortcut::activated, [this]() {
- this->removeTab(currentIndex());
- });
-
- QShortcut *tabLeftShortcut = new QShortcut(this);
- tabLeftShortcut->setKey(QKeySequence(QString::fromStdString(config->value<std::string>("browser.shortcuts.tabLeft").value())));
- connect(tabLeftShortcut, &QShortcut::activated, [this]() {
- this->setCurrentIndex(currentIndex()-1);
- });
-
- QShortcut *tabRightShortcut = new QShortcut(this);
- tabRightShortcut->setKey(QKeySequence(QString::fromStdString(config->value<std::string>("browser.shortcuts.tabRight").value())));
- connect(tabRightShortcut, &QShortcut::activated, [this]() {
- this->setCurrentIndex(currentIndex()+1);
- });
-}
-
-WebViewTabBar::~WebViewTabBar()
-{
- // cleanup
- qDeleteAll(m_views);
- m_views.clear();
-}
-
-int WebViewTabBar::addTab(const QUrl &url)
-{
- WebView *view = new WebView(0);
- QWebEnginePage *page = new QWebEnginePage(m_profile);
- view->setPage(page);
- page->load(url);
- m_views.append(view);
-
- connect(view, &QWebEngineView::titleChanged, [this, view](const QString &title) {
- int index = m_views.indexOf(view);
- setTabText(index, title);
- });
- connect(view, &QWebEngineView::iconChanged, [this, view](const QIcon &icon) {
- int index = m_views.indexOf(view);
- setTabIcon(index, icon);
- });
-
- return QTabBar::addTab("New Tab");
-}
-
-void WebViewTabBar::setProfile(WebEngineProfile *profile)
-{
- Q_CHECK_PTR(profile);
-
- m_profile = profile;
- for(auto view : qAsConst(m_views)) {
- QWebEnginePage *page = new QWebEnginePage(profile);
- page->load(view->url());
- view->setPage(page);
- }
-}
-
-WebEngineProfile *WebViewTabBar::profile()
-{
- return m_profile;
-}
-
-WebView *WebViewTabBar::currentView()
-{
- return m_views.at(currentIndex());
-}
-
-void WebViewTabBar::contextMenuEvent(QContextMenuEvent *event)
-{
- int tabIndex = tabAt(event->pos());
- if(tabIndex < 0) {
- return;
- }
-
- QMenu menu(this);
- QAction* closeAction = menu.addAction(tr("Close tab"));
- connect(closeAction, &QAction::triggered, this, [tabIndex, this]() {
- removeTab(tabIndex);
- });
- menu.exec(event->globalPos());
-}
-
-QSize WebViewTabBar::tabSizeHint(int index) const
-{
- Q_UNUSED(index)
- return QSize(200, this->height());
-}
-
-void WebViewTabBar::handleCurrentChanged(int index)
-{
- if(index < 0) {
- addTab(m_profile->newtab());
- return;
- }
- emit currentTabChanged(m_views.at(index));
-}
-
-void WebViewTabBar::removeTab(int index)
-{
- // remove the tab data from the index
- m_views.at(index)->deleteLater();
- m_views.remove(index);
-
- // remove the tab from the QTabBar
- // this emits the currentTabChanged signal, so it should be done after the view is removed from the index
- QTabBar::removeTab(index);
-}
-
-void WebViewTabBar::updateTabText(WebView *view, const QString &text)
-{
- int index = m_views.indexOf(view);
- setTabText(index, text);
-}
-
-void WebViewTabBar::updateVectorArrangement(int from, int to)
-{
- m_views.move(from, to);
-}