[vlc-commits] qt: svg support for pixmapanimator

Pierre Lamot git at videolan.org
Sat Oct 14 22:28:26 CEST 2017


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Fri Sep 29 10:25:09 2017 +0200| [fe4fcce2798f08e08b2bc9c0f99bb66dc3517fd6] | committer: Jean-Baptiste Kempf

qt: svg support for pixmapanimator

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fe4fcce2798f08e08b2bc9c0f99bb66dc3517fd6
---

 modules/gui/qt/components/playlist/standardpanel.cpp |  9 +++++----
 modules/gui/qt/dialogs/plugins.cpp                   | 11 ++++++-----
 modules/gui/qt/util/animators.cpp                    |  8 ++++----
 modules/gui/qt/util/animators.hpp                    |  9 +++++----
 modules/gui/qt/util/customwidgets.cpp                |  4 +++-
 5 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/modules/gui/qt/components/playlist/standardpanel.cpp b/modules/gui/qt/components/playlist/standardpanel.cpp
index 3cc132eff1..483bb2111f 100644
--- a/modules/gui/qt/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt/components/playlist/standardpanel.cpp
@@ -45,6 +45,7 @@
 #include <vlc_services_discovery.h>               /* SD_CMD_SEARCH */
 #include <vlc_intf_strings.h>                     /* POP_ */
 
+#define SPINNER_SIZE 32
 #define I_NEW_DIR \
     I_DIR_OR_FOLDER( N_("Create Directory"), N_( "Create Folder" ) )
 #define I_NEW_DIR_NAME \
@@ -104,7 +105,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     frames << ":/util/wait2";
     frames << ":/util/wait3";
     frames << ":/util/wait4";
-    spinnerAnimation = new PixmapAnimator( this, frames );
+    spinnerAnimation = new PixmapAnimator( this, frames, SPINNER_SIZE, SPINNER_SIZE );
     CONNECT( spinnerAnimation, pixmapReady( const QPixmap & ), this, updateViewport() );
 
     /* Saved Settings */
@@ -585,10 +586,10 @@ bool StandardPLPanel::eventFilter ( QObject *obj, QEvent * event )
             {
                 QWidget *viewport = qobject_cast<QWidget *>( obj );
                 QStylePainter painter( viewport );
-                QPixmap *spinner = spinnerAnimation->getPixmap();
+                const QPixmap& spinner = spinnerAnimation->getPixmap();
                 QPoint point = viewport->geometry().center();
-                point -= QPoint( spinner->size().width() / 2, spinner->size().height() / 2 );
-                painter.drawPixmap( point, *spinner );
+                point -= QPoint( spinner.width() / 2, spinner.height() / 2 );
+                painter.drawPixmap( point, spinner );
             }
         }
     }
diff --git a/modules/gui/qt/dialogs/plugins.cpp b/modules/gui/qt/dialogs/plugins.cpp
index 83a5fcf709..dd87ec743b 100644
--- a/modules/gui/qt/dialogs/plugins.cpp
+++ b/modules/gui/qt/dialogs/plugins.cpp
@@ -69,6 +69,7 @@
 
 //match the image source (width/height)
 #define SCORE_ICON_WIDTH_SCALE 4
+#define SPINNER_SIZE 32
 
 static QPixmap *loadPixmapFromData( char *, int size );
 
@@ -484,7 +485,7 @@ AddonsTab::AddonsTab( intf_thread_t *p_intf_ ) : QVLCFrame( p_intf_ )
     frames << ":/util/wait2";
     frames << ":/util/wait3";
     frames << ":/util/wait4";
-    spinnerAnimation = new PixmapAnimator( this, frames );
+    spinnerAnimation = new PixmapAnimator( this, frames, SPINNER_SIZE, SPINNER_SIZE );
     CONNECT( spinnerAnimation, pixmapReady( const QPixmap & ),
              addonsView->viewport(), update() );
     addonsView->viewport()->installEventFilter( this );
@@ -519,14 +520,14 @@ bool AddonsTab::eventFilter( QObject *obj, QEvent *event )
             QWidget *viewport = qobject_cast<QWidget *>( obj );
             if ( !viewport ) break;
             QStylePainter painter( viewport );
-            QPixmap *spinner = spinnerAnimation->getPixmap();
+            const QPixmap& spinner = spinnerAnimation->getPixmap();
             QPoint point = viewport->geometry().center();
-            point -= QPoint( spinner->size().width() / 2, spinner->size().height() / 2 );
-            painter.drawPixmap( point, *spinner );
+            point -= QPoint( spinner.width() / 2, spinner.height() / 2 );
+            painter.drawPixmap( point, spinner );
             QString text = qtr("Retrieving addons...");
             QSize textsize = fontMetrics().size( 0, text );
             point = viewport->geometry().center();
-            point -= QPoint( textsize.width() / 2, -spinner->size().height() );
+            point -= QPoint( textsize.width() / 2, -spinner.height() );
             painter.drawText( point, text );
         }
         else if ( addonsModel->rowCount() == 0 )
diff --git a/modules/gui/qt/util/animators.cpp b/modules/gui/qt/util/animators.cpp
index 4c5b805172..17772a8554 100644
--- a/modules/gui/qt/util/animators.cpp
+++ b/modules/gui/qt/util/animators.cpp
@@ -20,6 +20,7 @@
 
 #include "animators.hpp"
 #include "qt.hpp"
+#include "util/imagehelper.hpp"
 
 #include <QWidget>
 #include <QPixmap>
@@ -43,18 +44,17 @@ void BasicAnimator::updateCurrentTime( int msecs )
     }
 }
 
-PixmapAnimator::PixmapAnimator( QWidget *parent, QList<QString> frames )
+PixmapAnimator::PixmapAnimator(QWidget *parent, QList<QString> frames, int width , int height)
     : BasicAnimator( parent )
 {
     foreach( QString name, frames )
-        pixmaps.append( new QPixmap( name ) );
+        pixmaps.append( ImageHelper::loadSvgToPixmap( name, width, height ) );
     currentPixmap = pixmaps.at( 0 );
     setFps( frames.count() ); /* default to 1 sec loop */
 }
 
 PixmapAnimator::~PixmapAnimator()
 {
-    qDeleteAll( pixmaps );
 }
 
 void PixmapAnimator::updateCurrentTime( int msecs )
@@ -65,7 +65,7 @@ void PixmapAnimator::updateCurrentTime( int msecs )
     {
         current_frame = i;
         currentPixmap = pixmaps.at( current_frame );
-        emit pixmapReady( *currentPixmap );
+        emit pixmapReady( currentPixmap );
     }
 }
 
diff --git a/modules/gui/qt/util/animators.hpp b/modules/gui/qt/util/animators.hpp
index c980b72c68..0380c10f6b 100644
--- a/modules/gui/qt/util/animators.hpp
+++ b/modules/gui/qt/util/animators.hpp
@@ -27,6 +27,7 @@
 #include <QList>
 #include <QString>
 #include <QAbstractAnimation>
+#include <QPixmap>
 #include <QPersistentModelIndex>
 
 class QWidget;
@@ -63,14 +64,14 @@ class PixmapAnimator : public BasicAnimator
     Q_OBJECT
 
 public:
-    PixmapAnimator( QWidget *parent, QList<QString> _frames );
+    PixmapAnimator(QWidget *parent, QList<QString> _frames , int width, int height);
     int duration() const Q_DECL_OVERRIDE { return interval * pixmaps.count(); }
     virtual ~PixmapAnimator();
-    QPixmap *getPixmap() { return currentPixmap; }
+    const QPixmap& getPixmap() { return currentPixmap; }
 protected:
     void updateCurrentTime ( int msecs ) Q_DECL_OVERRIDE;
-    QList<QPixmap *> pixmaps;
-    QPixmap *currentPixmap;
+    QList<QPixmap> pixmaps;
+    QPixmap currentPixmap;
 signals:
     void pixmapReady( const QPixmap & );
 };
diff --git a/modules/gui/qt/util/customwidgets.cpp b/modules/gui/qt/util/customwidgets.cpp
index 61fd89838f..8ffb6d7870 100644
--- a/modules/gui/qt/util/customwidgets.cpp
+++ b/modules/gui/qt/util/customwidgets.cpp
@@ -39,6 +39,8 @@
 #include <QApplication>
 #include <vlc_actions.h>
 
+#define SPINNER_SIZE 32
+
 QFramelessButton::QFramelessButton( QWidget *parent )
                     : QPushButton( parent )
 {
@@ -326,7 +328,7 @@ SpinningIcon::SpinningIcon( QWidget *parent ) : QLabel( parent )
     frames << ":/util/wait2";
     frames << ":/util/wait3";
     frames << ":/util/wait4";
-    animator = new PixmapAnimator( this, frames );
+    animator = new PixmapAnimator( this, frames, SPINNER_SIZE, SPINNER_SIZE );
     CONNECT( animator, pixmapReady( const QPixmap & ), this, setPixmap( const QPixmap & ) );
     CONNECT( animator, pixmapReady( const QPixmap & ), this, repaint() );
     setScaledContents( true );



More information about the vlc-commits mailing list