/*****************************************************************************
* customwidgets.cpp: Custom widgets
****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2006-2011 the VideoLAN team
* Copyright (C) 2004 Daniel Molkentin <molkentin@kde.org>
* $Id$
*
#endif
#include "customwidgets.hpp"
-#include "qt4.hpp" /*needed for qtr and CONNECT, but not necessary */
+#include "qt4.hpp" /* needed for qtr, but not necessary */
#include <QPainter>
#include <QRect>
// Qt::Key_LaunchMail
// Qt::Key_LaunchMedia
/* Qt::Key_Launch0 through Qt::Key_LaunchF */
- // Qt::Key_MediaLast
+ /* ... */
+ { Qt::Key_Reload, KEY_BROWSER_REFRESH },
};
static int keycmp( const void *a, const void *b )
QString VLCKeyToString( unsigned val )
{
- char *base = vlc_keycode2str (val);
+ char *base = vlc_keycode2str (val, true);
if (base == NULL)
return qtr( "Unset" );
return r;
}
-
-/* Animated Icon implementation */
-
-AnimatedIcon::AnimatedIcon( QWidget *parent )
- : QLabel( parent ), mTimer( this ), mIdleFrame( NULL )
+PixmapAnimator::PixmapAnimator( QWidget *parent, QList<QString> frames )
+ : QAbstractAnimation( parent ), current_frame( 0 )
{
- mCurrentFrame = mRemainingLoops = 0;
- connect( &mTimer, SIGNAL( timeout() ), this, SLOT( onTimerTick() ) );
+ foreach( QString name, frames )
+ pixmaps.append( new QPixmap( name ) );
+ currentPixmap = pixmaps.at( 0 );
+ setFps( frames.count() ); /* default to 1 sec loop */
+ setLoopCount( -1 );
}
-AnimatedIcon::~AnimatedIcon()
+void PixmapAnimator::updateCurrentTime( int msecs )
{
- // We don't need to destroy the timer, he's our child
- delete mIdleFrame;
- foreach( QPixmap *frame, mFrames )
- delete frame;
-}
-
-void AnimatedIcon::addFrame( const QPixmap &pxm, int index )
-{
- if( index == 0 )
- {
- // Replace idle frame
- delete mIdleFrame;
- mIdleFrame = new QPixmap( pxm );
- setPixmap( *mIdleFrame );
- return;
- }
- QPixmap *copy = new QPixmap( pxm );
- mFrames.insert( ( index < 0 || index > mFrames.count() ) ? mFrames.count() :
- index, copy );
- if( !pixmap() )
- setPixmap( *copy );
-}
-
-void AnimatedIcon::play( int loops, int interval )
-{
- if( interval < 20 )
- {
-#ifndef NDEBUG
- printf( "AnimatedIcon::play(): interval is too short (%d ms)",
- interval );
-#endif
- interval = 20;
- }
-
- if( !mIdleFrame && (mFrames.isEmpty() || loops != 0 ) )
+ int i = msecs / interval;
+ if ( i >= pixmaps.count() ) i = pixmaps.count() - 1; /* roundings */
+ if ( i != current_frame )
{
-#ifndef NDEBUG
- printf( "AnimatedIcon::play(): no frames to display" );
-#endif
- return;
+ current_frame = i;
+ currentPixmap = pixmaps.at( current_frame );
+ emit pixmapReady( *currentPixmap );
}
-
- if( loops == 0 )
- {
- // Stop playback
- mCurrentFrame = mRemainingLoops = 0;
- mTimer.stop();
- setPixmap( mIdleFrame != NULL ? *mIdleFrame : *mFrames.last() );
- return;
- }
-
- if( loops <= -1 )
- loops = -1;
-
- mCurrentFrame = 1;
- mRemainingLoops = loops;
- mTimer.start( interval );
- setPixmap( *mFrames.first() );
}
-// private slot
-void AnimatedIcon::onTimerTick()
-{
- //assert( !mFrames.isEmpty() );
- if( ++mCurrentFrame > mFrames.count() )
- {
- if( mRemainingLoops != -1 )
- {
- if( --mRemainingLoops == 0 )
- {
- mTimer.stop();
- setPixmap( mIdleFrame ? *mIdleFrame : *mFrames.last() );
- return;
- }
- }
- mCurrentFrame = 1;
- }
- //assert( mCurrentFrame >= 1 && mCurrentFrame <= mFrames.count() );
- setPixmap( *mFrames.at( mCurrentFrame - 1 ) );
-}
-
-
-/* SpinningIcon implementation */
-
-SpinningIcon::SpinningIcon( QWidget *parent, bool noIdleFrame )
- : AnimatedIcon( parent )
+/* Animated Icon implementation */
+SpinningIcon::SpinningIcon( QWidget *parent ) : QLabel( parent )
{
- if( noIdleFrame )
- addFrame( QPixmap(), 0 );
- else
- addFrame( QPixmap( ":/util/wait0" ), 0 );
- addFrame( QPixmap( ":/util/wait1" ) );
- addFrame( QPixmap( ":/util/wait2" ) );
- addFrame( QPixmap( ":/util/wait3" ) );
- addFrame( QPixmap( ":/util/wait4" ) );
+ QList<QString> frames;
+ frames << ":/util/wait1";
+ frames << ":/util/wait2";
+ frames << ":/util/wait3";
+ frames << ":/util/wait4";
+ animator = new PixmapAnimator( this, frames );
+ CONNECT( animator, pixmapReady( const QPixmap & ), this, setPixmap( const QPixmap & ) );
+ CONNECT( animator, pixmapReady( const QPixmap & ), this, repaint() );
setScaledContents( true );
setFixedSize( 16, 16 );
+ animator->setCurrentTime( 0 );
}
QToolButtonExt::QToolButtonExt(QWidget *parent, int ms )
- :QToolButton( parent ), longClick( false )
+ : QToolButton( parent ),
+ shortClick( false ),
+ longClick( false )
{
setAutoRepeat( true );
/* default to twice the doubleclick delay */
setAutoRepeatDelay( ( ms > 0 )? ms : 2 * QApplication::doubleClickInterval() );
setAutoRepeatInterval( 100 );
connect( this, SIGNAL(released()), this, SLOT(releasedSlot()) );
+ connect( this, SIGNAL(clicked()), this, SLOT(clickedSlot()) );
}
+/* table illustrating the different scenarios and the events generated
+ * ====================
+ *
+ * event isDown()
+ *
+ * released false }
+ * clicked false }= short click
+ *
+ * released false = cancelled click (mouse released outside of button area,
+ * before long click delay kicks in)
+ *
+ * released true }
+ * clicked true }= long click (multiple of these generated)
+ * released false = stop long click (mouse released / moved outside of
+ * button area)
+ * (clicked false) = stop long click (additional event if mouse released
+ * inside of button area)
+ */
+
void QToolButtonExt::releasedSlot()
{
if( isDown() )
+ {
+ // we are beginning a long click
longClick = true;
+ shortClick = false;
+ }
+ else
+ {
+ if( longClick )
+ {
+ // we are stopping a long click
+ longClick = false;
+ shortClick = false;
+ }
+ else
+ {
+ // we are generating a short click
+ longClick = false;
+ shortClick = true;
+ }
+ }
+}
+void QToolButtonExt::clickedSlot()
+{
if( longClick )
emit longClicked();
- else
+ else if( shortClick )
emit shortClicked();
+}
- if( !isDown() )
- longClick = false;
+YesNoCheckBox::YesNoCheckBox( QWidget *parent ) : QCheckBox( parent )
+{
+ setEnabled( false );
+ setStyleSheet("\
+ QCheckBox::indicator:unchecked:hover,\
+ QCheckBox::indicator:unchecked {\
+ image: url(:/menu/quit);\
+ }\
+ QCheckBox::indicator:checked:hover,\
+ QCheckBox::indicator:checked {\
+ image: url(:/valid);\
+ }\
+ ");
}