[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: [PATCH] Animating icons in kicker
From: Allan Sandfeld Jensen <snowwolf () one2one-networks ! com>
Date: 2002-02-04 15:31:14
[Download RAW message or body]
This fixes the inconsistent behavior where an icon might be animated on the
desktop, but once draged onto kicker is passive. Also it adds eye-candy ;-)
Please feel free to test it.
(since the k-menu does not have an animated version yet, I have been testing
by copying filesystems/folder.* to apps/go.*.)
Sincerely
-Allan
["animate.patch" (text/x-diff)]
diff -ur kdebase/kicker/buttons/browserbutton.cpp kdebase-new/kicker/buttons/browserbutton.cpp
--- kdebase/kicker/buttons/browserbutton.cpp Mon Feb 4 16:04:00 2002
+++ kdebase-new/kicker/buttons/browserbutton.cpp Mon Feb 4 16:03:16 2002
@@ -90,7 +90,7 @@
{
KURL path = topMenu->path();
_menuTimer->stop();
- KFileItem item( path, QString::fromLatin1( "inode/directory" ), -1 );
+ KFileItem item( path, QString::fromLatin1( "inode/directory" ), (unsigned int)-1 );
KonqOperations::doDrop( &item, path, ev, this );
PanelButton::dropEvent(ev);
}
diff -ur kdebase/kicker/buttons/desktopbutton.cpp kdebase-new/kicker/buttons/desktopbutton.cpp
--- kdebase/kicker/buttons/desktopbutton.cpp Mon Feb 4 16:18:54 2002
+++ kdebase-new/kicker/buttons/desktopbutton.cpp Mon Feb 4 16:03:16 2002
@@ -21,6 +21,9 @@
******************************************************************/
+// Needs to be first for qmovie.h to parse
+#include "desktopbutton.h"
+
#include <qtooltip.h>
#include <qdragobject.h>
@@ -34,8 +37,11 @@
#include <kwin.h>
#include "kicker.h"
+#include "panel.h"
+/* FIXME: Something in the above breaks parsing of qmovie.h
#include "desktopbutton.h"
+*/
#include "desktopbutton.moc"
DesktopButton::DesktopButton( QWidget* parent )
@@ -77,7 +83,7 @@
void DesktopButton::dropEvent( QDropEvent *ev )
{
KURL dPath = KGlobalSettings::desktopPath();
- KFileItem item( dPath, QString::fromLatin1( "inode/directory" ), -1 );
+ KFileItem item( dPath, QString::fromLatin1( "inode/directory" ), (unsigned int)-1 );
KonqOperations::doDrop( &item, dPath, ev, this );
PanelButton::dropEvent(ev);
}
diff -ur kdebase/kicker/buttons/panelbutton.cpp kdebase-new/kicker/buttons/panelbutton.cpp
--- kdebase/kicker/buttons/panelbutton.cpp Mon Feb 4 16:18:54 2002
+++ kdebase-new/kicker/buttons/panelbutton.cpp Mon Feb 4 16:03:17 2002
@@ -54,6 +54,9 @@
return;
setTile( tilesGroup.readEntry( name + "Tile") );
+
+ // animation support:
+ _doAnimation = config.readBoolEntry( "EnableAnimatedIcons", true /*default*/ );
}
void PanelButton::slotIconChanged(int /*group*/)
diff -ur kdebase/kicker/buttons/panelbuttonbase.cpp kdebase-new/kicker/buttons/panelbuttonbase.cpp
--- kdebase/kicker/buttons/panelbuttonbase.cpp Mon Feb 4 16:19:01 2002
+++ kdebase-new/kicker/buttons/panelbuttonbase.cpp Mon Feb 4 16:03:17 2002
@@ -27,6 +27,7 @@
#include <qbitmap.h>
#include <qapplication.h>
#include <qstyle.h>
+#include <qmovie.h>
#include <kstddirs.h>
#include <kglobal.h>
@@ -230,6 +231,9 @@
, _arrowDirection(::Bottom)
, _popupDirection(::dUp)
, _orientation(Horizontal)
+ , _animated(false)
+ , _doAnimation(true)
+ , _movie(0L)
{
setBackgroundMode( PaletteBackground );
_oldCursor = cursor();
@@ -241,6 +245,15 @@
setAcceptDrops( !Kicker::kicker()->isImmutable() );
}
+/*
+void PanelButtonBase::reconfigure()
+{
+ KConfig* config = KGlobal::config();
+ config->setGroup("buttons");
+ _doAnimation = config->readBoolEntry("EnableAnimatedIcons", true);
+}*/
+
+
void PanelButtonBase::slotSettingsChanged(int category)
{
if (category != KApplication::SETTINGS_MOUSE) return;
@@ -281,6 +294,7 @@
KIconLoader * ldr = KGlobal::iconLoader();
_iconName = nm;
+ _animatedIcon = nm;
_icon = ldr->loadIcon(nm, KIcon::Panel, sz, KIcon::DefaultState, 0L, true);
@@ -454,24 +468,17 @@
void PanelButtonBase::enterEvent(QEvent* e)
{
+
if (_changeCursorOverItem)
setCursor(KCursor().handCursor());
- if (!zoomDisabled)
+ if( _doAnimation && hasAnimation() ) {
+ animate();
+ }
+ if (!isAnimated() && !zoomDisabled)
{
- if (!zoomButton)
- zoomButton = new ZoomButton;
-
- if (zoomButton->isZoomingEnabled() && /* _icon.width() < 32 && */
- !_iconz.isNull() && _iconz.width() > _icon.width() &&
- !mouseGrabber() && !qApp->activePopupWidget() )
- { // we can and should zoom
- if ( !zoomButton->isWatching( this ) ) {
- zoomButton->watchMe( this, mapToGlobal( rect().center() ), _iconz );
- update();
- }
- return;
- }
+ zoom();
+ return;
}
_highlight = true;
@@ -484,6 +491,12 @@
if (_changeCursorOverItem)
setCursor(_oldCursor);
+ if( isAnimated() )
+ {
+ if( _movie ) _movie->pause();
+ setAnimated( false );
+ //repaint(false);
+ }
if (_highlight) {
_highlight = false;
repaint(false);
@@ -646,4 +659,86 @@
}
p->restore();
+}
+
+void PanelButtonBase::zoom() {
+ if (!zoomButton)
+ zoomButton = new ZoomButton;
+
+ if (zoomButton->isZoomingEnabled() && /* _icon.width() < 32 && */
+ !_iconz.isNull() && _iconz.width() > _icon.width() &&
+ !mouseGrabber() && !qApp->activePopupWidget() )
+ { // we can and should zoom
+ if ( !zoomButton->isWatching( this ) ) {
+ zoomButton->watchMe( this, mapToGlobal( rect().center() ), _iconz );
+ update();
+ }
+ }
+}
+
+void PanelButtonBase::animate() {
+ QMovie movie = KGlobal::iconLoader()->loadMovie( mouseOverAnimation(), KIcon::Panel );
+ if ( !movie.isNull()) {
+ delete _movie;
+ _movie = new QMovie( movie );
+ _movie->connectUpdate( this, SLOT( slotMovieUpdate(const QRect&)));
+ _movie->connectStatus( this, SLOT( slotMovieStatus(int)));
+ setAnimated(true);
+ } else {
+ setAnimated(false);
+ if (_movie) _movie->pause();
+ setMouseOverAnimation( QString::null );
+ }
+}
+
+
+void PanelButtonBase::slotMovieUpdate( const QRect& rect)
+{
+ Q_ASSERT( _movie );
+ // seem stopAnimation triggers one last update
+ if ( _movie && isAnimated() ) {
+ _iconh = _movie->framePixmap();
+ update();
+ }
+}
+
+
+void PanelButtonBase::slotMovieStatus( int status )
+{
+ if ( status < 0 ) {
+ // Error playing the MNG -> forget about it and do normal iconeffect
+ if ( isAnimated() ) {
+ setAnimated( false );
+ setMouseOverAnimation( QString::null );
+ }
+ if ( !zoomDisabled ) zoom();
+ }
+}
+
+void PanelButtonBase::setMouseOverAnimation( const QString& movieFileName )
+{
+ if( !movieFileName.isEmpty() )
+ {
+ _animatedIcon = movieFileName;
+ }
+}
+
+QString PanelButtonBase::mouseOverAnimation() const
+{
+ return _animatedIcon;
+}
+
+bool PanelButtonBase::hasAnimation() const
+{
+ return ! _animatedIcon.isNull();
+}
+
+bool PanelButtonBase::isAnimated() const
+{
+ return _animated;
+}
+
+void PanelButtonBase::setAnimated( bool a )
+{
+ _animated = a;
}
diff -ur kdebase/kicker/buttons/panelbuttonbase.h kdebase-new/kicker/buttons/panelbuttonbase.h
--- kdebase/kicker/buttons/panelbuttonbase.h Mon Feb 4 16:19:01 2002
+++ kdebase-new/kicker/buttons/panelbuttonbase.h Mon Feb 4 16:03:17 2002
@@ -26,6 +26,7 @@
#include <qbutton.h>
#include <qpixmap.h>
+#include <qmovie.h>
#include <qimage.h>
#include <qcursor.h>
#include <qguardedptr.h>
@@ -55,6 +56,12 @@
Direction popupDirection() { return _popupDirection; }
static void setZoomEnabled(bool b);
+
+ void setMouseOverAnimation(const QString& movieFileName );
+ QString mouseOverAnimation() const;
+
+ bool isAnimated() const;
+ bool hasAnimation() const;
public slots:
void slotSetOrientation(Orientation o) { _orientation = o; }
@@ -62,6 +69,9 @@
protected slots:
void slotSettingsChanged(int);
+
+ void slotMovieUpdate( const QRect& );
+ void slotMovieStatus( int );
protected:
virtual void resizeEvent(QResizeEvent*);
@@ -72,10 +82,15 @@
virtual void dragEnterEvent(QDragEnterEvent *);
virtual void dragLeaveEvent(QDragLeaveEvent *);
virtual void dropEvent(QDropEvent *);
+
+ void animate();
+ void zoom();
void setArrowDirection(Position dir);
void loadTiles();
+ void setAnimated( bool );
+
bool _drawArrow;
bool _highlight;
bool _changeCursorOverItem;
@@ -93,12 +108,19 @@
Position _arrowDirection;
Direction _popupDirection;
Orientation _orientation;
+
+ QMovie* _movie;
+ QString _animatedIcon;
+ bool _animated;
+ bool _doAnimation;
+
};
class ZoomButton : public PanelButtonBase
{
Q_OBJECT
- public:
+
+public:
ZoomButton();
~ZoomButton();
bool isZoomingEnabled() const { return zooming; }
@@ -108,7 +130,7 @@
public slots:
void reconfigure();
- protected:
+protected:
void drawButtonLabel(QPainter *p, const QPixmap &bg);
bool eventFilter( QObject *o, QEvent * e);
// reimp those to do nothing
diff -ur kdebase/kicker/buttons/urlbutton.cpp kdebase-new/kicker/buttons/urlbutton.cpp
--- kdebase/kicker/buttons/urlbutton.cpp Mon Feb 4 16:04:09 2002
+++ kdebase-new/kicker/buttons/urlbutton.cpp Mon Feb 4 16:03:17 2002
@@ -128,7 +128,7 @@
}
else // attempt to interpret path as directory
{
- KFileItem item( url, QString::fromLatin1( "inode/directory" ), -1 );
+ KFileItem item( url, QString::fromLatin1( "inode/directory" ), (unsigned int)-1 );
KonqOperations::doDrop( &item, url, ev, this );
}
}
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic