mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-25 15:01:11 +02:00
* DpiScale GridView & delegate.
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include "utils/PixmapDelegateFader.h"
|
#include "utils/PixmapDelegateFader.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
#include "utils/AnimatedSpinner.h"
|
#include "utils/AnimatedSpinner.h"
|
||||||
|
#include "utils/DpiScaler.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -52,6 +53,7 @@ GridItemDelegate::GridItemDelegate( QAbstractItemView* parent, PlayableProxyMode
|
|||||||
: QStyledItemDelegate( (QObject*)parent )
|
: QStyledItemDelegate( (QObject*)parent )
|
||||||
, m_view( parent )
|
, m_view( parent )
|
||||||
, m_model( proxy )
|
, m_model( proxy )
|
||||||
|
, m_margin( TomahawkUtils::DpiScaler::scaledY( parent, 32 ) )
|
||||||
{
|
{
|
||||||
if ( m_view && m_view->metaObject()->indexOfSignal( "modelChanged()" ) > -1 )
|
if ( m_view && m_view->metaObject()->indexOfSignal( "modelChanged()" ) > -1 )
|
||||||
connect( m_view, SIGNAL( modelChanged() ), this, SLOT( modelChanged() ) );
|
connect( m_view, SIGNAL( modelChanged() ), this, SLOT( modelChanged() ) );
|
||||||
@@ -185,7 +187,7 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
QFont smallFont = font;
|
QFont smallFont = font;
|
||||||
smallFont.setPointSize( TomahawkUtils::defaultFontSize() );
|
smallFont.setPointSize( TomahawkUtils::defaultFontSize() );
|
||||||
|
|
||||||
QRect textRect = option.rect.adjusted( 0, r.height() + 8, 0, 0 );
|
QRect textRect = option.rect.adjusted( 0, r.height() + m_margin / 4, 0, 0 );
|
||||||
bool oneLiner = false;
|
bool oneLiner = false;
|
||||||
if ( bottom.isEmpty() )
|
if ( bottom.isEmpty() )
|
||||||
oneLiner = true;
|
oneLiner = true;
|
||||||
@@ -205,7 +207,7 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
}
|
}
|
||||||
|
|
||||||
to.setAlignment( Qt::AlignLeft | Qt::AlignTop );
|
to.setAlignment( Qt::AlignLeft | Qt::AlignTop );
|
||||||
text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 );
|
text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - m_margin / 8 );
|
||||||
painter->drawText( textRect, text, to );
|
painter->drawText( textRect, text, to );
|
||||||
|
|
||||||
// Calculate rect of artist on-hover button click area
|
// Calculate rect of artist on-hover button click area
|
||||||
@@ -223,7 +225,7 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
}
|
}
|
||||||
|
|
||||||
to.setAlignment( Qt::AlignLeft | Qt::AlignTop );
|
to.setAlignment( Qt::AlignLeft | Qt::AlignTop );
|
||||||
text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 );
|
text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - m_margin / 8 );
|
||||||
painter->drawText( textRect, text, to );
|
painter->drawText( textRect, text, to );
|
||||||
|
|
||||||
if ( item->album() )
|
if ( item->album() )
|
||||||
@@ -244,9 +246,9 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
painter->setFont( f );
|
painter->setFont( f );
|
||||||
}
|
}
|
||||||
|
|
||||||
textRect.adjust( 0, 2, 0, 2 );
|
textRect.adjust( 0, m_margin / 16, 0, m_margin / 16 );
|
||||||
to.setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
|
to.setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
|
||||||
text = painter->fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 3 );
|
text = painter->fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - m_margin / 8 );
|
||||||
painter->drawText( textRect, text, to );
|
painter->drawText( textRect, text, to );
|
||||||
|
|
||||||
// Calculate rect of artist on-hover button click area
|
// Calculate rect of artist on-hover button click area
|
||||||
@@ -347,7 +349,7 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
|
|||||||
cRect.setHeight( cRect.width() );
|
cRect.setHeight( cRect.width() );
|
||||||
|
|
||||||
HoverControls* controls = new HoverControls( m_view );
|
HoverControls* controls = new HoverControls( m_view );
|
||||||
controls->setFixedSize( 64, 40 );
|
controls->setFixedSize( m_margin * 2, m_margin + m_margin / 4 );
|
||||||
controls->move( cRect.center() - QPoint( controls->width() / 2 -1, controls->height() / 2 -1 ) );
|
controls->move( cRect.center() - QPoint( controls->width() / 2 -1, controls->height() / 2 -1 ) );
|
||||||
controls->setContentsMargins( 0, 0, 0, 0 );
|
controls->setContentsMargins( 0, 0, 0, 0 );
|
||||||
controls->setFocusPolicy( Qt::NoFocus );
|
controls->setFocusPolicy( Qt::NoFocus );
|
||||||
|
@@ -100,6 +100,8 @@ private:
|
|||||||
mutable QHash< QPersistentModelIndex, QWidget* > m_spinner;
|
mutable QHash< QPersistentModelIndex, QWidget* > m_spinner;
|
||||||
mutable QHash< QPersistentModelIndex, HoverControls* > m_hoverControls;
|
mutable QHash< QPersistentModelIndex, HoverControls* > m_hoverControls;
|
||||||
mutable QHash< QPersistentModelIndex, QTimeLine* > m_hoverFaders;
|
mutable QHash< QPersistentModelIndex, QTimeLine* > m_hoverFaders;
|
||||||
|
|
||||||
|
const int m_margin;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GRIDITEMDELEGATE_H
|
#endif // GRIDITEMDELEGATE_H
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "ContextMenu.h"
|
#include "ContextMenu.h"
|
||||||
#include "ViewManager.h"
|
#include "ViewManager.h"
|
||||||
#include "MetaPlaylistInterface.h"
|
#include "MetaPlaylistInterface.h"
|
||||||
|
#include "utils/DpiScaler.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/AnimatedSpinner.h"
|
#include "utils/AnimatedSpinner.h"
|
||||||
#include "utils/PixmapDelegateFader.h"
|
#include "utils/PixmapDelegateFader.h"
|
||||||
@@ -65,7 +66,7 @@ GridView::GridView( QWidget* parent )
|
|||||||
setDropIndicatorShown( false );
|
setDropIndicatorShown( false );
|
||||||
setDragDropOverwriteMode( false );
|
setDragDropOverwriteMode( false );
|
||||||
setUniformItemSizes( true );
|
setUniformItemSizes( true );
|
||||||
setSpacing( 16 );
|
setSpacing( TomahawkUtils::DpiScaler::scaledX( this, 16 ) );
|
||||||
setContentsMargins( 0, 0, 0, 0 );
|
setContentsMargins( 0, 0, 0, 0 );
|
||||||
setMouseTracking( true );
|
setMouseTracking( true );
|
||||||
setContextMenuPolicy( Qt::CustomContextMenu );
|
setContextMenuPolicy( Qt::CustomContextMenu );
|
||||||
@@ -78,7 +79,8 @@ GridView::GridView( QWidget* parent )
|
|||||||
|
|
||||||
setAutoFitItems( true );
|
setAutoFitItems( true );
|
||||||
setAutoResize( false );
|
setAutoResize( false );
|
||||||
setItemSize( QSize( 170, 170 + 56 ) );
|
|
||||||
|
setItemSize( TomahawkUtils::DpiScaler::scaled( this, QSize( 170, 170 + 56 ) ) );
|
||||||
setProxyModel( new PlayableProxyModel( this ) );
|
setProxyModel( new PlayableProxyModel( this ) );
|
||||||
|
|
||||||
m_timer.setInterval( SCROLL_TIMEOUT );
|
m_timer.setInterval( SCROLL_TIMEOUT );
|
||||||
|
Reference in New Issue
Block a user