1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 13:47:26 +02:00

* Add an alternative OverlayWidget CTOR for regular QWidgets.

This commit is contained in:
Christian Muehlhaeuser
2012-06-01 10:40:48 +02:00
parent 95dd12aaea
commit f35821b3b5
2 changed files with 54 additions and 27 deletions

View File

@@ -31,27 +31,48 @@
#define OPACITY 0.70 #define OPACITY 0.70
OverlayWidget::OverlayWidget( QWidget* parent )
: QWidget( parent ) // this is on purpose!
, m_parent( parent )
, m_itemView( 0 )
{
init();
}
OverlayWidget::OverlayWidget( QAbstractItemView* parent ) OverlayWidget::OverlayWidget( QAbstractItemView* parent )
: QWidget( parent ) // this is on purpose! : QWidget( parent ) // this is on purpose!
, m_opacity( 0.00 )
, m_parent( parent ) , m_parent( parent )
, m_itemView( parent )
{
init();
if ( m_itemView->model() )
{
connect( m_itemView->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ), Qt::UniqueConnection );
connect( m_itemView->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( onViewChanged() ), Qt::UniqueConnection );
connect( m_itemView->model(), SIGNAL( loadingStarted() ), SLOT( onViewChanged() ), Qt::UniqueConnection );
connect( m_itemView->model(), SIGNAL( loadingFinished() ), SLOT( onViewChanged() ), Qt::UniqueConnection );
}
connect( m_itemView, SIGNAL( modelChanged() ), SLOT( onViewModelChanged() ) );
}
OverlayWidget::~OverlayWidget()
{
}
void
OverlayWidget::init()
{ {
setAttribute( Qt::WA_TranslucentBackground, true ); setAttribute( Qt::WA_TranslucentBackground, true );
m_opacity = 0.00;
setOpacity( m_opacity ); setOpacity( m_opacity );
m_timer.setSingleShot( true ); m_timer.setSingleShot( true );
connect( &m_timer, SIGNAL( timeout() ), this, SLOT( hide() ) ); connect( &m_timer, SIGNAL( timeout() ), this, SLOT( hide() ) );
if ( m_parent->model() )
{
connect( m_parent->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ), Qt::UniqueConnection );
connect( m_parent->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( onViewChanged() ), Qt::UniqueConnection );
connect( m_parent->model(), SIGNAL( loadingStarted() ), SLOT( onViewChanged() ), Qt::UniqueConnection );
connect( m_parent->model(), SIGNAL( loadingFinished() ), SLOT( onViewChanged() ), Qt::UniqueConnection );
}
connect( m_parent, SIGNAL( modelChanged() ), SLOT( onViewModelChanged() ) );
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
QFont f( font() ); QFont f( font() );
f.setPointSize( f.pointSize() - 2 ); f.setPointSize( f.pointSize() - 2 );
@@ -60,11 +81,6 @@ OverlayWidget::OverlayWidget( QAbstractItemView* parent )
} }
OverlayWidget::~OverlayWidget()
{
}
void void
OverlayWidget::setOpacity( qreal opacity ) OverlayWidget::setOpacity( qreal opacity )
{ {
@@ -133,7 +149,10 @@ OverlayWidget::shown() const
void void
OverlayWidget::onViewChanged() OverlayWidget::onViewChanged()
{ {
PlayableProxyModel* model = qobject_cast<PlayableProxyModel*>( m_parent->model() ); if ( !m_itemView )
return;
PlayableProxyModel* model = qobject_cast<PlayableProxyModel*>( m_itemView->model() );
if ( m_text.isEmpty() || ( model && ( model->rowCount( QModelIndex() ) || model->isLoading() ) ) ) if ( m_text.isEmpty() || ( model && ( model->rowCount( QModelIndex() ) || model->isLoading() ) ) )
{ {
@@ -149,12 +168,15 @@ OverlayWidget::onViewChanged()
void void
OverlayWidget::onViewModelChanged() OverlayWidget::onViewModelChanged()
{ {
if ( m_parent->model() ) if ( !m_itemView )
return;
if ( m_itemView->model() )
{ {
connect( m_parent->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ), Qt::UniqueConnection ); connect( m_itemView->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ), Qt::UniqueConnection );
connect( m_parent->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( onViewChanged() ), Qt::UniqueConnection ); connect( m_itemView->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( onViewChanged() ), Qt::UniqueConnection );
connect( m_parent->model(), SIGNAL( loadingStarted() ), SLOT( onViewChanged() ), Qt::UniqueConnection ); connect( m_itemView->model(), SIGNAL( loadingStarted() ), SLOT( onViewChanged() ), Qt::UniqueConnection );
connect( m_parent->model(), SIGNAL( loadingFinished() ), SLOT( onViewChanged() ), Qt::UniqueConnection ); connect( m_itemView->model(), SIGNAL( loadingFinished() ), SLOT( onViewChanged() ), Qt::UniqueConnection );
onViewChanged(); onViewChanged();
} }
@@ -167,7 +189,7 @@ OverlayWidget::paintEvent( QPaintEvent* event )
Q_UNUSED( event ); Q_UNUSED( event );
{ {
QSize maxiSize = QSize( (double)m_parent->viewport()->width() * 0.70, (double)m_parent->viewport()->height() * 0.70 ); QSize maxiSize = QSize( (double)m_parent->width() * 0.70, (double)m_parent->height() * 0.70 );
QSize prefSize = QSize( 380, 128 ); QSize prefSize = QSize( 380, 128 );
int width = qMin( maxiSize.width(), prefSize.width() ); int width = qMin( maxiSize.width(), prefSize.width() );
int height = qMin( maxiSize.height(), prefSize.height() ); int height = qMin( maxiSize.height(), prefSize.height() );

View File

@@ -31,6 +31,7 @@ Q_OBJECT
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
public: public:
OverlayWidget( QWidget* parent );
OverlayWidget( QAbstractItemView* parent ); OverlayWidget( QAbstractItemView* parent );
~OverlayWidget(); ~OverlayWidget();
@@ -55,10 +56,14 @@ private slots:
void onViewModelChanged(); void onViewModelChanged();
private: private:
void init();
QString m_text; QString m_text;
qreal m_opacity; qreal m_opacity;
QAbstractItemView* m_parent; QWidget* m_parent;
QAbstractItemView* m_itemView;
QTimer m_timer; QTimer m_timer;
}; };