mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
TabManager: item based update.
This commit is contained in:
parent
06094cfc1c
commit
9cb5f106ef
|
@ -17,6 +17,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "tabmanagerdelegate.h"
|
||||
#include "tabmanagerwidget.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
|
@ -36,6 +37,7 @@ void TabManagerDelegate::paint(QPainter* painter, const QStyleOptionViewItem &op
|
|||
const QWidget* w = opt.widget;
|
||||
const QStyle* style = w ? w->style() : QApplication::style();
|
||||
const Qt::LayoutDirection direction = w ? w->layoutDirection() : QApplication::layoutDirection();
|
||||
const bool isActiveOrCaption = index.data(TabItem::ActiveOrCaptionRole).toBool();
|
||||
|
||||
const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text;
|
||||
|
||||
|
@ -125,6 +127,9 @@ void TabManagerDelegate::paint(QPainter* painter, const QStyleOptionViewItem &op
|
|||
painter->drawRect(textRect.adjusted(0, 0, -1, -1));
|
||||
}
|
||||
|
||||
if (isActiveOrCaption)
|
||||
opt.font.setBold(true);
|
||||
|
||||
painter->setFont(opt.font);
|
||||
viewItemDrawText(painter, &opt, textRect, opt.text, textPalette.color(colorRole), filterText);
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ void TabManagerPlugin::mainWindowCreated(BrowserWindow* window, bool refresh)
|
|||
}
|
||||
|
||||
connect(window->tabWidget(), SIGNAL(currentChanged(int)), m_controller, SIGNAL(requestRefreshTree()));
|
||||
connect(window->tabWidget(), SIGNAL(pinStateChanged(int,bool)), m_controller, SIGNAL(pinStateChanged(int,bool)));
|
||||
connect(window->tabWidget(), SIGNAL(pinStateChanged(int,bool)), m_controller, SIGNAL(requestRefreshTree()));
|
||||
}
|
||||
|
||||
if (refresh) {
|
||||
|
|
|
@ -169,11 +169,11 @@ void TabManagerWidget::refreshTree()
|
|||
}
|
||||
|
||||
for (int j = 0; j < winItem->childCount(); ++j) {
|
||||
QTreeWidgetItem* tabItem = winItem->child(j);
|
||||
if (tabItem->checkState(0) == Qt::Unchecked) {
|
||||
TabItem* tabItem = static_cast<TabItem*>(winItem->child(j));
|
||||
if (!tabItem || tabItem->checkState(0) == Qt::Unchecked) {
|
||||
continue;
|
||||
}
|
||||
selectedTabs << qvariant_cast<QWidget*>(tabItem->data(0, WebTabPointerRole));
|
||||
selectedTabs << tabItem->webTab();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,9 +196,9 @@ void TabManagerWidget::refreshTree()
|
|||
QTreeWidgetItem* winItem = ui->treeWidget->topLevelItem(i);
|
||||
|
||||
for (int j = 0; j < winItem->childCount(); ++j) {
|
||||
QTreeWidgetItem* tabItem = winItem->child(j);
|
||||
TabItem* tabItem = static_cast<TabItem*>(winItem->child(j));
|
||||
|
||||
if (selectedTabs.contains(qvariant_cast<QWidget*>(tabItem->data(0, WebTabPointerRole)))) {
|
||||
if (tabItem && selectedTabs.contains(tabItem->webTab())) {
|
||||
tabItem->setCheckState(0, Qt::Checked);
|
||||
}
|
||||
}
|
||||
|
@ -216,12 +216,13 @@ void TabManagerWidget::refreshTree()
|
|||
|
||||
void TabManagerWidget::onItemActivated(QTreeWidgetItem* item, int column)
|
||||
{
|
||||
if (!item) {
|
||||
TabItem* tabItem = static_cast<TabItem*>(item);
|
||||
if (!tabItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
BrowserWindow* mainWindow = qobject_cast<BrowserWindow*>(qvariant_cast<QWidget*>(item->data(0, BrowserWindowPointerRole)));
|
||||
QWidget* tabWidget = qvariant_cast<QWidget*>(item->data(0, WebTabPointerRole));
|
||||
BrowserWindow* mainWindow = tabItem->window();
|
||||
QWidget* tabWidget = tabItem->webTab();
|
||||
|
||||
if (column == 1) {
|
||||
if (item->childCount() > 0)
|
||||
|
@ -268,11 +269,11 @@ void TabManagerWidget::customContextMenuRequested(const QPoint &pos)
|
|||
{
|
||||
QMenu* menu = nullptr;
|
||||
|
||||
QTreeWidgetItem* item = ui->treeWidget->itemAt(pos);
|
||||
TabItem* item = static_cast<TabItem*>(ui->treeWidget->itemAt(pos));
|
||||
|
||||
if (item) {
|
||||
BrowserWindow* mainWindow = qobject_cast<BrowserWindow*>(qvariant_cast<QWidget*>(item->data(0, BrowserWindowPointerRole)));
|
||||
QWidget* tabWidget = qvariant_cast<QWidget*>(item->data(0, WebTabPointerRole));
|
||||
BrowserWindow* mainWindow = item->window();
|
||||
QWidget* tabWidget = item->webTab();
|
||||
|
||||
if (mainWindow && tabWidget) {
|
||||
int index = mainWindow->tabWidget()->indexOf(tabWidget);
|
||||
|
@ -351,8 +352,12 @@ void TabManagerWidget::filterChanged(const QString &filter, bool force)
|
|||
QTreeWidgetItem* parentItem = ui->treeWidget->topLevelItem(i);
|
||||
int visibleChildCount = 0;
|
||||
for (int j = 0; j < parentItem->childCount(); ++j) {
|
||||
QTreeWidgetItem* childItem = parentItem->child(j);
|
||||
if (childItem->text(0).contains(filterRegExp) || childItem->data(0, UrlRole).toString().simplified().contains(filterRegExp)) {
|
||||
TabItem* childItem = static_cast<TabItem*>(parentItem->child(j));
|
||||
if (!childItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (childItem->text(0).contains(filterRegExp) || childItem->webTab()->url().toString().simplified().contains(filterRegExp)) {
|
||||
++visibleChildCount;
|
||||
childItem->setHidden(false);
|
||||
}
|
||||
|
@ -446,13 +451,13 @@ void TabManagerWidget::processActions()
|
|||
}
|
||||
|
||||
for (int j = 0; j < winItem->childCount(); ++j) {
|
||||
QTreeWidgetItem* tabItem = winItem->child(j);
|
||||
if (tabItem->checkState(0) == Qt::Unchecked) {
|
||||
TabItem* tabItem = static_cast<TabItem*>(winItem->child(j));
|
||||
if (!tabItem || tabItem->checkState(0) == Qt::Unchecked) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BrowserWindow* mainWindow = qobject_cast<BrowserWindow*>(qvariant_cast<QWidget*>(tabItem->data(0, BrowserWindowPointerRole)));
|
||||
WebTab* webTab = qobject_cast<WebTab*>(qvariant_cast<QWidget*>(tabItem->data(0, WebTabPointerRole)));
|
||||
BrowserWindow* mainWindow = tabItem->window();
|
||||
WebTab* webTab = tabItem->webTab();
|
||||
|
||||
// current supported actions are not applied to pinned tabs
|
||||
if (webTab->isPinned()) {
|
||||
|
@ -597,15 +602,6 @@ bool TabManagerWidget::bookmarkSelectedTabs(const QHash<BrowserWindow*, WebTab*>
|
|||
return true;
|
||||
}
|
||||
|
||||
QTreeWidgetItem* TabManagerWidget::createEmptyItem(QTreeWidgetItem* parent, bool addToTree)
|
||||
{
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem(addToTree ? (parent ? parent : ui->treeWidget->invisibleRootItem()) : 0);
|
||||
item->setFlags(item->flags() | (parent ? Qt::ItemIsUserCheckable : Qt::ItemIsUserCheckable | Qt::ItemIsTristate));
|
||||
item->setCheckState(0, Qt::Unchecked);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
QTreeWidgetItem* TabManagerWidget::groupByDomainName(bool useHostName)
|
||||
{
|
||||
QTreeWidgetItem* currentTabItem = nullptr;
|
||||
|
@ -634,44 +630,29 @@ QTreeWidgetItem* TabManagerWidget::groupByDomainName(bool useHostName)
|
|||
QString domain = domainFromUrl(webTab->url(), useHostName);
|
||||
|
||||
if (!tabsGroupedByDomain.contains(domain)) {
|
||||
QTreeWidgetItem* groupItem = createEmptyItem(0, false);
|
||||
groupItem->setText(0, domain);
|
||||
groupItem->setToolTip(0, domain);
|
||||
QFont font = groupItem->font(0);
|
||||
font.setBold(true);
|
||||
groupItem->setFont(0, font);
|
||||
TabItem* groupItem = new TabItem(ui->treeWidget, 0, false);
|
||||
groupItem->setTitle(domain);
|
||||
groupItem->setIsActiveOrCaption(true);
|
||||
|
||||
tabsGroupedByDomain.insert(domain, groupItem);
|
||||
}
|
||||
|
||||
QTreeWidgetItem* groupItem = tabsGroupedByDomain.value(domain);
|
||||
|
||||
QTreeWidgetItem* tabItem = createEmptyItem(groupItem);
|
||||
TabItem* tabItem = new TabItem(ui->treeWidget, groupItem);
|
||||
tabItem->setBrowserWindow(mainWin);
|
||||
tabItem->setWebTab(webTab);
|
||||
|
||||
if (webTab == mainWin->weView()->webTab()) {
|
||||
QFont font = tabItem->font(0);
|
||||
font.setBold(true);
|
||||
tabItem->setFont(0, font);
|
||||
tabItem->setIsActiveOrCaption(true);
|
||||
|
||||
if (mainWin == getWindow())
|
||||
currentTabItem = tabItem;
|
||||
}
|
||||
if (!webTab->isLoading()) {
|
||||
if (!webTab->isPinned()) {
|
||||
tabItem->setIcon(0, webTab->icon());
|
||||
}
|
||||
else {
|
||||
tabItem->setIcon(0, QIcon(":tabmanager/data/tab-pinned.png"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
tabItem->setIcon(0, QIcon(":tabmanager/data/tab-loading.png"));
|
||||
}
|
||||
tabItem->setText(0, webTab->title());
|
||||
tabItem->setToolTip(0, webTab->title());
|
||||
|
||||
tabItem->setData(0, UrlRole, webTab->url().toString());
|
||||
tabItem->setData(0, WebTabPointerRole, QVariant::fromValue(qobject_cast<QWidget*>(webTab)));
|
||||
tabItem->setData(0, BrowserWindowPointerRole, QVariant::fromValue(qobject_cast<QWidget*>(mainWin)));
|
||||
|
||||
makeWebViewConnections(webTab->webView());
|
||||
tabItem->updateIcon();
|
||||
tabItem->setTitle(webTab->title());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -698,16 +679,12 @@ QTreeWidgetItem* TabManagerWidget::groupByWindow()
|
|||
|
||||
for (int win = 0; win < windows.count(); ++win) {
|
||||
BrowserWindow* mainWin = windows.at(win);
|
||||
QTreeWidgetItem* winItem = createEmptyItem();
|
||||
TabItem* winItem = new TabItem(ui->treeWidget);
|
||||
winItem->setBrowserWindow(mainWin);
|
||||
winItem->setText(0, tr("Window %1").arg(QString::number(win + 1)));
|
||||
winItem->setToolTip(0, tr("Double click to switch"));
|
||||
if (win == currentWindowIdx) {
|
||||
QFont font = winItem->font(0);
|
||||
font.setBold(true);
|
||||
winItem->setFont(0, font);
|
||||
}
|
||||
winItem->setIsActiveOrCaption(win == currentWindowIdx);
|
||||
|
||||
winItem->setData(0, BrowserWindowPointerRole, QVariant::fromValue(qobject_cast<QWidget*>(mainWin)));
|
||||
QList<WebTab*> tabs = mainWin->tabWidget()->allTabs();
|
||||
|
||||
for (int tab = 0; tab < tabs.count(); ++tab) {
|
||||
|
@ -716,34 +693,19 @@ QTreeWidgetItem* TabManagerWidget::groupByWindow()
|
|||
m_webPage = 0;
|
||||
continue;
|
||||
}
|
||||
QTreeWidgetItem* tabItem = createEmptyItem(winItem);
|
||||
TabItem* tabItem = new TabItem(ui->treeWidget, winItem);
|
||||
tabItem->setBrowserWindow(mainWin);
|
||||
tabItem->setWebTab(webTab);
|
||||
|
||||
if (webTab == mainWin->weView()->webTab()) {
|
||||
QFont font = tabItem->font(0);
|
||||
font.setBold(true);
|
||||
tabItem->setFont(0, font);
|
||||
tabItem->setIsActiveOrCaption(true);
|
||||
|
||||
if (mainWin == getWindow())
|
||||
currentTabItem = tabItem;
|
||||
}
|
||||
if (!webTab->isLoading()) {
|
||||
if (!webTab->isPinned()) {
|
||||
tabItem->setIcon(0, webTab->icon());
|
||||
}
|
||||
else {
|
||||
tabItem->setIcon(0, QIcon(":tabmanager/data/tab-pinned.png"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
tabItem->setIcon(0, QIcon(":tabmanager/data/tab-loading.png"));
|
||||
}
|
||||
tabItem->setText(0, webTab->title());
|
||||
tabItem->setToolTip(0, webTab->title());
|
||||
|
||||
tabItem->setData(0, UrlRole, webTab->url().toString());
|
||||
tabItem->setData(0, WebTabPointerRole, QVariant::fromValue(qobject_cast<QWidget*>(webTab)));
|
||||
tabItem->setData(0, BrowserWindowPointerRole, QVariant::fromValue(qobject_cast<QWidget*>(mainWin)));
|
||||
|
||||
makeWebViewConnections(webTab->webView());
|
||||
tabItem->updateIcon();
|
||||
tabItem->setTitle(webTab->title());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -760,14 +722,76 @@ BrowserWindow* TabManagerWidget::getWindow()
|
|||
}
|
||||
}
|
||||
|
||||
void TabManagerWidget::makeWebViewConnections(WebView* view)
|
||||
TabItem::TabItem(QTreeWidget* treeWidget, QTreeWidgetItem* parent, bool addToTree)
|
||||
: QObject()
|
||||
, QTreeWidgetItem(addToTree ? (parent ? parent : treeWidget->invisibleRootItem()) : 0, 1)
|
||||
, m_treeWidget(treeWidget)
|
||||
, m_window(0)
|
||||
, m_webTab(0)
|
||||
{
|
||||
if (view) {
|
||||
connect(view->page(), SIGNAL(loadFinished(bool)), this, SLOT(delayedRefreshTree()));
|
||||
connect(view->page(), SIGNAL(loadStarted()), this, SLOT(delayedRefreshTree()));
|
||||
connect(view, SIGNAL(titleChanged(QString)), this, SLOT(delayedRefreshTree()));
|
||||
connect(view, &WebView::iconChanged, this, [this]() {
|
||||
delayedRefreshTree();
|
||||
});
|
||||
setFlags(flags() | (parent ? Qt::ItemIsUserCheckable : Qt::ItemIsUserCheckable | Qt::ItemIsTristate));
|
||||
setCheckState(0, Qt::Unchecked);
|
||||
}
|
||||
|
||||
BrowserWindow* TabItem::window() const
|
||||
{
|
||||
return m_window;
|
||||
}
|
||||
|
||||
void TabItem::setBrowserWindow(BrowserWindow* window)
|
||||
{
|
||||
m_window = window;
|
||||
}
|
||||
|
||||
WebTab* TabItem::webTab() const
|
||||
{
|
||||
return m_webTab;
|
||||
}
|
||||
|
||||
void TabItem::setWebTab(WebTab* webTab)
|
||||
{
|
||||
m_webTab = webTab;
|
||||
|
||||
connect(m_webTab->webView()->page(), SIGNAL(audioMutedChanged(bool)), this, SLOT(updateIcon()));
|
||||
connect(m_webTab->webView()->page(), SIGNAL(loadFinished(bool)), this, SLOT(updateIcon()));
|
||||
connect(m_webTab->webView()->page(), SIGNAL(loadStarted()), this, SLOT(updateIcon()));
|
||||
connect(m_webTab->webView(), SIGNAL(titleChanged(QString)), this, SLOT(setTitle(QString)));
|
||||
connect(m_webTab->webView(), SIGNAL(iconChanged(QIcon)), this, SLOT(updateIcon()));
|
||||
}
|
||||
|
||||
void TabItem::updateIcon()
|
||||
{
|
||||
if (!m_webTab)
|
||||
return;
|
||||
|
||||
if (!m_webTab->isLoading()) {
|
||||
if (!m_webTab->isPinned()) {
|
||||
if (m_webTab->isMuted()) {
|
||||
setIcon(0, QIcon::fromTheme(QSL("audio-volume-muted"), QIcon(QSL(":icons/other/audiomuted.svg"))));
|
||||
}
|
||||
else if (!m_webTab->isMuted() && m_webTab->webView()->page()->recentlyAudible()) {
|
||||
setIcon(0, QIcon::fromTheme(QSL("audio-volume-high"), QIcon(QSL(":icons/other/audioplaying.svg"))));
|
||||
}
|
||||
else {
|
||||
setIcon(0, m_webTab->icon());
|
||||
}
|
||||
}
|
||||
else {
|
||||
setIcon(0, QIcon(":tabmanager/data/tab-pinned.png"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
setIcon(0, QIcon(":tabmanager/data/tab-loading.png"));
|
||||
}
|
||||
}
|
||||
|
||||
void TabItem::setTitle(const QString &title)
|
||||
{
|
||||
setText(0, title);
|
||||
setToolTip(0, title);
|
||||
}
|
||||
|
||||
void TabItem::setIsActiveOrCaption(bool yes)
|
||||
{
|
||||
setData(0, ActiveOrCaptionRole, yes ? QVariant(true) : QVariant());
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
#include <QHash>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
|
@ -61,19 +62,10 @@ public slots:
|
|||
void changeGroupType();
|
||||
|
||||
private:
|
||||
enum TabDataRole {
|
||||
WebTabPointerRole = Qt::UserRole + 10,
|
||||
BrowserWindowPointerRole = Qt::UserRole + 20,
|
||||
UrlRole = Qt::UserRole + 30
|
||||
};
|
||||
|
||||
QTreeWidgetItem* createEmptyItem(QTreeWidgetItem* parent = 0, bool addToTree = true);
|
||||
QTreeWidgetItem* groupByDomainName(bool useHostName = false);
|
||||
QTreeWidgetItem* groupByWindow();
|
||||
BrowserWindow* getWindow();
|
||||
|
||||
void makeWebViewConnections(WebView *view);
|
||||
|
||||
Ui::TabManagerWidget* ui;
|
||||
QPointer<BrowserWindow> m_window;
|
||||
WebPage* m_webPage;
|
||||
|
@ -105,4 +97,32 @@ signals:
|
|||
void groupTypeChanged(TabManagerWidget::GroupType);
|
||||
};
|
||||
|
||||
class TabItem : public QObject, public QTreeWidgetItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum StateRole {
|
||||
ActiveOrCaptionRole = Qt::UserRole + 1
|
||||
};
|
||||
|
||||
TabItem(QTreeWidget* treeWidget, QTreeWidgetItem* parent = 0, bool addToTree = true);
|
||||
|
||||
BrowserWindow* window() const;
|
||||
void setBrowserWindow(BrowserWindow* window);
|
||||
|
||||
WebTab* webTab() const;
|
||||
void setWebTab(WebTab* webTab);
|
||||
|
||||
public slots:
|
||||
void updateIcon();
|
||||
void setTitle(const QString& title);
|
||||
void setIsActiveOrCaption(bool yes);
|
||||
|
||||
private:
|
||||
QTreeWidget* m_treeWidget;
|
||||
BrowserWindow* m_window;
|
||||
WebTab* m_webTab;
|
||||
};
|
||||
|
||||
#endif // TABMANAGERWIDGET_H
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* TabManager plugin for Falkon
|
||||
* Copyright (C) 2013 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
* Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -122,7 +122,6 @@ TabManagerWidget* TabManagerWidgetController::createTabManagerWidget(BrowserWind
|
|||
|
||||
connect(tabManagerWidget, SIGNAL(groupTypeChanged(TabManagerWidget::GroupType)), this, SLOT(setGroupType(TabManagerWidget::GroupType)));
|
||||
connect(this, SIGNAL(requestRefreshTree(WebPage*)), tabManagerWidget, SLOT(delayedRefreshTree(WebPage*)));
|
||||
connect(this, SIGNAL(pinStateChanged(int,bool)), tabManagerWidget, SLOT(delayedRefreshTree()));
|
||||
|
||||
emit requestRefreshTree();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* TabManager plugin for Falkon
|
||||
* Copyright (C) 2013 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
* Copyright (C) 2013-2017 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -60,7 +60,6 @@ private:
|
|||
|
||||
signals:
|
||||
void requestRefreshTree(WebPage* p = 0);
|
||||
void pinStateChanged(int index, bool pinned);
|
||||
};
|
||||
|
||||
#endif // TABMANAGERWIDGETCONTROLLER_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user