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