-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ztabwidget.cpp
32 lines (30 loc) · 980 Bytes
/
ztabwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <QMouseEvent>
#include "ztabwidget.h"
#include "ztabbar.h"
ZTabWidget::ZTabWidget(QWidget *parent) :
QTabWidget(parent)
{
tabBar = new ZTabBar(this);
// Control double-click on tab bar through an event filter.
tabBar->installEventFilter(this);
setTabBar(tabBar);
}
// Method is based on code from class MyTabWidget of project https://gitorious.org/qmpq.
bool ZTabWidget::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseButtonDblClick) {
QMouseEvent * mouseEvent = static_cast<QMouseEvent *>(event);
int tabIndex;
tabIndex = tabBar->tabAt(mouseEvent->pos());
if (tabIndex == -1)
// Chosen no a tab.
emit tabBarDoubleClickedOnEmptySpace();
else
// Chosen a tab
emit tabBarDoubleClickedOnTab(tabIndex);
return true;
} else {
// standard event processing
return QTabWidget::eventFilter(obj, event);
}
}