From 6e40be23ae449bf5f4f5dc3babf936e9efe07594 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 11 Apr 2009 20:02:50 +0200 Subject: animated loading. Imported following (a bit) Arora code.. --- src/mainview.cpp | 37 +++++++++++++++++++++++++++++++++---- src/mainview.h | 13 ++++++++++++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/mainview.cpp b/src/mainview.cpp index 3b5db52e..6a7ed495 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -62,7 +62,7 @@ MainView::MainView(QWidget *parent) { setTabBar(m_tabBar); - loadingGitPath = KStandardDirs::locate("appdata" , "pics/loading.gif"); + m_loadingGitPath = KStandardDirs::locate("appdata" , "pics/loading.gif"); connect(m_tabBar, SIGNAL(newTab()), this, SLOT(newWebView())); connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(slotCloseTab(int))); @@ -527,14 +527,17 @@ void MainView::slotCloseTab(int index) } -// FIXME: provide movie for loading sites void MainView::webViewLoadStarted() { WebView *webView = qobject_cast(sender()); int index = webViewIndex(webView); if (-1 != index) { - setTabIcon(index, QIcon(loadingGitPath)); + QLabel *label = animatedLoading(index); + if (label->movie()) + { + label->movie()->start(); + } } } @@ -546,7 +549,11 @@ void MainView::webViewIconChanged() if (-1 != index) { QIcon icon = Application::instance()->icon(webView->url()); - setTabIcon(index, icon); + QLabel *label = animatedLoading(index); + QMovie *movie = label->movie(); + delete movie; + label->setMovie(0); + label->setPixmap(icon.pixmap(16, 16)); } } @@ -675,3 +682,25 @@ void MainView::moveTab(int fromIndex, int toIndex) m_lineEdits->insertWidget(toIndex, lineEdit); } + +QLabel *MainView::animatedLoading(int index) +{ + if (index == -1) + return 0; + + QLabel *label = qobject_cast(m_tabBar->tabButton(index, QTabBar::LeftSide)); + if (!label) + { + label = new QLabel(this); + if (!label->movie()) + { + QMovie *movie = new QMovie(m_loadingGitPath, QByteArray(), label); + movie->setSpeed(50); + label->setMovie(movie); + movie->start(); + } + m_tabBar->setTabButton(index, QTabBar::LeftSide, 0); + m_tabBar->setTabButton(index, QTabBar::LeftSide, label); + } + return label; +} diff --git a/src/mainview.h b/src/mainview.h index 6514c026..77d1d050 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -39,6 +39,7 @@ class QCompleter; class QStackedWidget; class QLineEdit; class QUrl; +class QLabel; /** @@ -141,6 +142,16 @@ private: */ void moveTab(int fromIndex, int toIndex); + /** + * This function creates (if not exists) and returns a QLabel + * with a loading QMovie. + * + * @param index the tab index where inserting the animated label + * + * @return animated label's pointer + */ + QLabel *animatedLoading(int index); + KAction *m_recentlyClosedTabsAction; KMenu *m_recentlyClosedTabsMenu; @@ -151,7 +162,7 @@ private: QStackedWidget *m_lineEdits; TabBar *m_tabBar; - QString loadingGitPath; + QString m_loadingGitPath; }; #endif -- cgit v1.2.1