Fix new tab adding by mouse double click under Ubuntu

This commit is contained in:
Abs62 2012-12-27 17:04:46 +04:00
parent 32b77e2848
commit be4adc00a0
2 changed files with 23 additions and 1 deletions

View file

@ -3,9 +3,13 @@
#include "maintabwidget.hh" #include "maintabwidget.hh"
#include <QDebug> #include <QDebug>
#include <QEvent>
#include <QMouseEvent>
MainTabWidget::MainTabWidget( QWidget * parent) : QTabWidget( parent ) { MainTabWidget::MainTabWidget( QWidget * parent) : QTabWidget( parent ) {
hideSingleTab = false; hideSingleTab = false;
installEventFilter( this );
tabBar()->installEventFilter( this );
} }
void MainTabWidget::setHideSingleTab(bool hide) void MainTabWidget::setHideSingleTab(bool hide)
@ -37,8 +41,25 @@ void MainTabWidget::updateTabBarVisibility()
tabBar()->setVisible( !hideSingleTab || tabBar()->count() > 1 ); tabBar()->setVisible( !hideSingleTab || tabBar()->count() > 1 );
} }
/*
void MainTabWidget::mouseDoubleClickEvent ( QMouseEvent * event ) void MainTabWidget::mouseDoubleClickEvent ( QMouseEvent * event )
{ {
(void) event; (void) event;
emit doubleClicked(); 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( tabBar()->tabAt( mev->pos() ) == -1 )
{
emit doubleClicked();
return true;
}
}
return QTabWidget::eventFilter( obj, ev );
}

View file

@ -24,12 +24,13 @@ signals:
void doubleClicked(); void doubleClicked();
protected: protected:
virtual void mouseDoubleClickEvent ( QMouseEvent * event ); // virtual void mouseDoubleClickEvent ( QMouseEvent * event );
private: private:
virtual void tabInserted(int index); virtual void tabInserted(int index);
virtual void tabRemoved(int index); virtual void tabRemoved(int index);
void updateTabBarVisibility(); void updateTabBarVisibility();
virtual bool eventFilter( QObject * obj, QEvent * ev );
bool hideSingleTab; bool hideSingleTab;
}; };