1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 00:09:47 +01:00

* OverlayWidget now expects a QAbstractItemView which it automatically connects all signals to.

This commit is contained in:
Christian Muehlhaeuser 2012-05-31 21:31:01 +02:00
parent 7a8818ae94
commit 7bdc5ea4f2
2 changed files with 38 additions and 3 deletions

View File

@ -30,7 +30,7 @@
#define OPACITY 0.70
OverlayWidget::OverlayWidget( QWidget* parent )
OverlayWidget::OverlayWidget( QAbstractItemView* parent )
: QWidget( parent ) // this is on purpose!
, m_opacity( 0.00 )
, m_parent( parent )
@ -42,6 +42,12 @@ OverlayWidget::OverlayWidget( QWidget* parent )
m_timer.setSingleShot( true );
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, SIGNAL( modelChanged() ), SLOT( onViewModelChanged() ) );
#ifdef Q_WS_MAC
QFont f( font() );
@ -120,6 +126,31 @@ OverlayWidget::shown() const
}
void
OverlayWidget::onViewChanged()
{
if ( m_parent->model()->rowCount() )
{
hide();
}
else
{
show();
}
}
void
OverlayWidget::onViewModelChanged()
{
if ( m_parent->model() )
{
connect( m_parent->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ), Qt::UniqueConnection );
onViewChanged();
}
}
void
OverlayWidget::paintEvent( QPaintEvent* event )
{

View File

@ -31,7 +31,7 @@ Q_OBJECT
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
public:
OverlayWidget( QWidget* parent );
OverlayWidget( QAbstractItemView* parent );
~OverlayWidget();
qreal opacity() const { return m_opacity; }
@ -49,12 +49,16 @@ public slots:
protected:
// void changeEvent( QEvent* e );
void paintEvent( QPaintEvent* event );
private slots:
void onViewChanged();
void onViewModelChanged();
private:
QString m_text;
qreal m_opacity;
QWidget* m_parent;
QAbstractItemView* m_parent;
QTimer m_timer;
};