mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 23:26:40 +02:00
fixes in dragndrop menu
This commit is contained in:
@@ -61,16 +61,18 @@ void AnimationHelper::expand()
|
|||||||
|
|
||||||
void AnimationHelper::collapse( bool immediately )
|
void AnimationHelper::collapse( bool immediately )
|
||||||
{
|
{
|
||||||
|
m_fullyExpanded = false;
|
||||||
|
m_expandTimer.stop();
|
||||||
|
|
||||||
if ( immediately )
|
if ( immediately )
|
||||||
{
|
{
|
||||||
m_fullyExpanded = false;
|
|
||||||
m_forceClosing = true;
|
m_forceClosing = true;
|
||||||
|
if ( m_size != m_startSize )
|
||||||
m_collapseAnimation->start();
|
m_collapseAnimation->start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//m_fullyExpanded = false;
|
if ( m_size != m_startSize )
|
||||||
m_expandTimer.stop();
|
|
||||||
m_collapseTimer.start();
|
m_collapseTimer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,23 @@ SourceDelegate::SourceDelegate( QAbstractItemView* parent )
|
|||||||
: QStyledItemDelegate( parent )
|
: QStyledItemDelegate( parent )
|
||||||
, m_parent( parent )
|
, m_parent( parent )
|
||||||
{
|
{
|
||||||
|
m_dropTypeMap.insert( 0, SourceTreeItem::DropTypeThisTrack );
|
||||||
|
m_dropTypeMap.insert( 1, SourceTreeItem::DropTypeThisAlbum );
|
||||||
|
m_dropTypeMap.insert( 2, SourceTreeItem::DropTypeAllFromArtist );
|
||||||
|
m_dropTypeMap.insert( 3, SourceTreeItem::DropTypeLocalItems );
|
||||||
|
m_dropTypeMap.insert( 4, SourceTreeItem::DropTypeTop50 );
|
||||||
|
|
||||||
|
m_dropTypeTextMap.insert( 0, "Track" );
|
||||||
|
m_dropTypeTextMap.insert( 1, "Album" );
|
||||||
|
m_dropTypeTextMap.insert( 2, "Artist" );
|
||||||
|
m_dropTypeTextMap.insert( 3, "Local" );
|
||||||
|
m_dropTypeTextMap.insert( 4, "Top 10" );
|
||||||
|
|
||||||
|
m_dropTypeImageMap.insert( 0, QPixmap( ":/data/images/new-additions.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) );
|
||||||
|
m_dropTypeImageMap.insert( 1, QPixmap( ":/data/images/new-additions.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) );
|
||||||
|
m_dropTypeImageMap.insert( 2, QPixmap( ":/data/images/drop-all-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) );
|
||||||
|
m_dropTypeImageMap.insert( 3, QPixmap( ":/data/images/drop-local-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) );
|
||||||
|
m_dropTypeImageMap.insert( 4, QPixmap( ":/data/images/drop-top-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
@@ -169,18 +186,24 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
|
|
||||||
// Get whole rect for the menu
|
// Get whole rect for the menu
|
||||||
QRect itemsRect = option.rect.adjusted( -option.rect.x(), m_expandedMap.value( index )->originalSize().height(), 0, 0 );
|
QRect itemsRect = option.rect.adjusted( -option.rect.x(), m_expandedMap.value( index )->originalSize().height(), 0, 0 );
|
||||||
|
|
||||||
|
QPoint cursorPos = m_parent->mapFromGlobal( QCursor::pos() );
|
||||||
|
bool cursorInRect = false;
|
||||||
|
if ( itemsRect.contains( cursorPos ) )
|
||||||
|
cursorInRect = true;
|
||||||
|
|
||||||
// draw the background
|
// draw the background
|
||||||
|
|
||||||
QLinearGradient linearGradient( 0, 0, 0, itemsRect.height() );
|
QLinearGradient linearGradient( itemsRect.topLeft(), itemsRect.bottomLeft() );
|
||||||
linearGradient.setColorAt( 0.0, QColor( 0xdb, 0x1b, 0x06 ) );
|
linearGradient.setColorAt( 0.0, QColor( 0xdb, 0x1b, 0x06 ) );
|
||||||
linearGradient.setColorAt( 1.0, QColor( 0xf4, 0x17, 0x05 ) );
|
// linearGradient.setColorAt( 1.0, QColor( 0xf4, 0x17, 0x05 ) );
|
||||||
|
linearGradient.setColorAt( 1.0, Qt::black );
|
||||||
painter->setBrush( linearGradient );
|
painter->setBrush( linearGradient );
|
||||||
painter->drawRect( itemsRect );
|
painter->drawRect( itemsRect );
|
||||||
|
|
||||||
|
// calculate sizes for the icons
|
||||||
int totalCount = dropTypeCount( item );
|
int totalCount = dropTypeCount( item );
|
||||||
int itemWidth = itemsRect.width() / totalCount;
|
int itemWidth = itemsRect.width() / totalCount;
|
||||||
int iconSpacing = ( itemWidth - 32 ) / 2;
|
int iconSpacing = ( itemWidth - 32 ) / 2;
|
||||||
@@ -190,8 +213,6 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
QPoint cursorPos = m_parent->mapFromGlobal( QCursor::pos() );
|
|
||||||
|
|
||||||
QPen pen(Qt::white);
|
QPen pen(Qt::white);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
|
|
||||||
@@ -201,58 +222,34 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
QFont fontBold = painter->font();
|
QFont fontBold = painter->font();
|
||||||
fontBold.setBold( true );
|
fontBold.setBold( true );
|
||||||
|
|
||||||
QString text;
|
|
||||||
QRect textRect;
|
QRect textRect;
|
||||||
QPixmap icon;
|
|
||||||
|
|
||||||
QMap< int, SourceTreeItem::DropType > dropTypeMap;
|
|
||||||
dropTypeMap.insert( 0, SourceTreeItem::DropTypeThisTrack );
|
|
||||||
dropTypeMap.insert( 1, SourceTreeItem::DropTypeThisAlbum );
|
|
||||||
dropTypeMap.insert( 2, SourceTreeItem::DropTypeAllFromArtist );
|
|
||||||
dropTypeMap.insert( 3, SourceTreeItem::DropTypeLocalItems );
|
|
||||||
dropTypeMap.insert( 4, SourceTreeItem::DropTypeTop50 );
|
|
||||||
|
|
||||||
QMap< int, QString > dropTypeTextMap;
|
|
||||||
dropTypeTextMap.insert( 0, "Track" );
|
|
||||||
dropTypeTextMap.insert( 1, "Album" );
|
|
||||||
dropTypeTextMap.insert( 2, "Artist" );
|
|
||||||
dropTypeTextMap.insert( 3, "Local" );
|
|
||||||
dropTypeTextMap.insert( 4, "Top 10" );
|
|
||||||
|
|
||||||
QMap< int, QString > dropTypeImageMap;
|
|
||||||
dropTypeImageMap.insert( 0, ":/data/images/new-additions.png" );
|
|
||||||
dropTypeImageMap.insert( 1, ":/data/images/new-additions.png" );
|
|
||||||
dropTypeImageMap.insert( 2, ":/data/images/drop-all-songs.png" );
|
|
||||||
dropTypeImageMap.insert( 3, ":/data/images/drop-local-songs.png" );
|
|
||||||
dropTypeImageMap.insert( 4, ":/data/images/drop-top-songs.png" );
|
|
||||||
|
|
||||||
SourceTreeItem::DropTypes dropTypes = item->supportedDropTypes( m_dropMimeData );
|
SourceTreeItem::DropTypes dropTypes = item->supportedDropTypes( m_dropMimeData );
|
||||||
|
|
||||||
for ( int i = 0; i < 5; ++i )
|
for ( int i = 0; i < 5; ++i )
|
||||||
{
|
{
|
||||||
if ( !dropTypes.testFlag( dropTypeMap.value( i ) ) )
|
if ( !dropTypes.testFlag( m_dropTypeMap.value( i ) ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
text = dropTypeTextMap.value( i );
|
|
||||||
|
|
||||||
if ( count > 0 )
|
if ( count > 0 )
|
||||||
itemsRect.adjust( itemWidth, 0, itemWidth, 0 );
|
itemsRect.adjust( itemWidth, 0, itemWidth, 0 );
|
||||||
|
|
||||||
if ( itemsRect.contains( cursorPos ) )
|
if ( itemsRect.contains( cursorPos ) | !cursorInRect )
|
||||||
{
|
{
|
||||||
painter->setFont( fontBold );
|
painter->setFont( fontBold );
|
||||||
m_hoveredDropType = dropTypeMap.value( i );
|
m_hoveredDropType = m_dropTypeMap.value( i );
|
||||||
|
cursorInRect = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
painter->setFont( font );
|
painter->setFont( font );
|
||||||
|
|
||||||
textRect = itemsRect.adjusted( 0, 4, 0, 0 );
|
textRect = itemsRect.adjusted( 0, 4, 0, 0 );
|
||||||
painter->drawPixmap( textRect.x() + iconSpacing, textRect.y(), QPixmap( dropTypeImageMap.value( i ) ).scaledToWidth( 32, Qt::SmoothTransformation ) );
|
painter->drawPixmap( textRect.x() + iconSpacing, textRect.y(), m_dropTypeImageMap.value( i ) );
|
||||||
|
|
||||||
int textSpacing = ( itemWidth - painter->fontMetrics().width( text ) ) / 2;
|
int textSpacing = ( itemWidth - painter->fontMetrics().width( m_dropTypeTextMap.value( i ) ) ) / 2;
|
||||||
textRect.adjust( textSpacing, 32 + 4, 0, 0 );
|
textRect.adjust( textSpacing, 32 + 6, 0, 0 );
|
||||||
painter->drawText( textRect, text );
|
painter->drawText( textRect, m_dropTypeTextMap.value( i ) );
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,6 +452,10 @@ SourceDelegate::hovered(const QModelIndex &index, const QMimeData *mimeData)
|
|||||||
{
|
{
|
||||||
if ( !index.isValid() )
|
if ( !index.isValid() )
|
||||||
{
|
{
|
||||||
|
foreach ( AnimationHelper *helper, m_expandedMap )
|
||||||
|
{
|
||||||
|
helper->collapse();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( !m_expandedMap.contains( index ) )
|
if ( !m_expandedMap.contains( index ) )
|
||||||
@@ -470,6 +471,8 @@ SourceDelegate::hovered(const QModelIndex &index, const QMimeData *mimeData)
|
|||||||
connect( m_expandedMap.value( m_newDropHoverIndex ), SIGNAL( finished( QModelIndex ) ), SLOT( animationFinished( QModelIndex ) ) );
|
connect( m_expandedMap.value( m_newDropHoverIndex ), SIGNAL( finished( QModelIndex ) ), SLOT( animationFinished( QModelIndex ) ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
qDebug() << "expandedMap already contains index" << index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -37,6 +37,11 @@ private:
|
|||||||
QMimeData *m_dropMimeData;
|
QMimeData *m_dropMimeData;
|
||||||
mutable SourceTreeItem::DropType m_hoveredDropType; // Hack to keep easily track of the current highlighted DropType in paint()
|
mutable SourceTreeItem::DropType m_hoveredDropType; // Hack to keep easily track of the current highlighted DropType in paint()
|
||||||
QMap< QModelIndex, AnimationHelper* > m_expandedMap;
|
QMap< QModelIndex, AnimationHelper* > m_expandedMap;
|
||||||
|
|
||||||
|
QMap< int, SourceTreeItem::DropType > m_dropTypeMap;
|
||||||
|
QMap< int, QString > m_dropTypeTextMap;
|
||||||
|
QMap< int, QPixmap > m_dropTypeImageMap;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SOURCEDELEGATE_H
|
#endif // SOURCEDELEGATE_H
|
||||||
|
@@ -471,6 +471,8 @@ SourceTreeView::dragMoveEvent( QDragMoveEvent* event )
|
|||||||
m_delegate->hovered( index, event->mimeData() );
|
m_delegate->hovered( index, event->mimeData() );
|
||||||
dataChanged(index, index);
|
dataChanged(index, index);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
m_delegate->hovered( QModelIndex(), 0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -586,5 +588,7 @@ SourceTreeView::itemFromIndex( const QModelIndex& index ) const
|
|||||||
void
|
void
|
||||||
SourceTreeView::update( const QModelIndex &index )
|
SourceTreeView::update( const QModelIndex &index )
|
||||||
{
|
{
|
||||||
|
// updateGeometries();
|
||||||
|
// QTreeView::update( index );
|
||||||
dataChanged( index, index );
|
dataChanged( index, index );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user