diff options
| author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-15 15:48:28 +0100 | 
|---|---|---|
| committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-15 15:48:28 +0100 | 
| commit | 4066c1f093b572b949f9b1f5b0dc1c1a646b7552 (patch) | |
| tree | d1b220e65ac6e8c527c107dc7386a38afb930374 /src/subwindow | |
| parent | Add SaveSessionDialog (diff) | |
| download | smolbote-4066c1f093b572b949f9b1f5b0dc1c1a646b7552.tar.xz | |
Move tab actions to Subwindow menu
Diffstat (limited to 'src/subwindow')
| -rw-r--r-- | src/subwindow/subwindow.cpp | 55 | ||||
| -rw-r--r-- | src/subwindow/subwindow.h | 15 | ||||
| -rw-r--r-- | src/subwindow/tabwidget.cpp | 4 | 
3 files changed, 45 insertions, 29 deletions
| 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<QString>("subwindow.shortcuts.close").value()), this); -    connect(closeTab_shortcut, &QShortcut::activated, this, [=]() { -        tabWidget->deleteTab(tabWidget->currentIndex()); -    }); - -    auto *leftTab_shortcut = new QShortcut(QKeySequence(config->value<QString>("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<QString>("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<QString>("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<QString>("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<QString>("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<WebView *>(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<TabData>(data)); +} + +SubWindow::TabData SubWindow::tabData(int index) const +{ +    return tabWidget->tabBar()->tabData(index).value<TabData>(); +} +  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(); diff --git a/src/subwindow/subwindow.h b/src/subwindow/subwindow.h index 1fc0097..eb7973f 100644 --- a/src/subwindow/subwindow.h +++ b/src/subwindow/subwindow.h @@ -22,9 +22,16 @@ class SubWindow : public QMdiSubWindow      Q_OBJECT  public: +    struct TabData +    { +        bool closeLocked = false; +        bool refreshLocked = false; +    }; +      explicit SubWindow(const Configuration *config, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());      ~SubWindow() override; +    int currentTabIndex() const;      WebView *currentView();      WebView *view(int index) const;      int tabCount() const; @@ -32,13 +39,19 @@ public:      void setProfile(WebProfile *profile);      WebProfile *profile() const; +    void setTabData(TabData &data, int index); +    TabData tabData(int index) const; +  signals:      void currentViewChanged(WebView *view);      void showStatusMessage(const QString &message, int timeout = 0);  public slots:      int addTab(const QUrl &url = QUrl(), WebProfile *profile = nullptr); +    void closeTab(int index); +      void setCurrentTab(int index); +    void moveTab(int from, int to);      int restoreLastTab();      void restoreTabMenu(QMenu *menu); @@ -51,4 +64,6 @@ private:      QMetaObject::Connection linkHoveredConnection;  }; +Q_DECLARE_METATYPE(SubWindow::TabData) +  #endif // SMOLBOTE_SUBWINDOW_H diff --git a/src/subwindow/tabwidget.cpp b/src/subwindow/tabwidget.cpp index c635aee..58e9b03 100644 --- a/src/subwindow/tabwidget.cpp +++ b/src/subwindow/tabwidget.cpp @@ -15,6 +15,7 @@  #include <QTabBar>  #include "webprofile.h"  #include <QWebEngineHistory> +#include "subwindow.h"  inline WebView *createViewFromInfo(TabWidget::TabInformation &tab, QWidget *parent)  { @@ -93,6 +94,9 @@ int TabWidget::addTab(WebView *view)          this->setTabIcon(idx, icon);      }); +    SubWindow::TabData data; +    tabBar()->setTabData(idx, QVariant::fromValue<SubWindow::TabData>(data)); +      return idx;  } | 
