1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Enable closing tab by middle clicking in the tab list menu

This commit is contained in:
Charles 2013-06-14 17:28:38 +07:00 committed by nowrep
parent 98fac13f85
commit 9e476bfbc2
2 changed files with 30 additions and 3 deletions

View File

@ -35,7 +35,6 @@
#include <QTimer>
#include <QMovie>
#include <QMenu>
#include <QMimeData>
#include <QStackedWidget>
#include <QMouseEvent>
@ -95,6 +94,19 @@ void AddTabButton::dropEvent(QDropEvent* event)
}
}
void MenuTabs::mouseReleaseEvent(QMouseEvent* event)
{
if (event->button() == Qt::MiddleButton) {
QAction* action = actionAt(event->pos());
if (action) {
emit closeTab(action->data().toInt());
action->setEnabled(false);
event->accept();
}
}
QMenu::mouseReleaseEvent(event);
}
TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
: QTabWidget(parent)
, p_QupZilla(mainClass)
@ -126,7 +138,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
m_buttonListTabs = new ToolButton(this);
m_buttonListTabs->setObjectName("tabwidget-button-opentabs");
m_menuTabs = new QMenu(this);
m_menuTabs = new MenuTabs(this);
m_buttonListTabs->setMenu(m_menuTabs);
m_buttonListTabs->setPopupMode(QToolButton::InstantPopup);
m_buttonListTabs->setToolTip(tr("List of tabs"));
@ -137,6 +149,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
connect(m_buttonAddTab, SIGNAL(clicked()), p_QupZilla, SLOT(addTab()));
connect(m_menuTabs, SIGNAL(aboutToShow()), this, SLOT(aboutToShowClosedTabsMenu()));
connect(m_menuTabs, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
loadSettings();
}

View File

@ -21,6 +21,7 @@
#include <QTabWidget>
#include <QUrl>
#include <QNetworkRequest>
#include <QMenu>
#include "toolbutton.h"
#include "qz_namespace.h"
@ -50,6 +51,19 @@ private:
TabWidget* m_tabWidget;
};
class QT_QUPZILLA_EXPORT MenuTabs : public QMenu
{
Q_OBJECT
public:
explicit MenuTabs(QWidget *parent = 0) : QMenu(parent) {}
signals:
void closeTab(int);
private:
void mouseReleaseEvent(QMouseEvent* event);
};
class QT_QUPZILLA_EXPORT TabWidget : public QTabWidget
{
Q_OBJECT
@ -151,7 +165,7 @@ private:
bool m_isRestoringState;
TabBar* m_tabBar;
QMenu* m_menuTabs;
MenuTabs* m_menuTabs;
ToolButton* m_buttonListTabs;
AddTabButton* m_buttonAddTab;
ClosedTabsManager* m_closedTabsManager;