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:
@@ -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() )
|
||||||
{
|
{
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user