From facc2f92fe73d4e925510fcb2936483798efba6a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 23 Jan 2013 19:04:05 +0100 Subject: Improve icon management code In the 1.x way, IconManager notified all the tabs about icons changed. This way, just the interested tab is :) --- src/tabwindow/tabwindow.cpp | 30 ++++++++++++++++++++++++++++++ src/tabwindow/tabwindow.h | 1 + 2 files changed, 31 insertions(+) (limited to 'src/tabwindow') diff --git a/src/tabwindow/tabwindow.cpp b/src/tabwindow/tabwindow.cpp index e0b6224a..4f58ce3e 100644 --- a/src/tabwindow/tabwindow.cpp +++ b/src/tabwindow/tabwindow.cpp @@ -247,6 +247,7 @@ WebWindow *TabWindow::prepareNewTab(WebPage *page) WebWindow *tab = new WebWindow(this, _isPrivateBrowsing, page); connect(tab, SIGNAL(titleChanged(QString)), this, SLOT(tabTitleChanged(QString))); + connect(tab, SIGNAL(iconChanged()), this, SLOT(tabIconChanged())); connect(tab, SIGNAL(loadStarted()), this, SLOT(tabLoadStarted())); connect(tab, SIGNAL(loadFinished(bool)), this, SLOT(tabLoadFinished(bool))); @@ -409,6 +410,33 @@ void TabWindow::tabTitleChanged(const QString &title) } +void TabWindow::tabIconChanged() +{ + WebWindow *tab = qobject_cast(sender()); + if (!tab) + return; + + if (tab->isLoading()) + return; + + int index = indexOf(tab); + + if (-1 == index) + return; + + QLabel *label = qobject_cast(tabBar()->tabButton(index, QTabBar::LeftSide)); + if (!label) + { + label = new QLabel(this); + tabBar()->setTabButton(index, QTabBar::LeftSide, 0); + tabBar()->setTabButton(index, QTabBar::LeftSide, label); + } + + KIcon ic = IconManager::self()->iconForUrl(tab->url()); + label->setPixmap(ic.pixmap(16, 16)); +} + + void TabWindow::tabLoadStarted() { WebWindow *tab = qobject_cast(sender()); @@ -604,6 +632,7 @@ void TabWindow::detachTab(int index, TabWindow *toWindow) // WARNING: Code copied from prepareNewTab method. // Any new changes there should be applied here... disconnect(tab, SIGNAL(titleChanged(QString)), this, SLOT(tabTitleChanged(QString))); + disconnect(tab, SIGNAL(iconChanged()), this, SLOT(tabIconChanged())); disconnect(tab, SIGNAL(loadStarted()), this, SLOT(tabLoadStarted())); disconnect(tab, SIGNAL(loadFinished(bool)), this, SLOT(tabLoadFinished(bool))); disconnect(tab, SIGNAL(pageCreated(WebPage*)), this, SLOT(pageCreated(WebPage*))); @@ -612,6 +641,7 @@ void TabWindow::detachTab(int index, TabWindow *toWindow) // WARNING: Code copied from prepareNewTab method. // Any new changes there should be applied here... connect(tab, SIGNAL(titleChanged(QString)), w, SLOT(tabTitleChanged(QString))); + connect(tab, SIGNAL(iconChanged()), w, SLOT(tabIconChanged())); connect(tab, SIGNAL(loadStarted()), w, SLOT(tabLoadStarted())); connect(tab, SIGNAL(loadFinished(bool)), w, SLOT(tabLoadFinished(bool))); connect(tab, SIGNAL(pageCreated(WebPage*)), w, SLOT(pageCreated(WebPage*))); diff --git a/src/tabwindow/tabwindow.h b/src/tabwindow/tabwindow.h index c3df016c..3a00ac4a 100644 --- a/src/tabwindow/tabwindow.h +++ b/src/tabwindow/tabwindow.h @@ -92,6 +92,7 @@ private Q_SLOTS: void updateNewTabButtonPosition(); void tabTitleChanged(const QString &); + void tabIconChanged(); void tabLoadStarted(); void tabLoadFinished(bool); -- cgit v1.2.1