1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-22 21:54:00 +02:00

* Some of the ugliest, hackiest code I've written in recent times. Hack around broken QColumnView.

This commit is contained in:
Christian Muehlhaeuser
2013-09-05 22:19:46 +02:00
parent 73b023c96e
commit 585a7ad878
2 changed files with 52 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ ColumnView::ColumnView( QWidget* parent )
, m_previewWidget( new ColumnViewPreviewWidget( this ) ) , m_previewWidget( new ColumnViewPreviewWidget( this ) )
, m_updateContextView( true ) , m_updateContextView( true )
, m_contextMenu( new ContextMenu( this ) ) , m_contextMenu( new ContextMenu( this ) )
, m_scrollDelta( 0 )
{ {
setFrameShape( QFrame::NoFrame ); setFrameShape( QFrame::NoFrame );
setAttribute( Qt::WA_MacShowFocusRect, 0 ); setAttribute( Qt::WA_MacShowFocusRect, 0 );
@@ -73,6 +74,7 @@ ColumnView::ColumnView( QWidget* parent )
setSelectionBehavior( QAbstractItemView::SelectRows ); setSelectionBehavior( QAbstractItemView::SelectRows );
setContextMenuPolicy( Qt::CustomContextMenu ); setContextMenuPolicy( Qt::CustomContextMenu );
setProxyModel( new TreeProxyModel( this ) ); setProxyModel( new TreeProxyModel( this ) );
setPreviewWidget( m_previewWidget ); setPreviewWidget( m_previewWidget );
m_timer.setInterval( SCROLL_TIMEOUT ); m_timer.setInterval( SCROLL_TIMEOUT );
@@ -453,9 +455,53 @@ ColumnView::guid() const
} }
void
ColumnView::onScrollBarChanged( int value )
{
QWidget* parent = qobject_cast< QWidget* >( m_previewWidget->parent() );
parent->scroll( 0, m_scrollDelta - value );
m_scrollDelta = value;
}
void
ColumnView::fixScrollBars()
{
foreach ( QObject* widget, children() )
{
foreach ( QObject* view, widget->children() )
{
QScrollBar* sb = qobject_cast< QScrollBar* >( view );
if ( sb && sb->orientation() == Qt::Horizontal )
{
sb->setSingleStep( 6 );
}
foreach ( QObject* subviews, view->children() )
{
foreach ( QObject* scrollbar, subviews->children() )
{
QScrollBar* sb = qobject_cast< QScrollBar* >( scrollbar );
if ( sb && sb->orientation() == Qt::Vertical )
{
sb->setSingleStep( 6 );
connect( sb, SIGNAL( valueChanged( int ) ), SLOT( onScrollBarChanged( int ) ), Qt::UniqueConnection );
break;
}
}
}
}
}
}
void void
ColumnView::onUpdatePreviewWidget( const QModelIndex& index ) ColumnView::onUpdatePreviewWidget( const QModelIndex& index )
{ {
fixScrollBars();
PlayableItem* item = m_proxyModel->itemFromIndex( m_proxyModel->mapToSource( index ) ); PlayableItem* item = m_proxyModel->itemFromIndex( m_proxyModel->mapToSource( index ) );
if ( !item || !item->result() ) if ( !item || !item->result() )
{ {

View File

@@ -97,7 +97,11 @@ private slots:
void onCustomContextMenu( const QPoint& pos ); void onCustomContextMenu( const QPoint& pos );
void onMenuTriggered( int action ); void onMenuTriggered( int action );
void onScrollBarChanged( int value );
private: private:
void fixScrollBars();
OverlayWidget* m_overlay; OverlayWidget* m_overlay;
TreeModel* m_model; TreeModel* m_model;
TreeProxyModel* m_proxyModel; TreeProxyModel* m_proxyModel;
@@ -110,6 +114,8 @@ private:
QModelIndex m_contextMenuIndex; QModelIndex m_contextMenuIndex;
Tomahawk::ContextMenu* m_contextMenu; Tomahawk::ContextMenu* m_contextMenu;
int m_scrollDelta;
QString m_emptyTip; QString m_emptyTip;
QTimer m_timer; QTimer m_timer;
mutable QString m_guid; mutable QString m_guid;