From ad15a056672f049cf8302fc7a0a94b71f42db356 Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Sat, 27 Jun 2020 00:28:03 +0200 Subject: Allows middle-clicking to close tabs. --- src/kristall.pro | 4 +++ src/mainwindow.ui | 55 ++++++++++++++++++++++++++++------------ src/widgets/browsertabbar.cpp | 18 +++++++++++++ src/widgets/browsertabbar.hpp | 15 +++++++++++ src/widgets/browsertabwidget.cpp | 8 ++++++ src/widgets/browsertabwidget.hpp | 16 ++++++++++++ 6 files changed, 100 insertions(+), 16 deletions(-) create mode 100644 src/widgets/browsertabbar.cpp create mode 100644 src/widgets/browsertabbar.hpp create mode 100644 src/widgets/browsertabwidget.cpp create mode 100644 src/widgets/browsertabwidget.hpp (limited to 'src') diff --git a/src/kristall.pro b/src/kristall.pro index 43316cc..e50db0e 100644 --- a/src/kristall.pro +++ b/src/kristall.pro @@ -69,6 +69,8 @@ SOURCES += \ mainwindow.cpp \ renderers/markdownrenderer.cpp \ renderers/textstyleinstance.cpp \ + widgets/browsertabbar.cpp \ + widgets/browsertabwidget.cpp \ widgets/mediaplayer.cpp \ mimeparser.cpp \ protocolhandler.cpp \ @@ -109,6 +111,8 @@ HEADERS += \ mainwindow.hpp \ renderers/markdownrenderer.hpp \ renderers/textstyleinstance.hpp \ + widgets/browsertabbar.hpp \ + widgets/browsertabwidget.hpp \ widgets/mediaplayer.hpp \ mimeparser.hpp \ protocolhandler.hpp \ diff --git a/src/mainwindow.ui b/src/mainwindow.ui index f7ac5cb..886bd89 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -35,7 +35,7 @@ 0 - + -1 @@ -58,7 +58,8 @@ - + + .. Document Outline @@ -95,7 +96,8 @@ - + + .. Bookmarks @@ -125,7 +127,8 @@ - + + .. History @@ -210,7 +213,8 @@ - + + .. About... @@ -218,7 +222,8 @@ - + + .. Quit @@ -234,7 +239,8 @@ - + + .. Close Tab @@ -245,7 +251,8 @@ - + + .. Settings @@ -253,7 +260,8 @@ - + + .. Backward @@ -264,7 +272,8 @@ - + + .. Foreward @@ -275,7 +284,8 @@ - + + .. Refresh @@ -295,7 +305,8 @@ - + + .. Save as... @@ -321,7 +332,8 @@ - + + .. Go to home @@ -332,7 +344,8 @@ - + + .. Help @@ -343,7 +356,8 @@ - + + .. Changelog @@ -351,13 +365,22 @@ - + + .. Manage Certificates… + + + BrowserTabWidget + QTabWidget +
widgets/browsertabwidget.hpp
+ 1 +
+
diff --git a/src/widgets/browsertabbar.cpp b/src/widgets/browsertabbar.cpp new file mode 100644 index 0000000..503157f --- /dev/null +++ b/src/widgets/browsertabbar.cpp @@ -0,0 +1,18 @@ +#include "browsertabbar.hpp" + +#include + +BrowserTabBar::BrowserTabBar(QWidget *parent) : + QTabBar(parent) +{ + +} + +void BrowserTabBar::mouseReleaseEvent(QMouseEvent *event) +{ + if(event->button() == Qt::MiddleButton) { + emit tabCloseRequested(this->tabAt(event->pos())); + } else { + QTabBar::mousePressEvent(event); + } +} diff --git a/src/widgets/browsertabbar.hpp b/src/widgets/browsertabbar.hpp new file mode 100644 index 0000000..f1cd49b --- /dev/null +++ b/src/widgets/browsertabbar.hpp @@ -0,0 +1,15 @@ +#ifndef BROWSERTABS_HPP +#define BROWSERTABS_HPP + +#include + +class BrowserTabBar : public QTabBar +{ + Q_OBJECT +public: + explicit BrowserTabBar(QWidget * parent); + + void mouseReleaseEvent(QMouseEvent *event) override; +}; + +#endif // BROWSERTABS_HPP diff --git a/src/widgets/browsertabwidget.cpp b/src/widgets/browsertabwidget.cpp new file mode 100644 index 0000000..7419c52 --- /dev/null +++ b/src/widgets/browsertabwidget.cpp @@ -0,0 +1,8 @@ +#include "browsertabwidget.hpp" + +#include "browsertabbar.hpp" + +BrowserTabWidget::BrowserTabWidget(QWidget *parent) : QTabWidget(parent) +{ + this->setTabBar(new BrowserTabBar(this)); +} diff --git a/src/widgets/browsertabwidget.hpp b/src/widgets/browsertabwidget.hpp new file mode 100644 index 0000000..dd4142c --- /dev/null +++ b/src/widgets/browsertabwidget.hpp @@ -0,0 +1,16 @@ +#ifndef BROWSERTABWIDGET_HPP +#define BROWSERTABWIDGET_HPP + +#include + +class BrowserTabWidget : public QTabWidget +{ + Q_OBJECT +public: + explicit BrowserTabWidget(QWidget *parent = nullptr); + +signals: + +}; + +#endif // BROWSERTABWIDGET_HPP -- cgit v1.2.3