From 6e1d411f9218645851f0dde54688739390b62736 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 3 Apr 2020 21:23:35 +0300 Subject: Remove QMdiArea in MainWindow Kconfig: Change About Dialog shortcut default to F1 (was Ctrl+H) Change close current tab shortcut to Ctrl+W (was Ctrl+X) MainWindow: automatically close window when last subwindow is closed MenuBar: remove Tile/Cascade subwindows actions add show/hide/close subwindow actions SubWindow: remove Subwindow menu shortcut (was F1 by default) add close shortcut (default Ctrl+Shift+W) Minor fixes: Fix PKGBUILD sources --- src/subwindow/subwindow.cpp | 79 ++++++++++++++------------------------------- src/subwindow/subwindow.h | 73 ++++++++++++++++++++++++++++++----------- 2 files changed, 79 insertions(+), 73 deletions(-) (limited to 'src/subwindow') diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp index c6e156e..58acee6 100644 --- a/src/subwindow/subwindow.cpp +++ b/src/subwindow/subwindow.cpp @@ -8,29 +8,31 @@ #include "subwindow.h" #include "browser.h" -#include "tabwidget.h" +#include "configuration.h" +#include "webengine/webprofile.h" #include "webengine/webview.h" #include -#include -#include -#include +#include +#include #include #include -#include +#include #include #include -#include "configuration.h" -#include "webengine/webprofile.h" +#include SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags flags) - : QMdiSubWindow(parent, flags) + : QWidget(parent, flags) , tabWidget(new TabWidget(this)) { // delete this window when it closes - setAttribute(Qt::WA_DeleteOnClose, true); + //setAttribute(Qt::WA_DeleteOnClose, true); - resize(800, 600); - setWidget(tabWidget); + auto *layout = new QVBoxLayout; + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(tabWidget); + setLayout(layout); m_profile = WebProfile::defaultProfile(); @@ -74,31 +76,6 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags flags) }); } -SubWindow::~SubWindow() -{ - delete tabWidget; -} - -int SubWindow::currentTabIndex() const -{ - return tabWidget->currentIndex(); -} - -WebView *SubWindow::currentView() -{ - return qobject_cast(tabWidget->currentWidget()); -} - -WebView *SubWindow::view(int index) const -{ - return qobject_cast(tabWidget->widget(index)); -} - -int SubWindow::tabCount() const -{ - return tabWidget->count(); -} - void SubWindow::setProfile(WebProfile *profile) { if(profile == nullptr) { @@ -113,11 +90,6 @@ void SubWindow::setProfile(WebProfile *profile) } } -WebProfile *SubWindow::profile() const -{ - return m_profile; -} - void SubWindow::setTabData(TabData &data, int index) { tabWidget->tabBar()->setTabData(index, QVariant::fromValue(data)); @@ -143,28 +115,25 @@ int SubWindow::addTab(const QUrl &url, WebProfile *profile) return tabWidget->addTab(view); } -void SubWindow::closeTab(int index) -{ - tabWidget->removeTab(index); -} - -void SubWindow::setCurrentTab(int index) +void SubWindow::moveTab(int from, int to) { - if(index >= 0) - tabWidget->setCurrentIndex(index); + tabWidget->tabBar()->moveTab(from, to); } -void SubWindow::moveTab(int from, int to) +void SubWindow::closeEvent(QCloseEvent *event) { - tabWidget->tabBar()->moveTab(from, to); + emit aboutToClose(); + event->accept(); } -int SubWindow::restoreLastTab() +void SubWindow::hideEvent(QHideEvent *event) { - return tabWidget->restoreLastTab(); + emit visibilityChanged(false); + event->accept(); } -void SubWindow::restoreTabMenu(QMenu *menu) +void SubWindow::showEvent(QShowEvent *event) { - tabWidget->restoreTabMenu(menu); + emit visibilityChanged(true); + event->accept(); } diff --git a/src/subwindow/subwindow.h b/src/subwindow/subwindow.h index c4f96c0..8343a9b 100644 --- a/src/subwindow/subwindow.h +++ b/src/subwindow/subwindow.h @@ -9,51 +9,88 @@ #ifndef SMOLBOTE_SUBWINDOW_H #define SMOLBOTE_SUBWINDOW_H -#include +#include "tabwidget.h" +#include "webengine/webview.h" +#include #include -#include +#include -class TabWidget; -class WebView; class WebProfile; -class SubWindow : public QMdiSubWindow +class SubWindow : public QWidget { Q_OBJECT public: - struct TabData - { + struct TabData { bool closeLocked = false; bool refreshLocked = false; }; explicit SubWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); - ~SubWindow() override; + ~SubWindow() = default; + + [[nodiscard]] int currentTabIndex() const + { + return tabWidget->currentIndex(); + } + + [[nodiscard]] WebView *currentView() + { + return qobject_cast(tabWidget->currentWidget()); + } + + [[nodiscard]] WebView *view(int index) const + { + return qobject_cast(tabWidget->widget(index)); + } - int currentTabIndex() const; - WebView *currentView(); - WebView *view(int index) const; - int tabCount() const; + [[nodiscard]] int tabCount() const + { + return tabWidget->count(); + } void setProfile(WebProfile *profile); - WebProfile *profile() const; + [[nodiscard]] WebProfile *profile() const + { + return m_profile; + } void setTabData(TabData &data, int index); - TabData tabData(int index) const; + [[nodiscard]] TabData tabData(int index) const; signals: void currentViewChanged(WebView *view); void showStatusMessage(const QString &message, int timeout = 0); + void visibilityChanged(bool isVisible); + void aboutToClose(); public slots: int addTab(const QUrl &url = QUrl(), WebProfile *profile = nullptr); - void closeTab(int index); + void closeTab(int index) + { + tabWidget->removeTab(index); + } - void setCurrentTab(int index); + void setCurrentTab(int index) + { + if(index >= 0) + tabWidget->setCurrentIndex(index); + } void moveTab(int from, int to); - int restoreLastTab(); - void restoreTabMenu(QMenu *menu); + int restoreLastTab() + { + return tabWidget->restoreLastTab(); + } + void restoreTabMenu(QMenu *menu) + { + tabWidget->restoreTabMenu(menu); + } + +protected: + void closeEvent(QCloseEvent *event); + void hideEvent(QHideEvent *event); + void showEvent(QShowEvent *event); private: WebProfile *m_profile; -- cgit v1.2.1