mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
VerticalTabs: Add Tab Tree context menu with tree actions
With Close Tree + Expand/Collapse all actions.
This commit is contained in:
parent
67e82e8923
commit
6aee383a9c
@ -86,6 +86,16 @@ void TabTreeView::setTabsInOrder(bool enable)
|
||||
m_tabsInOrder = enable;
|
||||
}
|
||||
|
||||
bool TabTreeView::haveTreeModel() const
|
||||
{
|
||||
return m_haveTreeModel;
|
||||
}
|
||||
|
||||
void TabTreeView::setHaveTreeModel(bool enable)
|
||||
{
|
||||
m_haveTreeModel = enable;
|
||||
}
|
||||
|
||||
void TabTreeView::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
QTreeView::setModel(model);
|
||||
@ -296,6 +306,7 @@ bool TabTreeView::viewportEvent(QEvent *event)
|
||||
options |= TabContextMenu::ShowCloseOtherTabsActions;
|
||||
}
|
||||
TabContextMenu menu(tabIndex, m_window, options);
|
||||
addMenuActions(&menu, index);
|
||||
menu.exec(ce->globalPos());
|
||||
break;
|
||||
}
|
||||
@ -333,3 +344,44 @@ TabTreeView::DelegateButton TabTreeView::buttonAt(const QPoint &pos, const QMode
|
||||
}
|
||||
return NoButton;
|
||||
}
|
||||
|
||||
void TabTreeView::addMenuActions(QMenu *menu, const QModelIndex &index) const
|
||||
{
|
||||
if (!m_haveTreeModel) {
|
||||
return;
|
||||
}
|
||||
|
||||
menu->addSeparator();
|
||||
QMenu *m = menu->addMenu(tr("Tab Tree"));
|
||||
|
||||
if (index.isValid() && model()->rowCount(index) > 0) {
|
||||
QPersistentModelIndex pindex = index;
|
||||
m->addAction(tr("Close Tree"), this, [=]() {
|
||||
QVector<WebTab*> tabs;
|
||||
reverseTraverse(pindex, [&](const QModelIndex &index) {
|
||||
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
|
||||
if (tab) {
|
||||
tabs.append(tab);
|
||||
}
|
||||
});
|
||||
for (WebTab *tab : qAsConst(tabs)) {
|
||||
tab->closeTab();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
m->addSeparator();
|
||||
m->addAction(tr("Expand All"), this, &TabTreeView::expandAll);
|
||||
m->addAction(tr("Collapse All"), this, &TabTreeView::collapseAll);
|
||||
}
|
||||
|
||||
void TabTreeView::reverseTraverse(const QModelIndex &root, std::function<void(const QModelIndex&)> callback) const
|
||||
{
|
||||
if (!root.isValid()) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < model()->rowCount(root); ++i) {
|
||||
reverseTraverse(model()->index(i, 0, root), callback);
|
||||
}
|
||||
callback(root);
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#include <QTreeView>
|
||||
|
||||
class QMenu;
|
||||
|
||||
class BrowserWindow;
|
||||
|
||||
class TabTreeDelegate;
|
||||
@ -38,6 +40,9 @@ public:
|
||||
bool areTabsInOrder() const;
|
||||
void setTabsInOrder(bool enable);
|
||||
|
||||
bool haveTreeModel() const;
|
||||
void setHaveTreeModel(bool enable);
|
||||
|
||||
void setModel(QAbstractItemModel *model) override;
|
||||
|
||||
void updateIndex(const QModelIndex &index);
|
||||
@ -59,6 +64,8 @@ private:
|
||||
|
||||
void initView();
|
||||
DelegateButton buttonAt(const QPoint &pos, const QModelIndex &index) const;
|
||||
void addMenuActions(QMenu *menu, const QModelIndex &index) const;
|
||||
void reverseTraverse(const QModelIndex &root, std::function<void(const QModelIndex&)> callback) const;
|
||||
|
||||
BrowserWindow *m_window;
|
||||
TabTreeDelegate *m_delegate;
|
||||
@ -66,6 +73,7 @@ private:
|
||||
QPersistentModelIndex m_pressedIndex;
|
||||
QPersistentModelIndex m_hoveredIndex;
|
||||
bool m_tabsInOrder = false;
|
||||
bool m_haveTreeModel = false;
|
||||
int m_backgroundIndentation = 0;
|
||||
QString m_expandedSessionKey;
|
||||
bool m_initializing = false;
|
||||
|
@ -81,6 +81,7 @@ void VerticalTabsWidget::setViewType(VerticalTabsPlugin::ViewType type)
|
||||
model->setSourceModel(m_window->tabModel());
|
||||
m_normalView->setModel(model);
|
||||
m_normalView->setTabsInOrder(true);
|
||||
m_normalView->setHaveTreeModel(false);
|
||||
break;
|
||||
|
||||
case VerticalTabsPlugin::TabTreeView:
|
||||
@ -89,6 +90,7 @@ void VerticalTabsWidget::setViewType(VerticalTabsPlugin::ViewType type)
|
||||
model->setSourceModel(m_treeModel);
|
||||
m_normalView->setModel(model);
|
||||
m_normalView->setTabsInOrder(false);
|
||||
m_normalView->setHaveTreeModel(true);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user