mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
VerticalTabs: Handle Ctrl+Tab switching tabs in tree order
This commit is contained in:
parent
ee2e1e9f78
commit
bbbe136346
@ -83,10 +83,9 @@ void TabListView::adjustStyleOption(QStyleOptionViewItem *option)
|
|||||||
} else if (model()->rowCount() == 1) {
|
} else if (model()->rowCount() == 1) {
|
||||||
option->viewItemPosition = QStyleOptionViewItem::OnlyOne;
|
option->viewItemPosition = QStyleOptionViewItem::OnlyOne;
|
||||||
} else {
|
} else {
|
||||||
const QRect rect = visualRect(index);
|
if (!indexBefore(index).isValid()) {
|
||||||
if (!indexAt(QPoint(rect.x() - rect.width() / 2, rect.y())).isValid()) {
|
|
||||||
option->viewItemPosition = QStyleOptionViewItem::Beginning;
|
option->viewItemPosition = QStyleOptionViewItem::Beginning;
|
||||||
} else if (!indexAt(QPoint(rect.x() + rect.width() / 2, rect.y())).isValid()) {
|
} else if (!indexAfter(index).isValid()) {
|
||||||
option->viewItemPosition = QStyleOptionViewItem::End;
|
option->viewItemPosition = QStyleOptionViewItem::End;
|
||||||
} else {
|
} else {
|
||||||
option->viewItemPosition = QStyleOptionViewItem::Middle;
|
option->viewItemPosition = QStyleOptionViewItem::Middle;
|
||||||
@ -94,6 +93,24 @@ void TabListView::adjustStyleOption(QStyleOptionViewItem *option)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndex TabListView::indexAfter(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
const QRect rect = visualRect(index);
|
||||||
|
return indexAt(QPoint(rect.right() + rect.width() / 2, rect.y()));
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex TabListView::indexBefore(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid()) {
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
const QRect rect = visualRect(index);
|
||||||
|
return indexAt(QPoint(rect.left() - rect.width() / 2, rect.y()));
|
||||||
|
}
|
||||||
|
|
||||||
void TabListView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
void TabListView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||||
{
|
{
|
||||||
if (current.data(TabModel::CurrentTabRole).toBool()) {
|
if (current.data(TabModel::CurrentTabRole).toBool()) {
|
||||||
|
@ -34,6 +34,9 @@ public:
|
|||||||
void updateIndex(const QModelIndex &index);
|
void updateIndex(const QModelIndex &index);
|
||||||
void adjustStyleOption(QStyleOptionViewItem *option);
|
void adjustStyleOption(QStyleOptionViewItem *option);
|
||||||
|
|
||||||
|
QModelIndex indexAfter(const QModelIndex &index) const;
|
||||||
|
QModelIndex indexBefore(const QModelIndex &index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override;
|
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override;
|
||||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
|
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
|
||||||
|
@ -19,7 +19,10 @@
|
|||||||
#include "verticaltabsplugin.h"
|
#include "verticaltabsplugin.h"
|
||||||
#include "verticaltabswidget.h"
|
#include "verticaltabswidget.h"
|
||||||
|
|
||||||
|
#include "tabwidget.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
VerticalTabsController::VerticalTabsController(VerticalTabsPlugin *plugin)
|
VerticalTabsController::VerticalTabsController(VerticalTabsPlugin *plugin)
|
||||||
: SideBarInterface(plugin)
|
: SideBarInterface(plugin)
|
||||||
@ -47,5 +50,24 @@ QWidget *VerticalTabsController::createSideBarWidget(BrowserWindow *window)
|
|||||||
connect(m_plugin, &VerticalTabsPlugin::viewTypeChanged, widget, &VerticalTabsWidget::setViewType);
|
connect(m_plugin, &VerticalTabsPlugin::viewTypeChanged, widget, &VerticalTabsWidget::setViewType);
|
||||||
connect(m_plugin, &VerticalTabsPlugin::styleSheetChanged, widget, &VerticalTabsWidget::setStyleSheet);
|
connect(m_plugin, &VerticalTabsPlugin::styleSheetChanged, widget, &VerticalTabsWidget::setStyleSheet);
|
||||||
|
|
||||||
|
m_widgets[window] = widget;
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VerticalTabsController::handleKeyPress(QKeyEvent *event, TabWidget *tabWidget)
|
||||||
|
{
|
||||||
|
if (event->key() == Qt::Key_Tab && event->modifiers() == Qt::ControlModifier) {
|
||||||
|
VerticalTabsWidget *widget = m_widgets.value(tabWidget->browserWindow());
|
||||||
|
if (widget) {
|
||||||
|
widget->switchToNextTab();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (event->key() == Qt::Key_Backtab && event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) {
|
||||||
|
VerticalTabsWidget *widget = m_widgets.value(tabWidget->browserWindow());
|
||||||
|
if (widget) {
|
||||||
|
widget->switchToPreviousTab();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -17,9 +17,17 @@
|
|||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
#include "sidebarinterface.h"
|
#include "sidebarinterface.h"
|
||||||
|
|
||||||
|
class QKeyEvent;
|
||||||
|
|
||||||
|
class TabWidget;
|
||||||
|
|
||||||
class VerticalTabsPlugin;
|
class VerticalTabsPlugin;
|
||||||
|
class VerticalTabsWidget;
|
||||||
|
|
||||||
class VerticalTabsController : public SideBarInterface
|
class VerticalTabsController : public SideBarInterface
|
||||||
{
|
{
|
||||||
@ -31,6 +39,9 @@ public:
|
|||||||
QAction *createMenuAction() override;
|
QAction *createMenuAction() override;
|
||||||
QWidget *createSideBarWidget(BrowserWindow *window) override;
|
QWidget *createSideBarWidget(BrowserWindow *window) override;
|
||||||
|
|
||||||
|
bool handleKeyPress(QKeyEvent *event, TabWidget *tabWidget);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VerticalTabsPlugin *m_plugin;
|
VerticalTabsPlugin *m_plugin;
|
||||||
|
QHash<BrowserWindow*, QPointer<VerticalTabsWidget>> m_widgets;
|
||||||
};
|
};
|
||||||
|
@ -63,6 +63,8 @@ void VerticalTabsPlugin::init(InitState state, const QString &settingsPath)
|
|||||||
m_controller = new VerticalTabsController(this);
|
m_controller = new VerticalTabsController(this);
|
||||||
SideBarManager::addSidebar(QSL("VerticalTabs"), m_controller);
|
SideBarManager::addSidebar(QSL("VerticalTabs"), m_controller);
|
||||||
|
|
||||||
|
QZ_REGISTER_EVENT_HANDLER(PluginProxy::KeyPressHandler);
|
||||||
|
|
||||||
setWebTabBehavior(m_addChildBehavior);
|
setWebTabBehavior(m_addChildBehavior);
|
||||||
loadStyleSheet(m_theme);
|
loadStyleSheet(m_theme);
|
||||||
|
|
||||||
@ -103,6 +105,14 @@ void VerticalTabsPlugin::showSettings(QWidget *parent)
|
|||||||
settings->exec();
|
settings->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VerticalTabsPlugin::keyPress(const Qz::ObjectName &type, QObject *obj, QKeyEvent *event)
|
||||||
|
{
|
||||||
|
if (type == Qz::ON_TabWidget) {
|
||||||
|
return m_controller->handleKeyPress(event, static_cast<TabWidget*>(obj));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
VerticalTabsPlugin::ViewType VerticalTabsPlugin::viewType() const
|
VerticalTabsPlugin::ViewType VerticalTabsPlugin::viewType() const
|
||||||
{
|
{
|
||||||
return m_viewType;
|
return m_viewType;
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
bool testPlugin() override;
|
bool testPlugin() override;
|
||||||
QTranslator* getTranslator(const QString &locale) override;
|
QTranslator* getTranslator(const QString &locale) override;
|
||||||
void showSettings(QWidget *parent = nullptr) override;
|
void showSettings(QWidget *parent = nullptr) override;
|
||||||
|
bool keyPress(const Qz::ObjectName &type, QObject *obj, QKeyEvent *event) override;
|
||||||
|
|
||||||
enum ViewType {
|
enum ViewType {
|
||||||
TabListView,
|
TabListView,
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
#include "tablistview.h"
|
#include "tablistview.h"
|
||||||
#include "tabfiltermodel.h"
|
#include "tabfiltermodel.h"
|
||||||
|
|
||||||
|
#include "webtab.h"
|
||||||
#include "tabmodel.h"
|
#include "tabmodel.h"
|
||||||
#include "toolbutton.h"
|
#include "toolbutton.h"
|
||||||
#include "tabtreemodel.h"
|
#include "tabtreemodel.h"
|
||||||
|
#include "tabbedwebview.h"
|
||||||
#include "browserwindow.h"
|
#include "browserwindow.h"
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@ -36,7 +38,7 @@ VerticalTabsWidget::VerticalTabsWidget(BrowserWindow *window)
|
|||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
TabListView *m_pinnedView = new TabListView(this);
|
m_pinnedView = new TabListView(this);
|
||||||
TabFilterModel *model = new TabFilterModel(m_pinnedView);
|
TabFilterModel *model = new TabFilterModel(m_pinnedView);
|
||||||
model->setFilterPinnedTabs(false);
|
model->setFilterPinnedTabs(false);
|
||||||
model->setSourceModel(m_window->tabModel());
|
model->setSourceModel(m_window->tabModel());
|
||||||
@ -86,3 +88,61 @@ void VerticalTabsWidget::setViewType(VerticalTabsPlugin::ViewType type)
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VerticalTabsWidget::switchToNextTab()
|
||||||
|
{
|
||||||
|
WebTab *tab = nextTab();
|
||||||
|
if (tab) {
|
||||||
|
tab->makeCurrentTab();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VerticalTabsWidget::switchToPreviousTab()
|
||||||
|
{
|
||||||
|
WebTab *tab = previousTab();
|
||||||
|
if (tab) {
|
||||||
|
tab->makeCurrentTab();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WebTab *VerticalTabsWidget::nextTab() const
|
||||||
|
{
|
||||||
|
QModelIndex next;
|
||||||
|
if (m_window->weView()->webTab()->isPinned()) {
|
||||||
|
next = m_pinnedView->indexAfter(m_pinnedView->currentIndex());
|
||||||
|
if (!next.isValid()) {
|
||||||
|
next = m_normalView->model()->index(0, 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
next = m_normalView->indexBelow(m_normalView->currentIndex());
|
||||||
|
if (!next.isValid()) {
|
||||||
|
next = m_pinnedView->model()->index(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return next.data(TabModel::WebTabRole).value<WebTab*>();
|
||||||
|
}
|
||||||
|
|
||||||
|
WebTab *VerticalTabsWidget::previousTab() const
|
||||||
|
{
|
||||||
|
QModelIndex previous;
|
||||||
|
if (m_window->weView()->webTab()->isPinned()) {
|
||||||
|
previous = m_pinnedView->indexBefore(m_pinnedView->currentIndex());
|
||||||
|
if (!previous.isValid()) {
|
||||||
|
previous = m_normalView->model()->index(m_normalView->model()->rowCount() - 1, 0);
|
||||||
|
while (previous.isValid()) {
|
||||||
|
const QModelIndex below = m_normalView->indexBelow(previous);
|
||||||
|
if (below.isValid()) {
|
||||||
|
previous = below;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
previous = m_normalView->indexAbove(m_normalView->currentIndex());
|
||||||
|
if (!previous.isValid()) {
|
||||||
|
previous = m_pinnedView->model()->index(m_pinnedView->model()->rowCount() - 1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return previous.data(TabModel::WebTabRole).value<WebTab*>();
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "verticaltabsplugin.h"
|
#include "verticaltabsplugin.h"
|
||||||
|
|
||||||
|
class WebTab;
|
||||||
class BrowserWindow;
|
class BrowserWindow;
|
||||||
class TabTreeModel;
|
class TabTreeModel;
|
||||||
|
|
||||||
@ -35,7 +36,13 @@ public:
|
|||||||
|
|
||||||
void setViewType(VerticalTabsPlugin::ViewType type);
|
void setViewType(VerticalTabsPlugin::ViewType type);
|
||||||
|
|
||||||
|
void switchToNextTab();
|
||||||
|
void switchToPreviousTab();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
WebTab *nextTab() const;
|
||||||
|
WebTab *previousTab() const;
|
||||||
|
|
||||||
BrowserWindow *m_window;
|
BrowserWindow *m_window;
|
||||||
TabListView *m_pinnedView;
|
TabListView *m_pinnedView;
|
||||||
TabTreeView *m_normalView;
|
TabTreeView *m_normalView;
|
||||||
|
Loading…
Reference in New Issue
Block a user