From 4066c1f093b572b949f9b1f5b0dc1c1a646b7552 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 15 Dec 2018 15:48:28 +0100 Subject: Move tab actions to Subwindow menu --- src/subwindow/subwindow.cpp | 55 +++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'src/subwindow/subwindow.cpp') diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp index 4beba49..a83cf14 100644 --- a/src/subwindow/subwindow.cpp +++ b/src/subwindow/subwindow.cpp @@ -61,34 +61,6 @@ SubWindow::SubWindow(const Configuration *config, QWidget *parent, Qt::WindowFla menu->insertSeparator(firstAction); } - // general actions - auto *closeTab_shortcut = new QShortcut(QKeySequence(config->value("subwindow.shortcuts.close").value()), this); - connect(closeTab_shortcut, &QShortcut::activated, this, [=]() { - tabWidget->deleteTab(tabWidget->currentIndex()); - }); - - auto *leftTab_shortcut = new QShortcut(QKeySequence(config->value("subwindow.shortcuts.left").value()), this); - connect(leftTab_shortcut, &QShortcut::activated, this, [=]() { - tabWidget->setCurrentIndex(qMax(0, tabWidget->currentIndex() - 1)); - }); - - auto *moveTabLeft_shortcut = new QShortcut(QKeySequence(config->value("subwindow.shortcuts.moveLeft").value()), this); - connect(moveTabLeft_shortcut, &QShortcut::activated, this, [=]() { - auto idx = tabWidget->currentIndex(); - tabWidget->tabBar()->moveTab(idx, idx - 1); - }); - - auto *rightTab_shortcut = new QShortcut(QKeySequence(config->value("subwindow.shortcuts.right").value()), this); - connect(rightTab_shortcut, &QShortcut::activated, this, [=]() { - tabWidget->setCurrentIndex(qMin(tabWidget->currentIndex() + 1, tabWidget->count() - 1)); - }); - - auto *moveTabRight_shortcut = new QShortcut(QKeySequence(config->value("subwindow.shortcuts.moveRight").value()), this); - connect(moveTabRight_shortcut, &QShortcut::activated, this, [=]() { - auto idx = tabWidget->currentIndex(); - tabWidget->tabBar()->moveTab(idx, idx + 1); - }); - auto *fullScreen_shortcut = new QShortcut(QKeySequence(config->value("subwindow.shortcuts.fullscreen").value()), this); connect(fullScreen_shortcut, &QShortcut::activated, this, [=]() { auto *w = this->window(); @@ -130,6 +102,11 @@ SubWindow::~SubWindow() delete tabWidget; } +int SubWindow::currentTabIndex() const +{ + return tabWidget->currentIndex(); +} + WebView *SubWindow::currentView() { return qobject_cast(tabWidget->currentWidget()); @@ -164,6 +141,16 @@ WebProfile *SubWindow::profile() const return m_profile; } +void SubWindow::setTabData(TabData &data, int index) +{ + tabWidget->tabBar()->setTabData(index, QVariant::fromValue(data)); +} + +SubWindow::TabData SubWindow::tabData(int index) const +{ + return tabWidget->tabBar()->tabData(index).value(); +} + int SubWindow::addTab(const QUrl &url, WebProfile *profile) { Q_CHECK_PTR(m_profile); @@ -179,12 +166,22 @@ int SubWindow::addTab(const QUrl &url, WebProfile *profile) return tabWidget->addTab(view); } +void SubWindow::closeTab(int index) +{ + tabWidget->deleteTab(index); +} + void SubWindow::setCurrentTab(int index) { - if(index > 0) + if(index >= 0) tabWidget->setCurrentIndex(index); } +void SubWindow::moveTab(int from, int to) +{ + tabWidget->tabBar()->moveTab(from, to); +} + int SubWindow::restoreLastTab() { return tabWidget->restoreLastTab(); -- cgit v1.2.1