1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

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.
This commit is contained in:
srazi 2015-10-18 17:26:12 +03:30 committed by David Rosca
parent ceca46e836
commit 33553a049a
10 changed files with 290 additions and 84 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -22,6 +22,9 @@
#include "pluginproxy.h"
#include "mainapplication.h"
#include "sidebar.h"
#include "tabwidget.h"
#include "tabbar.h"
#include "tabmanagersettings.h"
#include <QInputDialog>
#include <QTranslator>
@ -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 <s.r.alavizadeh@gmail.com>";
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("<p>Please select view type:<br />"
"<b>Note:</b> The \"<i>Window</i>\" 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);
}

View File

@ -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

View File

@ -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();
}

View File

@ -0,0 +1,27 @@
#ifndef TABMANAGERSETTINGS_H
#define TABMANAGERSETTINGS_H
#include <QDialog>
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

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TabManagerSettings</class>
<widget class="QDialog" name="TabManagerSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>371</width>
<height>237</height>
</rect>
</property>
<property name="windowTitle">
<string>Tab Manager Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>View</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Please select view type:</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="sidebarRadio">
<property name="text">
<string>SideBar</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="windowRadio">
<property name="text">
<string>Window</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Note:&lt;/span&gt; The &amp;quot;Window&amp;quot; type is recommended for managing lots of windows/tabs.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Use TabManager plugin as replacement for main TabBar.</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -21,6 +21,7 @@
#include "browserwindow.h"
#include "tabwidget.h"
#include "mainapplication.h"
#include "tabbar.h"
#include <QDesktopWidget>
#include <QStatusBar>
@ -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();
}

View File

@ -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<BrowserWindow*, QWidget*> m_statusBarIcons;