forked from qt-creator/qt-creator
Application Output: Add middle click closes tab feature
Task-number: QTCREATORBUG-12804 Change-Id: If370056cd0cda1f02558cbd02134a12877d5ce3d Reviewed-by: Robert Loehning <robert.loehning@digia.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -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));
|
||||||
|
|||||||
Reference in New Issue
Block a user