From 33553a049ac3fd20682fe3a4a9a8aaf6a860a385 Mon Sep 17 00:00:00 2001 From: srazi Date: Sun, 18 Oct 2015 17:26:12 +0330 Subject: [PATCH] TabManager: Add an option to use it as main tabbar replacement. - Note: in `TabBar::setVisible()` we didn't need to check `(visible && m_window->isFullScreen())` because tabbar's visibility in fullscreen mode is managed by m_navigationContainer. --- src/lib/tabwidget/tabbar.cpp | 11 +- src/lib/tabwidget/tabbar.h | 3 + src/plugins/TabManager/TabManager.pro | 9 +- src/plugins/TabManager/tabmanagerplugin.cpp | 139 ++++++++++++------ src/plugins/TabManager/tabmanagerplugin.h | 21 ++- src/plugins/TabManager/tabmanagersettings.cpp | 32 ++++ src/plugins/TabManager/tabmanagersettings.h | 27 ++++ src/plugins/TabManager/tabmanagersettings.ui | 91 ++++++++++++ .../TabManager/tabmanagerwidgetcontroller.cpp | 30 +--- .../TabManager/tabmanagerwidgetcontroller.h | 11 +- 10 files changed, 290 insertions(+), 84 deletions(-) create mode 100644 src/plugins/TabManager/tabmanagersettings.cpp create mode 100644 src/plugins/TabManager/tabmanagersettings.h create mode 100644 src/plugins/TabManager/tabmanagersettings.ui diff --git a/src/lib/tabwidget/tabbar.cpp b/src/lib/tabwidget/tabbar.cpp index 36510a434..37b3712a4 100644 --- a/src/lib/tabwidget/tabbar.cpp +++ b/src/lib/tabwidget/tabbar.cpp @@ -47,6 +47,7 @@ TabBar::TabBar(BrowserWindow* window, TabWidget* tabWidget) , m_clickedTab(0) , m_normalTabWidth(0) , m_activeTabWidth(0) + , m_forceHidden(false) { setObjectName("tabbar"); setElideMode(Qt::ElideRight); @@ -97,7 +98,9 @@ TabWidget* TabBar::tabWidget() const void TabBar::setVisible(bool visible) { - if (visible && m_window->isFullScreen()) { + if (m_forceHidden) { + hideTabPreview(false); + ComboTabBar::setVisible(false); return; } @@ -109,6 +112,12 @@ void TabBar::setVisible(bool visible) ComboTabBar::setVisible(visible); } +void TabBar::setForceHidden(bool hidden) +{ + m_forceHidden = hidden; + setVisible(!m_forceHidden); +} + void TabBar::overflowChanged(bool overflowed) { // Make sure close buttons on inactive tabs are hidden diff --git a/src/lib/tabwidget/tabbar.h b/src/lib/tabwidget/tabbar.h index 16b57daeb..780c7ef1d 100644 --- a/src/lib/tabwidget/tabbar.h +++ b/src/lib/tabwidget/tabbar.h @@ -38,6 +38,7 @@ public: TabWidget* tabWidget() const; void setVisible(bool visible); + void setForceHidden(bool hidden); void overrideTabTextColor(int index, QColor color); void restoreTabTextColor(int index); @@ -108,6 +109,8 @@ private: QColor m_originalTabTextColor; QPoint m_dragStartPosition; + + bool m_forceHidden; }; #endif // TABBAR_H diff --git a/src/plugins/TabManager/TabManager.pro b/src/plugins/TabManager/TabManager.pro index c2bff69ac..9d2800be2 100644 --- a/src/plugins/TabManager/TabManager.pro +++ b/src/plugins/TabManager/TabManager.pro @@ -4,16 +4,19 @@ os2: TARGET = TabManPl SOURCES += tabmanagerplugin.cpp \ tabmanagerwidget.cpp \ - tabmanagerwidgetcontroller.cpp + tabmanagerwidgetcontroller.cpp \ + tabmanagersettings.cpp HEADERS += tabmanagerplugin.h \ tabmanagerwidget.h \ - tabmanagerwidgetcontroller.h + tabmanagerwidgetcontroller.h \ + tabmanagersettings.h RESOURCES += tabmanagerplugin.qrc FORMS += \ - tabmanagerwidget.ui + tabmanagerwidget.ui \ + tabmanagersettings.ui TRANSLATIONS = \ translations/fa_IR.ts diff --git a/src/plugins/TabManager/tabmanagerplugin.cpp b/src/plugins/TabManager/tabmanagerplugin.cpp index b2cc18267..f8e363687 100644 --- a/src/plugins/TabManager/tabmanagerplugin.cpp +++ b/src/plugins/TabManager/tabmanagerplugin.cpp @@ -22,6 +22,9 @@ #include "pluginproxy.h" #include "mainapplication.h" #include "sidebar.h" +#include "tabwidget.h" +#include "tabbar.h" +#include "tabmanagersettings.h" #include #include @@ -36,7 +39,9 @@ TabManagerPlugin::TabManagerPlugin() : QObject() , m_controller(0) , m_tabManagerWidget(0) + , m_viewType(Undefined) , m_initState(false) + , m_asTabBarReplacement(false) { } @@ -46,7 +51,7 @@ PluginSpec TabManagerPlugin::pluginSpec() spec.name = "Tab Manager"; spec.info = "Simple yet powerful tab manager for QupZilla"; spec.description = "Adds ability to managing tabs and windows"; - spec.version = "0.4.1"; + spec.version = "0.5.0"; spec.author = "Razi Alavizadeh "; spec.icon = QPixmap(":tabmanager/data/tabmanager.png"); spec.hasSettings = true; @@ -59,7 +64,7 @@ void TabManagerPlugin::init(InitState state, const QString &settingsPath) Q_UNUSED(state) m_controller = new TabManagerWidgetController(this); - connect(mApp->plugins(), SIGNAL(mainWindowCreated(BrowserWindow*)), m_controller, SLOT(mainWindowCreated(BrowserWindow*))); + connect(mApp->plugins(), SIGNAL(mainWindowCreated(BrowserWindow*)), this, SLOT(mainWindowCreated(BrowserWindow*))); connect(mApp->plugins(), SIGNAL(mainWindowDeleted(BrowserWindow*)), m_controller, SLOT(mainWindowDeleted(BrowserWindow*))); connect(mApp->plugins(), SIGNAL(webPageCreated(WebPage*)), m_controller, SIGNAL(requestRefreshTree())); connect(mApp->plugins(), SIGNAL(webPageDeleted(WebPage*)), m_controller, SIGNAL(requestRefreshTree(WebPage*))); @@ -71,21 +76,19 @@ void TabManagerPlugin::init(InitState state, const QString &settingsPath) QSettings settings(s_settingsPath + QL1S("/tabmanager.ini"), QSettings::IniFormat); settings.beginGroup("View"); m_controller->setGroupType(TabManagerWidget::GroupType(settings.value("GroupType", TabManagerWidget::GroupByWindow).toInt())); - m_controller->setViewType(TabManagerWidgetController::ViewType(settings.value("ViewType", TabManagerWidgetController::ShowAsWindow).toInt())); + m_viewType = ViewType(settings.value("ViewType", ShowAsWindow).toInt()); + m_asTabBarReplacement = settings.value("AsTabBarReplacement", false).toBool(); settings.endGroup(); + setAsTabBarReplacement(m_asTabBarReplacement); insertManagerWidget(); } void TabManagerPlugin::unload() { - // save settings - QSettings settings(s_settingsPath + QL1S("/tabmanager.ini"), QSettings::IniFormat); - settings.beginGroup("View"); - settings.setValue("GroupType", m_controller->groupType()); - settings.setValue("ViewType", m_controller->viewType()); - settings.endGroup(); + saveSettings(); + setTabBarVisible(true); removeManagerWidget(); delete m_controller; @@ -105,40 +108,13 @@ QTranslator* TabManagerPlugin::getTranslator(const QString &locale) void TabManagerPlugin::showSettings(QWidget* parent) { - bool ok; - QString viewType = QInputDialog::getItem(parent, tr("Tab Manager View Type"), - tr("

Please select view type:
" - "Note: The \"Window\" type is recommended for managing lots of windows/tabs") - , QStringList() << tr("SideBar") << tr("Window") - , m_controller->viewType(), false, &ok, Qt::WindowStaysOnTopHint); - TabManagerWidgetController::ViewType type; - if (viewType == tr("SideBar")) { - type = TabManagerWidgetController::ShowAsSideBar; - } - else { - type = TabManagerWidgetController::ShowAsWindow; - } - - if (ok && type != m_controller->viewType()) { - removeManagerWidget(); - m_controller->setViewType(type); - insertManagerWidget(); - - if (type == TabManagerWidgetController::ShowAsSideBar) { - mApp->getWindow()->sideBarManager()->showSideBar("TabManager"); - } - else if (type == TabManagerWidgetController::ShowAsWindow) { - // add statusbar icon - foreach (BrowserWindow* window, mApp->windows()) { - m_controller->addStatusBarIcon(window); - } - } - } + TabManagerSettings* settings = new TabManagerSettings(this, parent); + settings->exec(); } void TabManagerPlugin::populateExtensionsMenu(QMenu* menu) { - if (m_controller->viewType() == TabManagerWidgetController::ShowAsWindow) { + if (viewType() == ShowAsWindow) { QAction* showAction = m_controller->createMenuAction(); showAction->setParent(menu); showAction->setCheckable(false); @@ -149,10 +125,10 @@ void TabManagerPlugin::populateExtensionsMenu(QMenu* menu) void TabManagerPlugin::insertManagerWidget() { - if (m_controller->viewType() == TabManagerWidgetController::ShowAsSideBar) { + if (viewType() == ShowAsSideBar) { SideBarManager::addSidebar("TabManager", m_controller); } - else if (m_controller->viewType() == TabManagerWidgetController::ShowAsWindow) { + else if (viewType() == ShowAsWindow) { if (!m_tabManagerWidget) { m_tabManagerWidget = m_controller->createTabManagerWidget(mApp->getWindow(), 0, true); m_tabManagerWidget->setWindowFlags(Qt::Window); @@ -161,19 +137,43 @@ void TabManagerPlugin::insertManagerWidget() if (m_initState) { foreach (BrowserWindow* window, mApp->windows()) { - m_controller->mainWindowCreated(window, false); + mainWindowCreated(window, false); + } + m_initState = false; + } +} + +void TabManagerPlugin::mainWindowCreated(BrowserWindow* window, bool refresh) +{ + if (window) { + window->tabWidget()->tabBar()->setForceHidden(m_asTabBarReplacement); + + if (m_viewType == ShowAsWindow) { + m_controller->addStatusBarIcon(window); } - m_initState = false; + connect(window->tabWidget(), SIGNAL(currentChanged(int)), m_controller, SIGNAL(requestRefreshTree())); + connect(window->tabWidget(), SIGNAL(pinStateChanged(int,bool)), m_controller, SIGNAL(pinStateChanged(int,bool))); + } + + if (refresh) { + m_controller->emitRefreshTree(); + } +} + +void TabManagerPlugin::setTabBarVisible(bool visible) +{ + foreach (BrowserWindow* window, mApp->windows()) { + window->tabWidget()->tabBar()->setForceHidden(!visible); } } void TabManagerPlugin::removeManagerWidget() { - if (m_controller->viewType() == TabManagerWidgetController::ShowAsSideBar) { + if (viewType() == ShowAsSideBar) { SideBarManager::removeSidebar("TabManager"); } - else if (m_controller->viewType() == TabManagerWidgetController::ShowAsWindow) { + else if (viewType() == ShowAsWindow) { // remove statusbar icon foreach (BrowserWindow* window, mApp->windows()) { m_controller->removeStatusBarIcon(window); @@ -185,7 +185,56 @@ void TabManagerPlugin::removeManagerWidget() } } + +TabManagerPlugin::ViewType TabManagerPlugin::viewType() +{ + return m_viewType; +} + +void TabManagerPlugin::setViewType(ViewType type) +{ + if (m_viewType != type) { + removeManagerWidget(); + m_viewType = type; + insertManagerWidget(); + + if (!m_initState) { + if (m_viewType == ShowAsSideBar) { + mApp->getWindow()->sideBarManager()->showSideBar("TabManager"); + } + else if (m_viewType == ShowAsWindow) { + // add statusbar icon + foreach (BrowserWindow* window, mApp->windows()) { + m_controller->addStatusBarIcon(window); + } + } + } + } +} + QString TabManagerPlugin::settingsPath() { return s_settingsPath; } + +void TabManagerPlugin::saveSettings() +{ + QSettings settings(s_settingsPath + QL1S("/tabmanager.ini"), QSettings::IniFormat); + settings.beginGroup("View"); + settings.setValue("GroupType", m_controller->groupType()); + settings.setValue("ViewType", viewType()); + settings.setValue("AsTabBarReplacement", asTabBarReplacement()); + settings.endGroup(); +} + +bool TabManagerPlugin::asTabBarReplacement() const +{ + return m_asTabBarReplacement; +} + +void TabManagerPlugin::setAsTabBarReplacement(bool yes) +{ + m_asTabBarReplacement = yes; + setTabBarVisible(!m_asTabBarReplacement); +} + diff --git a/src/plugins/TabManager/tabmanagerplugin.h b/src/plugins/TabManager/tabmanagerplugin.h index 51a623b49..bf0b70d3f 100644 --- a/src/plugins/TabManager/tabmanagerplugin.h +++ b/src/plugins/TabManager/tabmanagerplugin.h @@ -48,19 +48,38 @@ public: void showSettings(QWidget* parent = 0); void populateExtensionsMenu(QMenu* menu); + enum ViewType { + ShowAsSideBar = 0, + ShowAsWindow = 1, + Undefined = -1 + }; + void removeManagerWidget(); + ViewType viewType(); + void setViewType(ViewType type); + static QString settingsPath(); + void saveSettings(); + + bool asTabBarReplacement() const; + void setAsTabBarReplacement(bool yes); public slots: void insertManagerWidget(); +private slots: + void mainWindowCreated(BrowserWindow* window, bool refresh = true); + private: + void setTabBarVisible(bool visible); + TabManagerWidgetController* m_controller; TabManagerWidget* m_tabManagerWidget; static QString s_settingsPath; - QString m_viewType; + ViewType m_viewType; bool m_initState; + bool m_asTabBarReplacement; }; #endif // TABMANAGERPLUGIN_H diff --git a/src/plugins/TabManager/tabmanagersettings.cpp b/src/plugins/TabManager/tabmanagersettings.cpp new file mode 100644 index 000000000..a565db43a --- /dev/null +++ b/src/plugins/TabManager/tabmanagersettings.cpp @@ -0,0 +1,32 @@ +#include "tabmanagersettings.h" +#include "ui_tabmanagersettings.h" +#include "tabmanagerplugin.h" + +TabManagerSettings::TabManagerSettings(TabManagerPlugin* plugin, QWidget *parent) : + QDialog(parent), + ui(new Ui::TabManagerSettings), + m_plugin(plugin) +{ + setAttribute(Qt::WA_DeleteOnClose); + ui->setupUi(this); + + ui->sidebarRadio->setChecked(m_plugin->viewType() == TabManagerPlugin::ShowAsSideBar); + ui->windowRadio->setChecked(m_plugin->viewType() != TabManagerPlugin::ShowAsSideBar); + ui->checkBox->setChecked(m_plugin->asTabBarReplacement()); + + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); +} + +TabManagerSettings::~TabManagerSettings() +{ + delete ui; +} + +void TabManagerSettings::accept() +{ + m_plugin->setViewType(ui->sidebarRadio->isChecked() ? TabManagerPlugin::ShowAsSideBar : TabManagerPlugin::ShowAsWindow); + m_plugin->setAsTabBarReplacement(ui->checkBox->isChecked()); + + QDialog::accept(); +} diff --git a/src/plugins/TabManager/tabmanagersettings.h b/src/plugins/TabManager/tabmanagersettings.h new file mode 100644 index 000000000..c0c1b0178 --- /dev/null +++ b/src/plugins/TabManager/tabmanagersettings.h @@ -0,0 +1,27 @@ +#ifndef TABMANAGERSETTINGS_H +#define TABMANAGERSETTINGS_H + +#include + +namespace Ui { +class TabManagerSettings; +} +class TabManagerPlugin; + +class TabManagerSettings : public QDialog +{ + Q_OBJECT + +public: + explicit TabManagerSettings(TabManagerPlugin* plugin, QWidget *parent = 0); + ~TabManagerSettings(); + +public slots: + void accept(); + +private: + Ui::TabManagerSettings* ui; + TabManagerPlugin* m_plugin; +}; + +#endif // TABMANAGERSETTINGS_H diff --git a/src/plugins/TabManager/tabmanagersettings.ui b/src/plugins/TabManager/tabmanagersettings.ui new file mode 100644 index 000000000..ebbc4eadb --- /dev/null +++ b/src/plugins/TabManager/tabmanagersettings.ui @@ -0,0 +1,91 @@ + + + TabManagerSettings + + + + 0 + 0 + 371 + 237 + + + + Tab Manager Settings + + + + + + View + + + + + + Please select view type: + + + + + + + SideBar + + + + + + + Window + + + + + + + <html><head/><body><p><span style=" font-weight:600;">Note:</span> The &quot;Window&quot; type is recommended for managing lots of windows/tabs.</p></body></html> + + + true + + + + + + + + + + Use TabManager plugin as replacement for main TabBar. + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/src/plugins/TabManager/tabmanagerwidgetcontroller.cpp b/src/plugins/TabManager/tabmanagerwidgetcontroller.cpp index d708b4c39..994eaff5b 100644 --- a/src/plugins/TabManager/tabmanagerwidgetcontroller.cpp +++ b/src/plugins/TabManager/tabmanagerwidgetcontroller.cpp @@ -21,6 +21,7 @@ #include "browserwindow.h" #include "tabwidget.h" #include "mainapplication.h" +#include "tabbar.h" #include #include @@ -32,7 +33,6 @@ TabManagerWidgetController::TabManagerWidgetController(QObject* parent) : SideBarInterface(parent) , m_defaultTabManager(0) - , m_viewType(ShowAsWindow) , m_groupType(TabManagerWidget::GroupByWindow) { } @@ -92,16 +92,6 @@ QWidget* TabManagerWidgetController::createStatusBarIcon(BrowserWindow* mainWind return icon; } -TabManagerWidgetController::ViewType TabManagerWidgetController::viewType() -{ - return m_viewType; -} - -void TabManagerWidgetController::setViewType(ViewType type) -{ - m_viewType = type; -} - TabManagerWidget::GroupType TabManagerWidgetController::groupType() { return m_groupType; @@ -163,19 +153,6 @@ void TabManagerWidgetController::removeStatusBarIcon(BrowserWindow* window) } } -void TabManagerWidgetController::mainWindowCreated(BrowserWindow* window, bool refresh) -{ - if (window) { - addStatusBarIcon(window); - connect(window->tabWidget(), SIGNAL(currentChanged(int)), this, SIGNAL(requestRefreshTree())); - connect(window->tabWidget(), SIGNAL(pinStateChanged(int,bool)), this, SIGNAL(pinStateChanged(int,bool))); - } - - if (refresh) { - emit requestRefreshTree(); - } -} - void TabManagerWidgetController::mainWindowDeleted(BrowserWindow* window) { removeStatusBarIcon(window); @@ -231,3 +208,8 @@ void TabManagerWidgetController::showSideBySide() defaultTabManager()->activateWindow(); defaultTabManager()->raise(); } + +void TabManagerWidgetController::emitRefreshTree() +{ + emit requestRefreshTree(); +} diff --git a/src/plugins/TabManager/tabmanagerwidgetcontroller.h b/src/plugins/TabManager/tabmanagerwidgetcontroller.h index bcdd46600..713c143ce 100644 --- a/src/plugins/TabManager/tabmanagerwidgetcontroller.h +++ b/src/plugins/TabManager/tabmanagerwidgetcontroller.h @@ -27,11 +27,6 @@ class TabManagerWidgetController : public SideBarInterface { Q_OBJECT public: - enum ViewType { - ShowAsSideBar = 0, - ShowAsWindow = 1 - }; - explicit TabManagerWidgetController(QObject* parent = 0); ~TabManagerWidgetController(); @@ -41,9 +36,6 @@ public: QWidget* createStatusBarIcon(BrowserWindow* mainWindow); - ViewType viewType(); - void setViewType(ViewType type); - TabManagerWidget::GroupType groupType(); TabManagerWidget* createTabManagerWidget(BrowserWindow* mainClass, QWidget* parent = 0, bool defaultWidget = false); @@ -54,14 +46,13 @@ public: public slots: void setGroupType(TabManagerWidget::GroupType type); - void mainWindowCreated(BrowserWindow* window, bool refresh = true); void mainWindowDeleted(BrowserWindow* window); void raiseTabManager(); void showSideBySide(); + void emitRefreshTree(); private: TabManagerWidget* m_defaultTabManager; - ViewType m_viewType; TabManagerWidget::GroupType m_groupType; QHash m_statusBarIcons;