Commit e9fe22e8 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: BGWidget: split joke code.

And more :)
parent 3b412814
......@@ -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>
......
......@@ -43,6 +43,7 @@
#include <QLabel>
#include <QMouseEvent>
#include <QPropertyAnimation>
#include <QLinkedList>
class ResizeEvent;
class QPixmap;
......@@ -100,11 +101,47 @@ 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
{
......
......@@ -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 */
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 )
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment