aboutsummaryrefslogtreecommitdiff
path: root/src/widgets/browsertabbar.cpp
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/widgets/browsertabbar.cpp
parentef592c41848ded6253502a536abedb298aed1105 (diff)
downloadkristall-2091b038ef2a23a85d30d056307b3c405c416256.tar.gz
Added '+' button to tab bar
Diffstat (limited to 'src/widgets/browsertabbar.cpp')
-rw-r--r--src/widgets/browsertabbar.cpp44
1 files changed, 43 insertions, 1 deletions
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();
+}