Commit 569903ce authored by Marius Knaust's avatar Marius Knaust Committed by Thomas McGuire

Make it possible to close tabs with the middle mouse button.

Possible fix using KTabWidget instead of QTabWidget and a eventFilter to
catch the MidButton MouseButtonPress event to avoid the tab selection.

BUG: 207270
REVIEW: 101632
parent 3ef74f65
......@@ -30,6 +30,7 @@
#include <QtGui/QItemSelectionModel>
#include <QtGui/QTabBar>
#include <QtGui/QToolButton>
#include <QtGui/QMouseEvent>
#include "storagemodel.h"
#include "widget.h"
......@@ -50,6 +51,7 @@ public:
void onSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
void onNewTabClicked();
void onCloseTabClicked();
void closeTab( QWidget * );
void onCurrentTabChanged();
void onTabContextMenuRequest( const QPoint &pos );
......@@ -80,7 +82,7 @@ using namespace MessageList;
Pane::Pane( QAbstractItemModel *model, QItemSelectionModel *selectionModel, QWidget *parent )
: QTabWidget( parent ), d( new Private( this ) )
: KTabWidget( parent ), d( new Private( this ) )
{
d->mModel = model;
d->mSelectionModel = selectionModel;
......@@ -134,6 +136,10 @@ Pane::Pane( QAbstractItemModel *model, QItemSelectionModel *selectionModel, QWid
connect( Core::Settings::self(), SIGNAL(configChanged()),
this, SLOT(updateTabControls()) );
connect( this, SIGNAL(mouseMiddleClick( QWidget * )),
this, SLOT(closeTab( QWidget * )) );
tabBar()->installEventFilter( this );
}
Pane::~Pane()
......@@ -362,7 +368,11 @@ void Pane::Private::onNewTabClicked()
void Pane::Private::onCloseTabClicked()
{
Widget *w = static_cast<Widget*>( q->currentWidget() );
closeTab( q->currentWidget() );
}
void Pane::Private::closeTab( QWidget *w )
{
if ( !w || (q->count() < 2) ) {
return;
}
......@@ -371,6 +381,17 @@ void Pane::Private::onCloseTabClicked()
updateTabControls();
}
bool Pane::eventFilter( QObject *object, QEvent *event )
{
if ( event->type() == QEvent::MouseButtonPress ) {
QMouseEvent * const mouseEvent = static_cast<QMouseEvent *>( event );
if ( mouseEvent->button() == Qt::MidButton ) {
return true;
}
}
return KTabWidget::eventFilter( object, event );
}
void Pane::Private::onCurrentTabChanged()
{
emit q->currentTabChanged();
......
......@@ -22,7 +22,7 @@
#include <messagelist/core/enums.h>
#include <messagelist/core/view.h>
#include <QtCore/QHash>
#include <QtGui/QTabWidget>
#include <KTabWidget>
#include <kmime/kmime_message.h>
#include <akonadi/collection.h>
......@@ -62,7 +62,7 @@ class StorageModel;
* used if available.
*
*/
class MESSAGELIST_EXPORT Pane : public QTabWidget
class MESSAGELIST_EXPORT Pane : public KTabWidget
{
Q_OBJECT
......@@ -421,10 +421,13 @@ private:
Q_PRIVATE_SLOT(d, void onSelectionChanged( const QItemSelection&, const QItemSelection& ))
Q_PRIVATE_SLOT(d, void onNewTabClicked())
Q_PRIVATE_SLOT(d, void onCloseTabClicked())
Q_PRIVATE_SLOT(d, void closeTab( QWidget * ))
Q_PRIVATE_SLOT(d, void onCurrentTabChanged())
Q_PRIVATE_SLOT(d, void onTabContextMenuRequest( const QPoint& ))
Q_PRIVATE_SLOT(d, void updateTabControls())
bool eventFilter( QObject *obj, QEvent *event );
class Private;
Private * const d;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment