mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-14 02:52:12 +01:00
[TabBar] Use contextMenuEvent instead of customContextMenu signals
This commit is contained in:
parent
5f8ac0b70a
commit
d1754094b8
|
@ -54,7 +54,6 @@ TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget)
|
||||||
, m_activeTabWidth(0)
|
, m_activeTabWidth(0)
|
||||||
{
|
{
|
||||||
setObjectName("tabbar");
|
setObjectName("tabbar");
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
||||||
setElideMode(Qt::ElideRight);
|
setElideMode(Qt::ElideRight);
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
setTabsClosable(false);
|
setTabsClosable(false);
|
||||||
|
@ -65,7 +64,6 @@ TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget)
|
||||||
setMovable(true);
|
setMovable(true);
|
||||||
|
|
||||||
connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
|
connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
|
||||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
|
||||||
|
|
||||||
m_tabPreviewShowTimer = new QTimer(this);
|
m_tabPreviewShowTimer = new QTimer(this);
|
||||||
m_tabPreviewShowTimer->setInterval(300);
|
m_tabPreviewShowTimer->setInterval(300);
|
||||||
|
@ -130,62 +128,6 @@ void TabBar::setVisible(bool visible)
|
||||||
ComboTabBar::setVisible(visible);
|
ComboTabBar::setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabBar::contextMenuRequested(const QPoint &position)
|
|
||||||
{
|
|
||||||
int index = tabAt(position);
|
|
||||||
m_clickedTab = index;
|
|
||||||
|
|
||||||
QMenu menu;
|
|
||||||
menu.addAction(IconProvider::newTabIcon(), tr("&New tab"), m_window, SLOT(addTab()));
|
|
||||||
menu.addSeparator();
|
|
||||||
if (index != -1) {
|
|
||||||
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
|
|
||||||
if (!webTab) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_window->weView(m_clickedTab)->isLoading()) {
|
|
||||||
menu.addAction(QIcon::fromTheme(QSL("process-stop")), tr("&Stop Tab"), this, SLOT(stopTab()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
menu.addAction(QIcon::fromTheme(QSL("view-refresh")), tr("&Reload Tab"), this, SLOT(reloadTab()));
|
|
||||||
}
|
|
||||||
|
|
||||||
menu.addAction(QIcon::fromTheme("tab-duplicate"), tr("&Duplicate Tab"), this, SLOT(duplicateTab()));
|
|
||||||
|
|
||||||
if (count() > 1 && !webTab->isPinned()) {
|
|
||||||
menu.addAction(QIcon::fromTheme("tab-detach"), tr("D&etach Tab"), this, SLOT(detachTab()));
|
|
||||||
}
|
|
||||||
|
|
||||||
menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab()));
|
|
||||||
menu.addSeparator();
|
|
||||||
menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
|
|
||||||
menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab()));
|
|
||||||
menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
|
|
||||||
menu.addSeparator();
|
|
||||||
menu.addAction(m_window->action(QSL("Other/RestoreClosedTab")));
|
|
||||||
menu.addSeparator();
|
|
||||||
menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent()));
|
|
||||||
menu.addAction(QIcon::fromTheme("window-close"), tr("Cl&ose"), this, SLOT(closeTab()));
|
|
||||||
menu.addSeparator();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
|
|
||||||
menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
|
|
||||||
menu.addSeparator();
|
|
||||||
menu.addAction(m_window->action(QSL("Other/RestoreClosedTab")));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(m_tabWidget->canRestoreTab());
|
|
||||||
|
|
||||||
// Prevent choosing first option with double rightclick
|
|
||||||
const QPoint pos = mapToGlobal(position);
|
|
||||||
QPoint p(pos.x(), pos.y() + 1);
|
|
||||||
menu.exec(p);
|
|
||||||
|
|
||||||
m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabBar::overflowChanged(bool overflowed)
|
void TabBar::overflowChanged(bool overflowed)
|
||||||
{
|
{
|
||||||
// Make sure close buttons on inactive tabs are hidden
|
// Make sure close buttons on inactive tabs are hidden
|
||||||
|
@ -373,6 +315,62 @@ void TabBar::showCloseButton(int index)
|
||||||
insertCloseButton(index);
|
insertCloseButton(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabBar::contextMenuEvent(QContextMenuEvent* event)
|
||||||
|
{
|
||||||
|
int index = tabAt(event->pos());
|
||||||
|
m_clickedTab = index;
|
||||||
|
|
||||||
|
QMenu menu;
|
||||||
|
menu.addAction(IconProvider::newTabIcon(), tr("&New tab"), m_window, SLOT(addTab()));
|
||||||
|
menu.addSeparator();
|
||||||
|
if (index != -1) {
|
||||||
|
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
|
||||||
|
if (!webTab) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_window->weView(m_clickedTab)->isLoading()) {
|
||||||
|
menu.addAction(QIcon::fromTheme(QSL("process-stop")), tr("&Stop Tab"), this, SLOT(stopTab()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
menu.addAction(QIcon::fromTheme(QSL("view-refresh")), tr("&Reload Tab"), this, SLOT(reloadTab()));
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.addAction(QIcon::fromTheme("tab-duplicate"), tr("&Duplicate Tab"), this, SLOT(duplicateTab()));
|
||||||
|
|
||||||
|
if (count() > 1 && !webTab->isPinned()) {
|
||||||
|
menu.addAction(QIcon::fromTheme("tab-detach"), tr("D&etach Tab"), this, SLOT(detachTab()));
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab()));
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
|
||||||
|
menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab()));
|
||||||
|
menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addAction(m_window->action(QSL("Other/RestoreClosedTab")));
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent()));
|
||||||
|
menu.addAction(QIcon::fromTheme("window-close"), tr("Cl&ose"), this, SLOT(closeTab()));
|
||||||
|
menu.addSeparator();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
|
||||||
|
menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
|
||||||
|
menu.addSeparator();
|
||||||
|
menu.addAction(m_window->action(QSL("Other/RestoreClosedTab")));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(m_tabWidget->canRestoreTab());
|
||||||
|
|
||||||
|
// Prevent choosing first option with double rightclick
|
||||||
|
const QPoint pos = event->globalPos();
|
||||||
|
QPoint p(pos.x(), pos.y() + 1);
|
||||||
|
menu.exec(p);
|
||||||
|
|
||||||
|
m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
void TabBar::hideCloseButton(int index)
|
void TabBar::hideCloseButton(int index)
|
||||||
{
|
{
|
||||||
if (!validIndex(index) || tabsClosable()) {
|
if (!validIndex(index) || tabsClosable()) {
|
||||||
|
|
|
@ -60,7 +60,6 @@ signals:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void currentTabChanged(int index);
|
void currentTabChanged(int index);
|
||||||
void contextMenuRequested(const QPoint &position);
|
|
||||||
void overflowChanged(bool overflowed);
|
void overflowChanged(bool overflowed);
|
||||||
|
|
||||||
void reloadTab() { emit reloadTab(m_clickedTab); }
|
void reloadTab() { emit reloadTab(m_clickedTab); }
|
||||||
|
@ -88,6 +87,7 @@ private:
|
||||||
void hideCloseButton(int index);
|
void hideCloseButton(int index);
|
||||||
void showCloseButton(int index);
|
void showCloseButton(int index);
|
||||||
|
|
||||||
|
void contextMenuEvent(QContextMenuEvent* event);
|
||||||
void mouseDoubleClickEvent(QMouseEvent* event);
|
void mouseDoubleClickEvent(QMouseEvent* event);
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
void mouseMoveEvent(QMouseEvent* event);
|
void mouseMoveEvent(QMouseEvent* event);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user