aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow/widgets
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-08-07 10:18:28 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-08-07 10:18:28 +0200
commite68dbcfd937a3de352152857ef9ad146a7c89bfc (patch)
tree751b0f1d6c7a223b19b06730fabc0cca478fa57d /src/mainwindow/widgets
parentFix fullscreen toggle (diff)
downloadsmolbote-e68dbcfd937a3de352152857ef9ad146a7c89bfc.tar.xz
Move SubWindow to src/subwindow
Diffstat (limited to 'src/mainwindow/widgets')
-rw-r--r--src/mainwindow/widgets/tabwidget.cpp123
-rw-r--r--src/mainwindow/widgets/tabwidget.h37
2 files changed, 0 insertions, 160 deletions
diff --git a/src/mainwindow/widgets/tabwidget.cpp b/src/mainwindow/widgets/tabwidget.cpp
deleted file mode 100644
index 1ddfc95..0000000
--- a/src/mainwindow/widgets/tabwidget.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "tabwidget.h"
-#include "browser.h"
-#include "webengine/webview.h"
-#include <QAction>
-#include <QContextMenuEvent>
-#include <QMenu>
-#include <QTabBar>
-#include <webprofile.h>
-
-TabWidget::TabWidget(QWidget *parent)
- : QTabWidget(parent)
-{
- setStyleSheet("QTabBar::tab { width: 200px; }");
-
- setTabsClosable(true);
- //setTabBarAutoHide(true);
- setElideMode(Qt::ElideRight);
- setMovable(true);
-
- connect(this, &TabWidget::tabCloseRequested, this, &TabWidget::deleteTab);
-
- // when changing tabs, give focus to the widget
- // otherwise when closing tabs, the tabwidget will retain focus
- connect(this, &TabWidget::currentChanged, this, [this](int index) {
- if(widget(index))
- widget(index)->setFocus();
- });
-
- // context menu
- tabContextMenu = new QMenu(this);
- auto *closeTab = tabContextMenu->addAction(tr("Close Tab"));
- connect(closeTab, &QAction::triggered, this, [this]() {
- deleteTab(this->tabBar()->tabAt(mapFromGlobal(tabContextMenu->pos())));
- });
-
- auto *closeTabsLeft = tabContextMenu->addAction(tr("Close Tabs left"));
- connect(closeTabsLeft, &QAction::triggered, this, [this]() {
- int idx = this->tabBar()->tabAt(mapFromGlobal(tabContextMenu->pos()));
- for(int i = idx - 1; i >= 0; --i) {
- deleteTab(i);
- }
- });
-
- auto *closeTabsRight = tabContextMenu->addAction(tr("Close Tabs right"));
- connect(closeTabsRight, &QAction::triggered, this, [this]() {
- int idx = this->tabBar()->tabAt(mapFromGlobal(tabContextMenu->pos()));
- for(int i = count() - 1; i > idx; --i) {
- deleteTab(i);
- }
- });
-}
-
-TabWidget::~TabWidget()
-{
- for(int i = count() - 1; i >= 0; i--) {
- delete widget(i);
- }
-}
-
-int TabWidget::addTab(WebView *view)
-{
- Q_ASSERT_X(view != nullptr, "TabWidget::addTab", "Tried to add null view");
-
- int idx = QTabWidget::addTab(view, view->title());
- connect(view, &WebView::titleChanged, [this, view](const QString &title) {
- int idx = this->indexOf(view);
- Q_ASSERT(idx != -1);
-
- this->setTabText(idx, title);
- });
- connect(view, &WebView::iconChanged, [this, view](const QIcon &icon) {
- int idx = this->indexOf(view);
- Q_ASSERT(idx != -1);
-
- this->setTabIcon(idx, icon);
- });
-
- return idx;
-}
-
-void TabWidget::deleteTab(int index)
-{
- // deleting the widget automatically removes the tab?
- auto *w = widget(index);
- disconnect(w);
- delete w;
-
- if(count() == 0)
- parentWidget()->close();
-}
-
-void TabWidget::contextMenuEvent(QContextMenuEvent *event)
-{
- // check if the context menu was called on a tab
- int tabIndex = tabBar()->tabAt(event->pos());
- if(tabIndex < 0) {
- return;
- }
-
- tabContextMenu->exec(event->globalPos());
-}
-
-void TabWidget::mousePressEvent(QMouseEvent *event)
-{
- if(event->button() == Qt::MiddleButton) {
- int index = tabBar()->tabAt(event->pos());
- if(index >= 0) {
- deleteTab(index);
- }
- event->accept();
- return;
- }
-
- QTabWidget::mousePressEvent(event);
-}
diff --git a/src/mainwindow/widgets/tabwidget.h b/src/mainwindow/widgets/tabwidget.h
deleted file mode 100644
index 793e041..0000000
--- a/src/mainwindow/widgets/tabwidget.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#ifndef SMOLBOTE_TABWIDGET_H
-#define SMOLBOTE_TABWIDGET_H
-
-#include <QTabWidget>
-
-class QAction;
-class QMenu;
-class WebView;
-class TabWidget : public QTabWidget
-{
- Q_OBJECT
-
-public:
- explicit TabWidget(QWidget *parent = nullptr);
- ~TabWidget() override;
-
-public slots:
- int addTab(WebView *view);
- void deleteTab(int index);
-
-protected:
- void contextMenuEvent(QContextMenuEvent *event) override;
- void mousePressEvent(QMouseEvent *event) override;
-
-private:
- QMenu *tabContextMenu;
-};
-
-#endif // SMOLBOTE_TABWIDGET_H