aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2021-01-21 21:17:08 +1100
committerFelix Queißner <felix@ib-queissner.de>2021-01-21 13:49:54 +0100
commit2091b038ef2a23a85d30d056307b3c405c416256 (patch)
tree36520f2e35228fd1acdf469c68a04be5ec93c42c /src
parentef592c41848ded6253502a536abedb298aed1105 (diff)
downloadkristall-2091b038ef2a23a85d30d056307b3c405c416256.tar.gz
Added '+' button to tab bar
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp5
-rw-r--r--src/widgets/browsertabbar.cpp44
-rw-r--r--src/widgets/browsertabbar.hpp14
-rw-r--r--src/widgets/browsertabwidget.cpp5
-rw-r--r--src/widgets/browsertabwidget.hpp5
5 files changed, 67 insertions, 6 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 0bc4d90..1d9dfb0 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -15,6 +15,7 @@
#include "ioutil.hpp"
#include "kristall.hpp"
+#include "widgets/browsertabbar.hpp"
#include "dialogs/certificatemanagementdialog.hpp"
@@ -92,6 +93,10 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) :
this->ui->favourites_view->setContextMenuPolicy(Qt::CustomContextMenu);
this->ui->history_view->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ connect(this->ui->browser_tabs->tab_bar, &BrowserTabBar::on_newTabClicked, this, [this]() {
+ this->addEmptyTab(true, true);
+ });
}
MainWindow::~MainWindow()
diff --git a/src/widgets/browsertabbar.cpp b/src/widgets/browsertabbar.cpp
index 503157f..97fc1a1 100644
--- a/src/widgets/browsertabbar.cpp
+++ b/src/widgets/browsertabbar.cpp
@@ -2,10 +2,17 @@
#include <QMouseEvent>
+static const int NEWTAB_BTN_SIZE = 22,
+ NEWTAB_BTN_PAD_X = 4;
+
+
BrowserTabBar::BrowserTabBar(QWidget *parent) :
QTabBar(parent)
{
-
+ newTabBtn = new QPushButton("+", this);
+ newTabBtn->setFixedSize(NEWTAB_BTN_SIZE, NEWTAB_BTN_SIZE);
+ connect(newTabBtn, &QPushButton::clicked, this, &BrowserTabBar::on_newTabClicked);
+ this->newTabBtn->setVisible(true);
}
void BrowserTabBar::mouseReleaseEvent(QMouseEvent *event)
@@ -16,3 +23,38 @@ void BrowserTabBar::mouseReleaseEvent(QMouseEvent *event)
QTabBar::mousePressEvent(event);
}
}
+
+void BrowserTabBar::moveNewTabButton()
+{
+ // Find width of all tabs
+ int size = 0;
+ for (int i = 0; i < this->count(); ++i)
+ size += this->tabRect(i).width();
+
+ // Set location
+ int h = this->geometry().top();
+ int w = this->width();
+ if ((size + NEWTAB_BTN_SIZE + NEWTAB_BTN_PAD_X) > w)
+ {
+ this->newTabBtn->setVisible(false);
+ //this->newTabBtn->move(w - 54, h + 22 / 4);
+ }
+ else
+ {
+ this->newTabBtn->setVisible(true);
+ this->newTabBtn->move(size + NEWTAB_BTN_PAD_X,
+ h + NEWTAB_BTN_SIZE / 4);
+ }
+}
+
+void BrowserTabBar::resizeEvent(QResizeEvent *event)
+{
+ QTabBar::resizeEvent(event);
+ this->moveNewTabButton();
+}
+
+void BrowserTabBar::tabLayoutChange()
+{
+ QTabBar::tabLayoutChange();
+ this->moveNewTabButton();
+}
diff --git a/src/widgets/browsertabbar.hpp b/src/widgets/browsertabbar.hpp
index f1cd49b..674089b 100644
--- a/src/widgets/browsertabbar.hpp
+++ b/src/widgets/browsertabbar.hpp
@@ -2,6 +2,7 @@
#define BROWSERTABS_HPP
#include <QTabBar>
+#include <QPushButton>
class BrowserTabBar : public QTabBar
{
@@ -10,6 +11,19 @@ public:
explicit BrowserTabBar(QWidget * parent);
void mouseReleaseEvent(QMouseEvent *event) override;
+
+ void resizeEvent(QResizeEvent *event) override;
+
+ void tabLayoutChange() override;
+
+signals:
+ void on_newTabClicked();
+
+private:
+ void moveNewTabButton();
+
+private:
+ QPushButton *newTabBtn;
};
#endif // BROWSERTABS_HPP
diff --git a/src/widgets/browsertabwidget.cpp b/src/widgets/browsertabwidget.cpp
index 7419c52..9a6ee94 100644
--- a/src/widgets/browsertabwidget.cpp
+++ b/src/widgets/browsertabwidget.cpp
@@ -1,8 +1,7 @@
#include "browsertabwidget.hpp"
-#include "browsertabbar.hpp"
-
BrowserTabWidget::BrowserTabWidget(QWidget *parent) : QTabWidget(parent)
{
- this->setTabBar(new BrowserTabBar(this));
+ this->tab_bar = new BrowserTabBar(this);
+ this->setTabBar(this->tab_bar);
}
diff --git a/src/widgets/browsertabwidget.hpp b/src/widgets/browsertabwidget.hpp
index dd4142c..7ada869 100644
--- a/src/widgets/browsertabwidget.hpp
+++ b/src/widgets/browsertabwidget.hpp
@@ -2,6 +2,7 @@
#define BROWSERTABWIDGET_HPP
#include <QTabWidget>
+#include "browsertabbar.hpp"
class BrowserTabWidget : public QTabWidget
{
@@ -9,8 +10,8 @@ class BrowserTabWidget : public QTabWidget
public:
explicit BrowserTabWidget(QWidget *parent = nullptr);
-signals:
-
+public:
+ BrowserTabBar *tab_bar;
};
#endif // BROWSERTABWIDGET_HPP