/*****************************************************************************
* 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>
#include <QKeyEvent>
#include <QWheelEvent>
#include <QPixmap>
+#include <QApplication>
#include <vlc_keys.h>
-QVLCFramelessButton::QVLCFramelessButton( QWidget *parent )
+QFramelessButton::QFramelessButton( QWidget *parent )
: QPushButton( parent )
{
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
}
-void QVLCFramelessButton::paintEvent( QPaintEvent * )
+void QFramelessButton::paintEvent( QPaintEvent * )
{
QPainter painter( this );
QPixmap pix = icon().pixmap( size() );
painter.drawPixmap( QRect( pos.x(), pos.y(), pix.width(), pix.height() ), pix );
}
-QVLCElidingLabel::QVLCElidingLabel( const QString &s, Qt::TextElideMode mode, QWidget * parent )
- : elideMode( mode ), QLabel( s, parent )
+QElidingLabel::QElidingLabel( const QString &s, Qt::TextElideMode mode, QWidget * parent )
+ : QLabel( s, parent ), elideMode( mode )
{ }
-void QVLCElidingLabel::setElideMode( Qt::TextElideMode mode )
+void QElidingLabel::setElideMode( Qt::TextElideMode mode )
{
elideMode = mode;
repaint();
}
-void QVLCElidingLabel::paintEvent( QPaintEvent * event )
+void QElidingLabel::paintEvent( QPaintEvent * )
{
QPainter p( this );
int space = frameWidth() + margin();
p.drawText( r, fontMetrics().elidedText( text(), elideMode, r.width() ), alignment() );
}
-QString DebugLevelSpinBox::textFromValue( int v ) const
+QString QVLCDebugLevelSpinBox::textFromValue( int v ) const
{
QString const texts[] = {
/* Note that min level 0 is 'errors' in Qt Ui
// 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 )
- : 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 )
+ int i = msecs / interval;
+ if ( i >= pixmaps.count() ) i = pixmaps.count() - 1; /* roundings */
+ if ( i != current_frame )
{
- // Replace idle frame
- delete mIdleFrame;
- mIdleFrame = new QPixmap( pxm );
- setPixmap( *mIdleFrame );
- return;
+ current_frame = i;
+ currentPixmap = pixmaps.at( current_frame );
+ emit pixmapReady( *currentPixmap );
}
- QPixmap *copy = new QPixmap( pxm );
- mFrames.insert( ( index < 0 || index > mFrames.size() ) ? mFrames.size() :
- index, copy );
- if( !pixmap() )
- setPixmap( *copy );
}
-void AnimatedIcon::play( int loops, int interval )
+/* Animated Icon implementation */
+SpinningIcon::SpinningIcon( QWidget *parent ) : QLabel( parent )
{
- if( interval < 20 )
- {
-#ifndef NDEBUG
- printf( "AnimatedIcon::play(): interval is too short (%d ms)",
- interval );
-#endif
- interval = 20;
- }
-
- if( !mIdleFrame && ( mFrames.empty() | loops != 0 ) )
- {
-#ifndef NDEBUG
- printf( "AnimatedIcon::play(): no frames to display" );
-#endif
- return;
- }
-
- if( loops == 0 )
- {
- // Stop playback
- mCurrentFrame = mRemainingLoops = 0;
- mTimer.stop();
- setPixmap( mIdleFrame != NULL ? *mIdleFrame : *mFrames.last() );
- return;
- }
-
- if( loops <= -1 )
- loops = -1;
+ 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 );
+}
- mCurrentFrame = 1;
- mRemainingLoops = loops;
- mTimer.start( interval );
- setPixmap( *mFrames.first() );
+QToolButtonExt::QToolButtonExt(QWidget *parent, int ms )
+ : 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()) );
}
-// private slot
-void AnimatedIcon::onTimerTick()
+/* 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()
{
- //assert( !mFrames.empty() );
- if( ++mCurrentFrame > mFrames.size() )
+ if( isDown() )
+ {
+ // we are beginning a long click
+ longClick = true;
+ shortClick = false;
+ }
+ else
{
- if( mRemainingLoops != -1 )
+ if( longClick )
{
- if( --mRemainingLoops == 0 )
- {
- mTimer.stop();
- setPixmap( mIdleFrame ? *mIdleFrame : *mFrames.last() );
- return;
- }
+ // we are stopping a long click
+ longClick = false;
+ shortClick = false;
+ }
+ else
+ {
+ // we are generating a short click
+ longClick = false;
+ shortClick = true;
}
- mCurrentFrame = 1;
}
- //assert( mCurrentFrame >= 1 && mCurrentFrame <= mFrames.size() );
- setPixmap( *mFrames.at( mCurrentFrame - 1 ) );
}
-
-/* SpinningIcon implementation */
-
-SpinningIcon::SpinningIcon( QWidget *parent, bool noIdleFrame )
- : AnimatedIcon( parent )
+void QToolButtonExt::clickedSlot()
{
- 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" ) );
- setScaledContents( true );
- setFixedSize( 16, 16 );
+ if( longClick )
+ emit longClicked();
+ else if( shortClick )
+ emit shortClicked();
}
-SpinningIcon::~SpinningIcon()
+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);\
+ }\
+ ");
}