2013-12-21 21:08:52 +01:00
|
|
|
#include "gui/tabbar.h"
|
2013-07-30 18:54:36 +02:00
|
|
|
|
|
|
|
#include "core/defs.h"
|
|
|
|
#include "core/settings.h"
|
2013-12-21 21:08:52 +01:00
|
|
|
|
|
|
|
#include <QMouseEvent>
|
2013-07-30 18:54:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
TabBar::TabBar(QWidget *parent) : QTabBar(parent) {
|
|
|
|
setDocumentMode(true);
|
|
|
|
setUsesScrollButtons(true);
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
TabBar::~TabBar() {
|
2013-10-15 21:10:54 +02:00
|
|
|
qDebug("Destroying TabBar instance.");
|
2013-07-30 18:54:36 +02:00
|
|
|
}
|
|
|
|
|
2013-12-11 14:07:18 +01:00
|
|
|
void TabBar::wheelEvent(QWheelEvent *event) {
|
|
|
|
int current_index = currentIndex();
|
|
|
|
int number_of_tabs = count();
|
|
|
|
|
|
|
|
// Make sure rotating works.
|
|
|
|
if (number_of_tabs > 1) {
|
2013-12-11 18:54:09 +01:00
|
|
|
if (event->delta() > 0) {
|
|
|
|
// Scroll to the LEFT tab.
|
|
|
|
setCurrentIndex(current_index == 0 ?
|
|
|
|
number_of_tabs - 1 :
|
|
|
|
current_index - 1);
|
2013-12-11 14:07:18 +01:00
|
|
|
}
|
2013-12-11 18:54:09 +01:00
|
|
|
else if (event->delta() < 0) {
|
|
|
|
// Scroll to the RIGHT tab.
|
|
|
|
setCurrentIndex(current_index == number_of_tabs - 1 ?
|
|
|
|
0 :
|
|
|
|
current_index + 1);
|
2013-12-11 14:07:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 18:54:36 +02:00
|
|
|
void TabBar::mousePressEvent(QMouseEvent *event) {
|
|
|
|
QTabBar::mousePressEvent(event);
|
|
|
|
|
|
|
|
int tab_index = tabAt(event->pos());
|
|
|
|
|
|
|
|
// Check if user clicked on some tab or on empty space.
|
|
|
|
if (tab_index >= 0) {
|
|
|
|
// Check if user clicked tab with middle button.
|
|
|
|
// NOTE: This needs to be done here because
|
|
|
|
// destination does not know the original event.
|
2014-01-10 09:18:29 +01:00
|
|
|
if (event->button() & Qt::MiddleButton && Settings::instance()->value(APP_CFG_GUI,
|
2013-07-30 18:54:36 +02:00
|
|
|
"tab_close_mid_button",
|
|
|
|
true).toBool()) {
|
|
|
|
if (tabType(tab_index) == TabBar::Closable) {
|
|
|
|
// This tab is closable, so we can close it.
|
|
|
|
emit tabCloseRequested(tab_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBar::mouseDoubleClickEvent(QMouseEvent *event) {
|
|
|
|
QTabBar::mouseDoubleClickEvent(event);
|
|
|
|
|
|
|
|
int tab_index = tabAt(event->pos());
|
|
|
|
|
|
|
|
// Check if user clicked on some tab or on empty space.
|
|
|
|
if (tab_index >= 0) {
|
|
|
|
// Check if user clicked tab with middle button.
|
|
|
|
// NOTE: This needs to be done here because
|
|
|
|
// destination does not know the original event.
|
2014-01-10 09:18:29 +01:00
|
|
|
if (event->button() & Qt::LeftButton && Settings::instance()->value(APP_CFG_GUI,
|
2013-07-30 18:54:36 +02:00
|
|
|
"tab_close_double_button",
|
|
|
|
true).toBool()) {
|
|
|
|
if (tabType(tab_index) == TabBar::Closable) {
|
|
|
|
// This tab is closable, so we can close it.
|
|
|
|
emit tabCloseRequested(tab_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check if new tab should be opened with initial web browser.
|
|
|
|
// NOTE: This check could be unnecesary here and should be done in
|
|
|
|
// destination object but we keep it here for consistency.
|
2014-01-10 09:18:29 +01:00
|
|
|
else if (Settings::instance()->value(APP_CFG_GUI,
|
2013-07-30 18:54:36 +02:00
|
|
|
"tab_new_double_button",
|
|
|
|
true).toBool()) {
|
|
|
|
emit emptySpaceDoubleClicked();
|
|
|
|
}
|
|
|
|
}
|