mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
TabContextMenu: Add Options flags
This commit is contained in:
parent
825ee7ea96
commit
ea432a7de7
|
@ -347,7 +347,7 @@ void TabBar::contextMenuEvent(QContextMenuEvent* event)
|
|||
|
||||
int index = tabAt(event->pos());
|
||||
|
||||
TabContextMenu menu(index, Qt::Horizontal, m_window, m_tabWidget);
|
||||
TabContextMenu menu(index, m_window);
|
||||
|
||||
// Prevent choosing first option with double rightclick
|
||||
const QPoint pos = event->globalPos();
|
||||
|
|
|
@ -27,25 +27,24 @@
|
|||
#include "checkboxdialog.h"
|
||||
|
||||
|
||||
TabContextMenu::TabContextMenu(int index, Qt::Orientation orientation, BrowserWindow* window, TabWidget* tabWidget, bool showCloseOtherTabs)
|
||||
TabContextMenu::TabContextMenu(int index, BrowserWindow *window, Options options)
|
||||
: QMenu()
|
||||
, m_clickedTab(index)
|
||||
, m_tabsOrientation(orientation)
|
||||
, m_window(window)
|
||||
, m_tabWidget(tabWidget)
|
||||
, m_showCloseOtherTabs(showCloseOtherTabs)
|
||||
, m_options(options)
|
||||
{
|
||||
setObjectName("tabcontextmenu");
|
||||
|
||||
connect(this, SIGNAL(tabCloseRequested(int)), m_tabWidget->tabBar(), SIGNAL(tabCloseRequested(int)));
|
||||
connect(this, SIGNAL(reloadTab(int)), m_tabWidget, SLOT(reloadTab(int)));
|
||||
connect(this, SIGNAL(stopTab(int)), m_tabWidget, SLOT(stopTab(int)));
|
||||
connect(this, SIGNAL(closeAllButCurrent(int)), m_tabWidget, SLOT(closeAllButCurrent(int)));
|
||||
connect(this, SIGNAL(closeToRight(int)), m_tabWidget, SLOT(closeToRight(int)));
|
||||
connect(this, SIGNAL(closeToLeft(int)), m_tabWidget, SLOT(closeToLeft(int)));
|
||||
connect(this, SIGNAL(duplicateTab(int)), m_tabWidget, SLOT(duplicateTab(int)));
|
||||
connect(this, SIGNAL(loadTab(int)), m_tabWidget, SLOT(loadTab(int)));
|
||||
connect(this, SIGNAL(unloadTab(int)), m_tabWidget, SLOT(unloadTab(int)));
|
||||
TabWidget *tabWidget = m_window->tabWidget();
|
||||
connect(this, SIGNAL(tabCloseRequested(int)), tabWidget->tabBar(), SIGNAL(tabCloseRequested(int)));
|
||||
connect(this, SIGNAL(reloadTab(int)), tabWidget, SLOT(reloadTab(int)));
|
||||
connect(this, SIGNAL(stopTab(int)), tabWidget, SLOT(stopTab(int)));
|
||||
connect(this, SIGNAL(closeAllButCurrent(int)), tabWidget, SLOT(closeAllButCurrent(int)));
|
||||
connect(this, SIGNAL(closeToRight(int)), tabWidget, SLOT(closeToRight(int)));
|
||||
connect(this, SIGNAL(closeToLeft(int)), tabWidget, SLOT(closeToLeft(int)));
|
||||
connect(this, SIGNAL(duplicateTab(int)), tabWidget, SLOT(duplicateTab(int)));
|
||||
connect(this, SIGNAL(loadTab(int)), tabWidget, SLOT(loadTab(int)));
|
||||
connect(this, SIGNAL(unloadTab(int)), tabWidget, SLOT(unloadTab(int)));
|
||||
|
||||
init();
|
||||
}
|
||||
|
@ -84,7 +83,7 @@ void TabContextMenu::closeAllButCurrent()
|
|||
|
||||
void TabContextMenu::closeToRight()
|
||||
{
|
||||
const QString label = m_tabsOrientation == Qt::Horizontal
|
||||
const QString label = m_options & HorizontalTabs
|
||||
? tr("Do you really want to close all tabs to the right?")
|
||||
: tr("Do you really want to close all tabs to the bottom?");
|
||||
|
||||
|
@ -95,7 +94,7 @@ void TabContextMenu::closeToRight()
|
|||
|
||||
void TabContextMenu::closeToLeft()
|
||||
{
|
||||
const QString label = m_tabsOrientation == Qt::Horizontal
|
||||
const QString label = m_options & HorizontalTabs
|
||||
? tr("Do you really want to close all tabs to the left?")
|
||||
: tr("Do you really want to close all tabs to the top?");
|
||||
|
||||
|
@ -106,8 +105,9 @@ void TabContextMenu::closeToLeft()
|
|||
|
||||
void TabContextMenu::init()
|
||||
{
|
||||
TabWidget *tabWidget = m_window->tabWidget();
|
||||
if (m_clickedTab != -1) {
|
||||
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
|
||||
WebTab* webTab = tabWidget->webTab(m_clickedTab);
|
||||
if (!webTab) {
|
||||
return;
|
||||
}
|
||||
|
@ -131,14 +131,14 @@ void TabContextMenu::init()
|
|||
}
|
||||
|
||||
addSeparator();
|
||||
addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
|
||||
addAction(tr("Re&load All Tabs"), tabWidget, SLOT(reloadAllTabs()));
|
||||
addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
|
||||
addSeparator();
|
||||
|
||||
if (m_showCloseOtherTabs) {
|
||||
if (m_options & ShowCloseOtherTabsActions) {
|
||||
addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent()));
|
||||
addAction(m_tabsOrientation == Qt::Horizontal ? tr("Close Tabs To The Right") : tr("Close Tabs To The Bottom"), this, SLOT(closeToRight()));
|
||||
addAction(m_tabsOrientation == Qt::Horizontal ? tr("Close Tabs To The Left") : tr("Close Tabs To The Top"), this, SLOT(closeToLeft()));
|
||||
addAction(m_options & HorizontalTabs ? tr("Close Tabs To The Right") : tr("Close Tabs To The Bottom"), this, SLOT(closeToRight()));
|
||||
addAction(m_options & HorizontalTabs ? tr("Close Tabs To The Left") : tr("Close Tabs To The Top"), this, SLOT(closeToLeft()));
|
||||
addSeparator();
|
||||
}
|
||||
|
||||
|
@ -147,19 +147,18 @@ void TabContextMenu::init()
|
|||
} else {
|
||||
addAction(IconProvider::newTabIcon(), tr("&New tab"), m_window, SLOT(addTab()));
|
||||
addSeparator();
|
||||
addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
|
||||
addAction(tr("Reloa&d All Tabs"), tabWidget, SLOT(reloadAllTabs()));
|
||||
addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
|
||||
addSeparator();
|
||||
addAction(m_window->action(QSL("Other/RestoreClosedTab")));
|
||||
}
|
||||
|
||||
m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(m_tabWidget->canRestoreTab());
|
||||
m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(tabWidget->canRestoreTab());
|
||||
}
|
||||
|
||||
void TabContextMenu::pinTab()
|
||||
{
|
||||
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
|
||||
|
||||
WebTab* webTab = m_window->tabWidget()->webTab(m_clickedTab);
|
||||
if (webTab) {
|
||||
webTab->togglePinned();
|
||||
}
|
||||
|
@ -167,8 +166,7 @@ void TabContextMenu::pinTab()
|
|||
|
||||
void TabContextMenu::muteTab()
|
||||
{
|
||||
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
|
||||
|
||||
WebTab* webTab = m_window->tabWidget()->webTab(m_clickedTab);
|
||||
if (webTab) {
|
||||
webTab->toggleMuted();
|
||||
}
|
||||
|
|
|
@ -28,8 +28,19 @@ class TabWidget;
|
|||
class FALKON_EXPORT TabContextMenu : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TabContextMenu(int index, Qt::Orientation orientation, BrowserWindow* window, TabWidget* tabWidget, bool showCloseOtherTabs = true);
|
||||
enum Option {
|
||||
InvalidOption = 0,
|
||||
HorizontalTabs = 1 << 0,
|
||||
VerticalTabs = 1 << 1,
|
||||
ShowCloseOtherTabsActions = 1 << 2,
|
||||
|
||||
DefaultOptions = HorizontalTabs | ShowCloseOtherTabsActions
|
||||
};
|
||||
Q_DECLARE_FLAGS(Options, Option)
|
||||
|
||||
explicit TabContextMenu(int index, BrowserWindow *window, Options options = DefaultOptions);
|
||||
|
||||
signals:
|
||||
void reloadTab(int index);
|
||||
|
@ -61,10 +72,8 @@ private:
|
|||
void init();
|
||||
|
||||
int m_clickedTab;
|
||||
Qt::Orientation m_tabsOrientation;
|
||||
BrowserWindow* m_window;
|
||||
TabWidget* m_tabWidget;
|
||||
bool m_showCloseOtherTabs;
|
||||
BrowserWindow *m_window;
|
||||
Options m_options = InvalidOption;
|
||||
};
|
||||
|
||||
#endif // TABCONTEXTMENU_H
|
||||
|
|
|
@ -288,7 +288,11 @@ void TabManagerWidget::customContextMenuRequested(const QPoint &pos)
|
|||
// if items are not grouped by Window then actions "Close Other Tabs",
|
||||
// "Close Tabs To The Bottom" and "Close Tabs To The Top"
|
||||
// are ambiguous and should be hidden.
|
||||
menu = new TabContextMenu(index, Qt::Vertical, mainWindow, mainWindow->tabWidget(), m_groupType == GroupByWindow);
|
||||
TabContextMenu::Options options = TabContextMenu::VerticalTabs;
|
||||
if (m_groupType == GroupByWindow) {
|
||||
options |= TabContextMenu::ShowCloseOtherTabsActions;
|
||||
}
|
||||
menu = new TabContextMenu(index, mainWindow, options);
|
||||
menu->addSeparator();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,9 @@
|
|||
#include <QToolTip>
|
||||
#include <QHoverEvent>
|
||||
|
||||
TabListView::TabListView(QWidget *parent)
|
||||
TabListView::TabListView(BrowserWindow *window, QWidget *parent)
|
||||
: QListView(parent)
|
||||
, m_window(window)
|
||||
{
|
||||
setDragEnabled(true);
|
||||
setAcceptDrops(true);
|
||||
|
@ -206,10 +207,9 @@ bool TabListView::viewportEvent(QEvent *event)
|
|||
QContextMenuEvent *ce = static_cast<QContextMenuEvent*>(event);
|
||||
const QModelIndex index = indexAt(ce->pos());
|
||||
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
|
||||
if (tab) {
|
||||
TabContextMenu menu(tab, Qt::Horizontal, false);
|
||||
menu.exec(ce->globalPos());
|
||||
}
|
||||
const int tabIndex = tab ? tab->tabIndex() : -1;
|
||||
TabContextMenu menu(tabIndex, m_window, TabContextMenu::HorizontalTabs);
|
||||
menu.exec(ce->globalPos());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include <QListView>
|
||||
|
||||
class BrowserWindow;
|
||||
|
||||
class TabListDelegate;
|
||||
|
||||
class TabListView : public QListView
|
||||
|
@ -26,7 +28,7 @@ class TabListView : public QListView
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TabListView(QWidget *parent = nullptr);
|
||||
explicit TabListView(BrowserWindow *window, QWidget *parent = nullptr);
|
||||
|
||||
bool isHidingWhenEmpty() const;
|
||||
void setHideWhenEmpty(bool enable);
|
||||
|
@ -52,6 +54,7 @@ private:
|
|||
DelegateButton buttonAt(const QPoint &pos, const QModelIndex &index) const;
|
||||
void updateVisibility();
|
||||
|
||||
BrowserWindow *m_window;
|
||||
TabListDelegate *m_delegate;
|
||||
DelegateButton m_pressedButton = NoButton;
|
||||
QModelIndex m_pressedIndex;
|
||||
|
|
|
@ -27,8 +27,9 @@
|
|||
#include <QToolTip>
|
||||
#include <QHoverEvent>
|
||||
|
||||
TabTreeView::TabTreeView(QWidget *parent)
|
||||
TabTreeView::TabTreeView(BrowserWindow *window, QWidget *parent)
|
||||
: QTreeView(parent)
|
||||
, m_window(window)
|
||||
, m_expandedSessionKey(QSL("VerticalTabs-expanded"))
|
||||
{
|
||||
setDragEnabled(true);
|
||||
|
@ -289,10 +290,13 @@ bool TabTreeView::viewportEvent(QEvent *event)
|
|||
QContextMenuEvent *ce = static_cast<QContextMenuEvent*>(event);
|
||||
const QModelIndex index = indexAt(ce->pos());
|
||||
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
|
||||
if (tab) {
|
||||
TabContextMenu menu(tab, Qt::Vertical, m_tabsInOrder);
|
||||
menu.exec(ce->globalPos());
|
||||
const int tabIndex = tab ? tab->tabIndex() : -1;
|
||||
TabContextMenu::Options options = TabContextMenu::VerticalTabs;
|
||||
if (m_tabsInOrder) {
|
||||
options |= TabContextMenu::ShowCloseOtherTabsActions;
|
||||
}
|
||||
TabContextMenu menu(tabIndex, m_window, options);
|
||||
menu.exec(ce->globalPos());
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include <QTreeView>
|
||||
|
||||
class BrowserWindow;
|
||||
|
||||
class TabTreeDelegate;
|
||||
|
||||
class TabTreeView : public QTreeView
|
||||
|
@ -27,7 +29,7 @@ class TabTreeView : public QTreeView
|
|||
Q_PROPERTY(int backgroundIndentation READ backgroundIndentation WRITE setBackgroundIndentation)
|
||||
|
||||
public:
|
||||
explicit TabTreeView(QWidget *parent = nullptr);
|
||||
explicit TabTreeView(BrowserWindow *window, QWidget *parent = nullptr);
|
||||
|
||||
int backgroundIndentation() const;
|
||||
void setBackgroundIndentation(int indentation);
|
||||
|
@ -58,6 +60,7 @@ private:
|
|||
void initView();
|
||||
DelegateButton buttonAt(const QPoint &pos, const QModelIndex &index) const;
|
||||
|
||||
BrowserWindow *m_window;
|
||||
TabTreeDelegate *m_delegate;
|
||||
DelegateButton m_pressedButton = NoButton;
|
||||
QPersistentModelIndex m_pressedIndex;
|
||||
|
|
|
@ -40,7 +40,7 @@ VerticalTabsWidget::VerticalTabsWidget(BrowserWindow *window)
|
|||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
m_pinnedView = new TabListView(this);
|
||||
m_pinnedView = new TabListView(m_window, this);
|
||||
TabFilterModel *model = new TabFilterModel(m_pinnedView);
|
||||
model->setFilterPinnedTabs(false);
|
||||
model->setRejectDropOnLastIndex(true);
|
||||
|
@ -48,7 +48,7 @@ VerticalTabsWidget::VerticalTabsWidget(BrowserWindow *window)
|
|||
m_pinnedView->setModel(model);
|
||||
m_pinnedView->setHideWhenEmpty(true);
|
||||
|
||||
m_normalView = new TabTreeView(this);
|
||||
m_normalView = new TabTreeView(m_window, this);
|
||||
m_pinnedView->setFocusProxy(m_normalView);
|
||||
|
||||
ToolButton *buttonAddTab = new ToolButton(this);
|
||||
|
|
Loading…
Reference in New Issue
Block a user