forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaintabwidget.cc
78 lines (66 loc) · 1.79 KB
/
maintabwidget.cc
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* This file is (c) 2012 Tvangeste <[email protected]>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "maintabwidget.hh"
#include <QDebug>
#include <QEvent>
#include <QMouseEvent>
MainTabWidget::MainTabWidget( QWidget * parent) : QTabWidget( parent ) {
hideSingleTab = false;
installEventFilter( this );
tabBar()->installEventFilter( this );
}
void MainTabWidget::setHideSingleTab(bool hide)
{
hideSingleTab = hide;
updateTabBarVisibility();
}
void MainTabWidget::tabInserted(int index)
{
(void) index;
updateTabBarVisibility();
// Avoid bug in Qt 4.8.0
setUsesScrollButtons( count() > 10 );
}
void MainTabWidget::tabRemoved(int index)
{
(void) index;
updateTabBarVisibility();
// Avoid bug in Qt 4.8.0
setUsesScrollButtons( count() > 10 );
}
void MainTabWidget::updateTabBarVisibility()
{
tabBar()->setVisible( !hideSingleTab || tabBar()->count() > 1 );
}
/*
void MainTabWidget::mouseDoubleClickEvent ( QMouseEvent * event )
{
(void) event;
emit doubleClicked();
}
*/
bool MainTabWidget::eventFilter( QObject * obj, QEvent * ev )
{
// mouseDoubleClickEvent don't called under Ubuntu
if( ev->type() == QEvent::MouseButtonDblClick )
{
QMouseEvent * mev = static_cast< QMouseEvent *>( ev );
if( mev->y() >= tabBar()->rect().y()
&& mev->y() <= tabBar()->rect().y() + tabBar()->rect().height()
&& tabBar()->tabAt( mev->pos() ) == -1 )
{
emit doubleClicked();
return true;
}
}
if( obj == tabBar() && ev->type() == QEvent::MouseButtonPress )
{
QMouseEvent * mev = static_cast< QMouseEvent *>( ev );
if( mev->button() == Qt::MidButton )
{
emit tabCloseRequested( tabBar()->tabAt( mev->pos() ) );
return true;
}
}
return QTabWidget::eventFilter( obj, ev );
}