2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2012 Tvangeste <i.4m.l33t@yandex.ru>
|
2011-06-25 07:34:28 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
2011-06-23 14:17:09 +00:00
|
|
|
#include "maintabwidget.hh"
|
2012-12-27 13:04:46 +00:00
|
|
|
#include <QEvent>
|
|
|
|
#include <QMouseEvent>
|
2011-06-23 14:17:09 +00:00
|
|
|
|
|
|
|
MainTabWidget::MainTabWidget( QWidget * parent ):
|
|
|
|
QTabWidget( parent )
|
|
|
|
{
|
2011-07-19 10:03:13 +00:00
|
|
|
hideSingleTab = false;
|
2012-12-27 13:04:46 +00:00
|
|
|
installEventFilter( this );
|
|
|
|
tabBar()->installEventFilter( this );
|
2011-06-23 14:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTabWidget::setHideSingleTab( bool hide )
|
|
|
|
{
|
|
|
|
hideSingleTab = hide;
|
|
|
|
updateTabBarVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTabWidget::tabInserted( int index )
|
|
|
|
{
|
2012-10-31 13:58:35 +00:00
|
|
|
(void)index;
|
2011-06-23 14:17:09 +00:00
|
|
|
updateTabBarVisibility();
|
2012-02-15 16:27:03 +00:00
|
|
|
|
|
|
|
// Avoid bug in Qt 4.8.0
|
|
|
|
setUsesScrollButtons( count() > 10 );
|
2011-06-23 14:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTabWidget::tabRemoved( int index )
|
|
|
|
{
|
2012-10-31 13:58:35 +00:00
|
|
|
(void)index;
|
2011-06-23 14:17:09 +00:00
|
|
|
updateTabBarVisibility();
|
2012-02-15 16:27:03 +00:00
|
|
|
|
|
|
|
// Avoid bug in Qt 4.8.0
|
|
|
|
setUsesScrollButtons( count() > 10 );
|
2011-06-23 14:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTabWidget::updateTabBarVisibility()
|
|
|
|
{
|
|
|
|
tabBar()->setVisible( !hideSingleTab || tabBar()->count() > 1 );
|
|
|
|
}
|
2011-07-19 10:03:13 +00:00
|
|
|
|
2012-12-27 13:04:46 +00:00
|
|
|
bool MainTabWidget::eventFilter( QObject * obj, QEvent * ev )
|
|
|
|
{
|
2013-01-05 02:18:12 +00:00
|
|
|
if ( obj == tabBar() && ev->type() == QEvent::MouseButtonPress ) {
|
|
|
|
QMouseEvent * mev = static_cast< QMouseEvent * >( ev );
|
2022-01-08 13:16:22 +00:00
|
|
|
if ( mev->button() == Qt::MiddleButton ) {
|
2013-01-05 02:18:12 +00:00
|
|
|
emit tabCloseRequested( tabBar()->tabAt( mev->pos() ) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-27 13:04:46 +00:00
|
|
|
return QTabWidget::eventFilter( obj, ev );
|
|
|
|
}
|