[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegraphics/gwenview
From:       Aurélien Gâteau <agateau () kde ! org>
Date:       2010-05-22 22:10:54
Message-ID: 20100522221054.2CD94AC8BD () svn ! kde ! org
[Download RAW message or body]

SVN commit 1129596 by gateau:

Show an animation over the item when it is busy

 M  +11 -0     app/thumbnailviewpanel.cpp  
 M  +1 -0      app/thumbnailviewpanel.h  
 M  +9 -0      lib/thumbnailview/previewitemdelegate.cpp  
 M  +54 -0     lib/thumbnailview/thumbnailview.cpp  
 M  +21 -0     lib/thumbnailview/thumbnailview.h  


--- trunk/KDE/kdegraphics/gwenview/app/thumbnailviewpanel.cpp #1129595:1129596
@@ -204,6 +204,8 @@
 
 	connect(DocumentFactory::instance(), SIGNAL(documentChanged(const KUrl&)),
 		SLOT(generateThumbnailForUrl(const KUrl&)) );
+	connect(DocumentFactory::instance(), SIGNAL(documentBusyStateChanged(const KUrl&, bool)),
+		SLOT(updateThumbnailBusyState(const KUrl&, bool)) );
 }
 
 
@@ -347,4 +349,13 @@
 }
 
 
+void ThumbnailViewPanel::updateThumbnailBusyState(const KUrl& url, bool busy) {
+	QModelIndex index = d->mDirModel->indexForUrl(url);
+	if (!index.isValid()) {
+		return;
+	}
+	d->mThumbnailView->updateThumbnailBusyState(index, busy);
+}
+
+
 } // namespace
--- trunk/KDE/kdegraphics/gwenview/app/thumbnailviewpanel.h #1129595:1129596
@@ -71,6 +71,7 @@
 	void slotUrlsDropped(const KUrl& destUrl, QDropEvent*);
 	void showMenuForDroppedUrls(const KUrl::List&, const KUrl& destUrl);
 	void generateThumbnailForUrl(const KUrl&);
+	void updateThumbnailBusyState(const KUrl&, bool);
 
 private:
 	ThumbnailViewPanelPrivate* const d;
--- trunk/KDE/kdegraphics/gwenview/lib/thumbnailview/previewitemdelegate.cpp #1129595:1129596
@@ -805,6 +805,15 @@
 		painter->drawPixmap(framePosition, d->mSaveButtonPixmap);
 	}
 
+	// Draw busy indicator
+	if (d->mView->isBusy(index)) {
+		QPixmap pix = d->mView->busySequenceCurrentPixmap();
+		painter->drawPixmap(
+			thumbnailRect.left() + (thumbnailRect.width() - pix.width()) / 2,
+			thumbnailRect.top() + (thumbnailRect.height() - pix.height()) / 2,
+			pix);
+	}
+
 	if (index == d->mIndexUnderCursor) {
 		// Show bar again: if the thumbnail has changed, we may need to update
 		// its position. Don't do it if we are over rotate buttons, though: it
--- trunk/KDE/kdegraphics/gwenview/lib/thumbnailview/thumbnailview.cpp #1129595:1129596
@@ -30,6 +30,7 @@
 #include <QPointer>
 #include <QQueue>
 #include <QScrollBar>
+#include <QTimeLine>
 #include <QTimer>
 #include <QToolTip>
 
@@ -39,6 +40,7 @@
 #include <kicon.h>
 #include <kiconloader.h>
 #include <kglobalsettings.h>
+#include <kpixmapsequence.h>
 
 // Local
 #include "abstractthumbnailviewhelper.h"
@@ -133,6 +135,7 @@
 
 typedef QHash<QUrl, Thumbnail> ThumbnailForUrl;
 typedef QQueue<KUrl> UrlQueue;
+typedef QSet<QPersistentModelIndex> PersistentModelIndexSet;
 
 struct ThumbnailViewPrivate {
 	ThumbnailView* that;
@@ -147,6 +150,20 @@
 	QPixmap mWaitingThumbnail;
 	QPointer<ThumbnailLoadJob> mThumbnailLoadJob;
 
+	PersistentModelIndexSet mBusyIndexSet;
+	KPixmapSequence mBusySequence;
+	QTimeLine* mBusyAnimationTimeLine;
+
+	void setupBusyAnimation() {
+		mBusySequence = KPixmapSequence("process-working", 22);
+		mBusyAnimationTimeLine = new QTimeLine(200 * mBusySequence.frameCount(), that);
+		mBusyAnimationTimeLine->setCurveShape(QTimeLine::LinearCurve);
+		mBusyAnimationTimeLine->setEndFrame(mBusySequence.frameCount() - 1);
+		mBusyAnimationTimeLine->setLoopCount(0);
+		QObject::connect(mBusyAnimationTimeLine, SIGNAL(frameChanged(int)),
+			that, SLOT(updateBusyIndexes()));
+	}
+
 	void scheduleThumbnailGenerationForVisibleItems() {
 		if (mThumbnailLoadJob) {
 			mThumbnailLoadJob->removeItems(mThumbnailLoadJob->pendingItems());
@@ -278,6 +295,8 @@
 	setDropIndicatorShown(true);
 	setUniformItemSizes(true);
 
+	d->setupBusyAnimation();
+
 	viewport()->setMouseTracking(true);
 	// Set this attribute, otherwise the item delegate won't get the
 	// State_MouseOver state
@@ -558,6 +577,12 @@
 }
 
 
+
+bool ThumbnailView::isBusy(const QModelIndex& index) const {
+	return d->mBusyIndexSet.contains(index);
+}
+
+
 void ThumbnailView::startDrag(Qt::DropActions supportedActions) {
 	QModelIndexList indexes = selectionModel()->selectedIndexes();
 	if (indexes.isEmpty()) {
@@ -736,6 +761,35 @@
 }
 
 
+void ThumbnailView::updateThumbnailBusyState(const QModelIndex& _index, bool busy) {
+	QPersistentModelIndex index(_index);
+	if (busy && !d->mBusyIndexSet.contains(index)) {
+		d->mBusyIndexSet << index;
+		update(index);
+		if (d->mBusyAnimationTimeLine->state() != QTimeLine::Running) {
+			d->mBusyAnimationTimeLine->start();
+		}
+	} else if (!busy && d->mBusyIndexSet.remove(index)) {
+		update(index);
+		if (d->mBusyIndexSet.isEmpty()) {
+			d->mBusyAnimationTimeLine->stop();
+		}
+	}
+}
+
+
+void ThumbnailView::updateBusyIndexes() {
+	Q_FOREACH(const QPersistentModelIndex& index, d->mBusyIndexSet) {
+		update(index);
+	}
+}
+
+
+QPixmap ThumbnailView::busySequenceCurrentPixmap() const {
+	return d->mBusySequence.frameAt(d->mBusyAnimationTimeLine->currentFrame());
+}
+
+
 void ThumbnailView::smoothNextThumbnail() {
 	if (d->mSmoothThumbnailQueue.isEmpty()) {
 		return;
--- trunk/KDE/kdegraphics/gwenview/lib/thumbnailview/thumbnailview.h #1129595:1129596
@@ -63,10 +63,21 @@
 	bool isModified(const QModelIndex&) const;
 
 	/**
+	 * Returns true if the document pointed by the index is currently busy
+	 * (loading, saving, rotating...)
+	 */
+	bool isBusy(const QModelIndex& index) const;
+
+	/**
 	 * Generate thumbnail for @a index.
 	 */
 	void generateThumbnailForIndex(const QModelIndex& index);
 
+	/**
+	 * Tells the view the busy state of the document pointed by the index has changed.
+	 */
+	void updateThumbnailBusyState(const QModelIndex& index, bool);
+
 	virtual void setModel(QAbstractItemModel* model);
 
 	/**
@@ -74,6 +85,11 @@
 	 */
 	using QListView::scheduleDelayedItemsLayout;
 
+	/**
+	 * Returns the current pixmap to paint when drawing a busy index.
+	 */
+	QPixmap busySequenceCurrentPixmap() const;
+
 Q_SIGNALS:
 	/**
 	 * It seems we can't use the 'activated()' signal for now because it does
@@ -139,6 +155,11 @@
 	void setThumbnail(const KFileItem&, const QPixmap&, const QSize&);
 	void setBrokenThumbnail(const KFileItem&);
 
+	/*
+	 * Cause a repaint of all busy indexes
+	 */
+	void updateBusyIndexes();
+
 	void generateThumbnailsForVisibleItems();
 	void smoothNextThumbnail();
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic