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