Commit dfbe8657 authored by Daniel Teske's avatar Daniel Teske

Application Output: Add middle click closes tab feature

Task-number: QTCREATORBUG-12804
Change-Id: If370056cd0cda1f02558cbd02134a12877d5ce3d
Reviewed-by: default avatarRobert Loehning <robert.loehning@digia.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 8b3b868f
...@@ -81,21 +81,51 @@ public: ...@@ -81,21 +81,51 @@ public:
TabWidget(QWidget *parent = 0); TabWidget(QWidget *parent = 0);
signals: signals:
void contextMenuRequested(const QPoint &pos, const int index); void contextMenuRequested(const QPoint &pos, const int index);
protected:
bool eventFilter(QObject *object, QEvent *event);
private slots: private slots:
void slotContextMenuRequested(const QPoint &pos); void slotContextMenuRequested(const QPoint &pos);
private:
int m_tabIndexForMiddleClick;
}; };
} }
} }
TabWidget::TabWidget(QWidget *parent) TabWidget::TabWidget(QWidget *parent)
: QTabWidget(parent) : QTabWidget(parent), m_tabIndexForMiddleClick(-1)
{ {
tabBar()->installEventFilter(this);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), connect(this, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(slotContextMenuRequested(QPoint))); this, SLOT(slotContextMenuRequested(QPoint)));
} }
bool TabWidget::eventFilter(QObject *object, QEvent *event)
{
if (object == tabBar()) {
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
if (me->button() == Qt::MiddleButton) {
m_tabIndexForMiddleClick = tabBar()->tabAt(me->pos());
event->accept();
return true;
}
} else if (event->type() == QEvent::MouseButtonRelease) {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
if (me->button() == Qt::MiddleButton) {
int tab = tabBar()->tabAt(me->pos());
if (tab != -1 && tab == m_tabIndexForMiddleClick)
emit tabCloseRequested(tab);
m_tabIndexForMiddleClick = -1;
event->accept();
return true;
}
}
}
return QTabWidget::eventFilter(object, event);
}
void TabWidget::slotContextMenuRequested(const QPoint &pos) void TabWidget::slotContextMenuRequested(const QPoint &pos)
{ {
emit contextMenuRequested(pos, tabBar()->tabAt(pos)); emit contextMenuRequested(pos, tabBar()->tabAt(pos));
......
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