mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02:00
* Fade-in the overlay box.
This commit is contained in:
@@ -24,7 +24,7 @@ TrackView::TrackView( QWidget* parent )
|
||||
, m_proxyModel( 0 )
|
||||
, m_delegate( 0 )
|
||||
, m_header( new TrackHeader( this ) )
|
||||
, m_overlay( new OverlayWidget() )
|
||||
, m_overlay( new OverlayWidget( this ) )
|
||||
, m_resizing( false )
|
||||
{
|
||||
setSortingEnabled( false );
|
||||
@@ -289,8 +289,6 @@ TrackView::onFilterChanged( const QString& )
|
||||
{
|
||||
if ( selectedIndexes().count() )
|
||||
scrollTo( selectedIndexes().at( 0 ), QAbstractItemView::PositionAtCenter );
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,10 +1,18 @@
|
||||
#include "overlaywidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
#define CORNER_ROUNDNESS 32.0
|
||||
#define FADEIN_DURATION 500
|
||||
#define FONT_SIZE 18
|
||||
#define OPACITY 0.80
|
||||
|
||||
|
||||
OverlayWidget::OverlayWidget()
|
||||
: QWidget()
|
||||
OverlayWidget::OverlayWidget( QAbstractItemView* parent )
|
||||
: QWidget() // this is on purpose!
|
||||
, m_parent( parent )
|
||||
{
|
||||
resize( 380, 220 );
|
||||
setAttribute( Qt::WA_TranslucentBackground, true );
|
||||
@@ -16,12 +24,31 @@ OverlayWidget::~OverlayWidget()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OverlayWidget::setOpacity( qreal opacity )
|
||||
{
|
||||
m_opacity = opacity;
|
||||
m_parent->reset();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OverlayWidget::setText( const QString& text )
|
||||
{
|
||||
if ( text == m_text )
|
||||
return;
|
||||
|
||||
if ( isEnabled() )
|
||||
{
|
||||
QPropertyAnimation* animation = new QPropertyAnimation( this, "opacity" );
|
||||
animation->setDuration( FADEIN_DURATION );
|
||||
animation->setStartValue( 0.00 );
|
||||
animation->setEndValue( OPACITY );
|
||||
animation->start();
|
||||
}
|
||||
else
|
||||
m_opacity = OPACITY;
|
||||
|
||||
m_text = text;
|
||||
m_pixmap = QPixmap();
|
||||
}
|
||||
@@ -54,7 +81,10 @@ OverlayWidget::paint( QPainter* painter )
|
||||
QRect center( QPoint( ( painter->viewport().width() - m_pixmap.width() ) / 2,
|
||||
( painter->viewport().height() - m_pixmap.height() ) / 2 ), m_pixmap.size() );
|
||||
|
||||
painter->save();
|
||||
painter->setOpacity( m_opacity );
|
||||
painter->drawPixmap( center, m_pixmap );
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,15 +99,14 @@ OverlayWidget::paintEvent( QPaintEvent* event )
|
||||
|
||||
p.setPen( palette().shadow().color() );
|
||||
p.setBrush( palette().shadow() );
|
||||
p.setOpacity( 0.7 );
|
||||
|
||||
p.drawRoundedRect( r, 32.0, 32.0 );
|
||||
p.drawRoundedRect( r, CORNER_ROUNDNESS, CORNER_ROUNDNESS );
|
||||
|
||||
QTextOption to( Qt::AlignCenter );
|
||||
to.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
|
||||
|
||||
QFont f( font() );
|
||||
f.setPixelSize( 18 );
|
||||
f.setPixelSize( FONT_SIZE );
|
||||
f.setBold( true );
|
||||
|
||||
p.setFont( f );
|
||||
|
@@ -2,19 +2,24 @@
|
||||
#define OVERLAYWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QAbstractItemView>
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
class DLLEXPORT OverlayWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
|
||||
|
||||
public:
|
||||
OverlayWidget();
|
||||
OverlayWidget( QAbstractItemView* parent );
|
||||
~OverlayWidget();
|
||||
|
||||
QPixmap pixmap();
|
||||
|
||||
qreal opacity() const { return m_opacity; }
|
||||
void setOpacity( qreal opacity );
|
||||
|
||||
QString text() const { return m_text; }
|
||||
void setText( const QString& text );
|
||||
|
||||
@@ -27,6 +32,9 @@ protected:
|
||||
private:
|
||||
QString m_text;
|
||||
QPixmap m_pixmap;
|
||||
qreal m_opacity;
|
||||
|
||||
QAbstractItemView* m_parent;
|
||||
};
|
||||
|
||||
#endif // WELCOMEWIDGET_H
|
||||
|
Reference in New Issue
Block a user