[vlc-commits] Qt: BGWidget: split joke code.

Francois Cartegnie git at videolan.org
Sun Dec 30 20:52:32 CET 2012


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Dec 20 15:07:32 2012 +0100| [e9fe22e89fa8934f1fb050f9bdc752ab558c877a] | committer: Francois Cartegnie

Qt: BGWidget: split joke code.

And more :)

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

 modules/gui/qt4/components/interface_widgets.cpp |  125 ++++++++++++++++++++--
 modules/gui/qt4/components/interface_widgets.hpp |   39 ++++++-
 modules/gui/qt4/main_interface.cpp               |   32 +++++-
 modules/gui/qt4/main_interface.hpp               |    5 +-
 4 files changed, 189 insertions(+), 12 deletions(-)

diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index d6967c8..5c86063 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -197,6 +197,7 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
     setPalette( plt );
 
     /* Init the cone art */
+    defaultArt = QString( ":/logo/vlc128.png" );
     updateArt( "" );
 
     /* fade in animator */
@@ -216,16 +217,9 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
 void BackgroundWidget::updateArt( const QString& url )
 {
     if ( !url.isEmpty() )
-    {
         pixmapUrl = url;
-    }
     else
-    {   /* Xmas joke */
-        if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
-            pixmapUrl = QString( ":/logo/vlc128-xmas.png" );
-        else
-            pixmapUrl = QString( ":/logo/vlc128.png" );
-    }
+        pixmapUrl = defaultArt;
     update();
 }
 
@@ -297,6 +291,121 @@ void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
     event->accept();
 }
 
+EasterEggBackgroundWidget::EasterEggBackgroundWidget( intf_thread_t *p_intf )
+    : BackgroundWidget( p_intf )
+{
+    flakes = new QLinkedList<flake *>();
+    i_rate = 2;
+    i_speed = 1;
+    b_enabled = false;
+    timer = new QTimer( this );
+    timer->setInterval( 100 );
+    CONNECT( timer, timeout(), this, spawnFlakes() );
+    if ( isVisible() && b_enabled ) timer->start();
+    defaultArt = QString( ":/logo/vlc128-xmas.png" );
+    updateArt( "" );
+}
+
+EasterEggBackgroundWidget::~EasterEggBackgroundWidget()
+{
+    timer->stop();
+    delete timer;
+    reset();
+    delete flakes;
+}
+
+void EasterEggBackgroundWidget::showEvent( QShowEvent *e )
+{
+    if ( b_enabled ) timer->start();
+    BackgroundWidget::showEvent( e );
+}
+
+void EasterEggBackgroundWidget::hideEvent( QHideEvent *e )
+{
+    timer->stop();
+    reset();
+    BackgroundWidget::hideEvent( e );
+}
+
+void EasterEggBackgroundWidget::resizeEvent( QResizeEvent *e )
+{
+    reset();
+    BackgroundWidget::resizeEvent( e );
+}
+
+void EasterEggBackgroundWidget::animate()
+{
+    b_enabled = true;
+    if ( isVisible() ) timer->start();
+}
+
+void EasterEggBackgroundWidget::spawnFlakes()
+{
+    if ( ! isVisible() ) return;
+
+    double w = (double) width() / RAND_MAX;
+
+    int i_spawn = ( (double) qrand() / RAND_MAX ) * i_rate;
+
+    QLinkedList<flake *>::iterator it = flakes->begin();
+    while( it != flakes->end() )
+    {
+        flake *current = *it;
+        current->point.setY( current->point.y() + i_speed );
+        if ( current->point.y() + i_speed >= height() )
+        {
+            delete current;
+            it = flakes->erase( it );
+        }
+        else
+            it++;
+    }
+
+    if ( flakes->size() < MAX_FLAKES )
+    for ( int i=0; i<i_spawn; i++ )
+    {
+        flake *f = new flake;
+        f->point.setX( qrand() * w );
+        f->b_fat = ( qrand() < ( RAND_MAX * .33 ) );
+        flakes->append( f );
+    }
+    update();
+}
+
+void EasterEggBackgroundWidget::reset()
+{
+    while ( !flakes->isEmpty() )
+        delete flakes->takeFirst();
+}
+
+void EasterEggBackgroundWidget::paintEvent( QPaintEvent *e )
+{
+    QPainter painter(this);
+
+    painter.setBrush( QBrush( QColor(Qt::white) ) );
+    painter.setPen( QPen(Qt::white) );
+
+    QLinkedList<flake *>::const_iterator it = flakes->constBegin();
+    while( it != flakes->constEnd() )
+    {
+        const flake * const f = *(it++);
+        if ( f->b_fat )
+        {
+            /* Xsnow like :p */
+            painter.drawPoint( f->point.x(), f->point.y() -1 );
+            painter.drawPoint( f->point.x() + 1, f->point.y() );
+            painter.drawPoint( f->point.x(), f->point.y() +1 );
+            painter.drawPoint( f->point.x() - 1, f->point.y() );
+        }
+        else
+        {
+            painter.drawPoint( f->point );
+        }
+    }
+
+    BackgroundWidget::paintEvent( e );
+}
+
 #if 0
 #include <QPushButton>
 #include <QHBoxLayout>
diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp
index 730c7e0..118264f 100644
--- a/modules/gui/qt4/components/interface_widgets.hpp
+++ b/modules/gui/qt4/components/interface_widgets.hpp
@@ -43,6 +43,7 @@
 #include <QLabel>
 #include <QMouseEvent>
 #include <QPropertyAnimation>
+#include <QLinkedList>
 
 class ResizeEvent;
 class QPixmap;
@@ -95,16 +96,52 @@ private:
     bool b_expandPixmap;
     bool b_withart;
     QPropertyAnimation *fadeAnimation;
-    virtual void contextMenuEvent( QContextMenuEvent *event );
+    virtual void contextMenuEvent( QContextMenuEvent *event ); 
 protected:
     void paintEvent( QPaintEvent *e );
     virtual void showEvent( QShowEvent * e );
     static const int MARGIN = 5;
+    QString defaultArt;
 public slots:
     void toggle(){ TOGGLEV( this ); }
     void updateArt( const QString& );
 };
 
+class EasterEggBackgroundWidget : public BackgroundWidget
+{
+    Q_OBJECT
+
+public:
+    EasterEggBackgroundWidget( intf_thread_t * );
+    virtual ~EasterEggBackgroundWidget();
+
+public slots:
+    void animate();
+
+protected:
+    void paintEvent( QPaintEvent *e );
+    void showEvent( QShowEvent *e );
+    void hideEvent( QHideEvent * );
+    void resizeEvent( QResizeEvent * );
+
+private slots:
+    void spawnFlakes();
+    void reset();
+
+private:
+    struct flake
+    {
+        QPoint point;
+        bool b_fat;
+    };
+    QTimer *timer;
+    QLinkedList<flake *> *flakes;
+    int i_rate;
+    int i_speed;
+    bool b_enabled;
+    static const int MAX_FLAKES = 1000;
+};
+
 #if 0
 class VisualSelector : public QFrame
 {
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 05f5888..f479e4e 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -97,7 +97,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     input_name           = "";
     b_interfaceFullScreen= false;
     b_hasPausedWhenMinimized = false;
-
+    i_kc_offset          = false;
 
     /* Ask for Privacy */
     FirstRun::CheckAndRun( this, p_intf );
@@ -381,7 +381,15 @@ void MainInterface::createMainWidget( QSettings *creationSettings )
     stackCentralW = new QVLCStackedWidget( main );
 
     /* Bg Cone */
-    bgWidget = new BackgroundWidget( p_intf );
+    if ( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY
+         && var_InheritBool( p_intf, "qt-icon-change" ) )
+    {
+        bgWidget = new EasterEggBackgroundWidget( p_intf );
+        CONNECT( this, kc_pressed(), bgWidget, animate() );
+    }
+    else
+        bgWidget = new BackgroundWidget( p_intf );
+
     stackCentralW->addWidget( bgWidget );
     if ( !var_InheritBool( p_intf, "qt-bgcone" ) )
         bgWidget->setWithArt( false );
@@ -853,6 +861,14 @@ void MainInterface::togglePlaylist()
     debug();
 }
 
+const Qt::Key MainInterface::kc[10] =
+{
+    Qt::Key_Up, Qt::Key_Up,
+    Qt::Key_Down, Qt::Key_Down,
+    Qt::Key_Left, Qt::Key_Right, Qt::Key_Left, Qt::Key_Right,
+    Qt::Key_B, Qt::Key_A
+};
+
 void MainInterface::dockPlaylist( bool p_docked )
 {
     if( b_plDocked == p_docked ) return;
@@ -1312,6 +1328,18 @@ void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
 void MainInterface::keyPressEvent( QKeyEvent *e )
 {
     handleKeyPress( e );
+
+    /* easter eggs sequence handling */
+    if ( e->key() == kc[ i_kc_offset ] )
+        i_kc_offset++;
+    else
+        i_kc_offset = 0;
+
+    if ( i_kc_offset == (sizeof( kc ) / sizeof( Qt::Key )) )
+    {
+        i_kc_offset = 0;
+        emit kc_pressed();
+    }
 }
 
 void MainInterface::handleKeyPress( QKeyEvent *e )
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index ae0a624..c0ed1eb 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -181,6 +181,9 @@ private:
     void createTaskBarButtons();
 #endif
 
+    static const Qt::Key kc[10]; /* easter eggs */
+    int i_kc_offset;
+
 public slots:
     void dockPlaylist( bool b_docked = true );
     void toggleMinimalView( bool );
@@ -262,7 +265,7 @@ signals:
     void askToQuit();
     void askBoss();
     void askRaise();
-
+    void kc_pressed(); /* easter eggs */
 };
 
 #endif



More information about the vlc-commits mailing list