diff --git a/src/libtomahawk/playlist/GridItemDelegate.cpp b/src/libtomahawk/playlist/GridItemDelegate.cpp index f4447f20e..2cfd0a38b 100644 --- a/src/libtomahawk/playlist/GridItemDelegate.cpp +++ b/src/libtomahawk/playlist/GridItemDelegate.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2011-2012, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,6 +50,7 @@ namespace { GridItemDelegate::GridItemDelegate( QAbstractItemView* parent, PlayableProxyModel* proxy ) : QStyledItemDelegate( (QObject*)parent ) + , TomahawkUtils::DpiScaler( parent ) , m_view( parent ) , m_model( proxy ) { @@ -304,10 +306,11 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q m_playButton.clear(); ImageButton* button = new ImageButton( m_view ); - button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButton, TomahawkUtils::Original, QSize( 48, 48 ) ) ); - button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButtonPressed, TomahawkUtils::Original, QSize( 48, 48 ) ), QIcon::Off, QIcon::Active ); - button->setFixedSize( 48, 48 ); - button->move( option.rect.center() - QPoint( 23, 23 ) ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButton, TomahawkUtils::Original, scaled( 48, 48 ) ) ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButtonPressed, TomahawkUtils::Original, scaled( 48, 48 ) ), QIcon::Off, QIcon::Active ); + button->setFixedSize( scaled( 48, 48 ) ); + button->move( option.rect.center() - QPoint( button->width() / 2, + button->height() / 2 ) ); button->setContentsMargins( 0, 0, 0, 0 ); button->setFocusPolicy( Qt::NoFocus ); button->installEventFilter( this ); @@ -425,17 +428,20 @@ GridItemDelegate::onViewChanged() foreach ( const QPersistentModelIndex& index, m_spinner.keys() ) { QRect rect = m_view->visualRect( index ); - m_spinner.value( index )->move( rect.center() - QPoint( 23, 23 ) ); + m_spinner.value( index )->move( rect.center() - QPoint( m_spinner.value( index )->width() / 2, + m_spinner.value( index )->height() / 2 ) ); } foreach ( const QPersistentModelIndex& index, m_playButton.keys() ) { QRect rect = m_view->visualRect( index ); - m_playButton.value( index )->move( rect.center() - QPoint( 23, 23 ) ); + m_playButton.value( index )->move( rect.center() - QPoint( m_playButton.value( index )->width() / 2, + m_playButton.value( index )->height() / 2 ) ); } foreach ( const QPersistentModelIndex& index, m_pauseButton.keys() ) { QRect rect = m_view->visualRect( index ); - m_pauseButton.value( index )->move( rect.center() - QPoint( 23, 23 ) ); + m_pauseButton.value( index )->move( rect.center() - QPoint( m_pauseButton.value( index )->width() / 2, + m_pauseButton.value( index )->height() / 2 ) ); } } @@ -466,13 +472,13 @@ GridItemDelegate::updatePlayPauseButton( ImageButton* button, bool setState ) { if ( button->property( "paused" ).toBool() ) { - button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButton, TomahawkUtils::Original, QSize( 48, 48 ) ) ); - button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButtonPressed, TomahawkUtils::Original, QSize( 48, 48 ) ), QIcon::Off, QIcon::Active ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButton, TomahawkUtils::Original, scaled( 48, 48 ) ) ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButtonPressed, TomahawkUtils::Original, scaled( 48, 48 ) ), QIcon::Off, QIcon::Active ); } else { - button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButton, TomahawkUtils::Original, QSize( 48, 48 ) ) ); - button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButtonPressed, TomahawkUtils::Original, QSize( 48, 48 ) ), QIcon::Off, QIcon::Active ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButton, TomahawkUtils::Original, scaled( 48, 48 ) ) ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PlayButtonPressed, TomahawkUtils::Original, scaled( 48, 48 ) ), QIcon::Off, QIcon::Active ); } if ( setState ) @@ -551,10 +557,11 @@ void GridItemDelegate::createPauseButton( const QPersistentModelIndex& index ) { ImageButton* button = new ImageButton( m_view ); - button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButton, TomahawkUtils::Original, QSize( 48, 48 ) ) ); - button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButtonPressed, TomahawkUtils::Original, QSize( 48, 48 ) ), QIcon::Off, QIcon::Active ); - button->setFixedSize( 48, 48 ); - button->move( m_view->visualRect( index ).center() - QPoint( 23, 23 ) ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButton, TomahawkUtils::Original, scaled( 48, 48 ) ) ); + button->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::PauseButtonPressed, TomahawkUtils::Original, scaled( 48, 48 ) ), QIcon::Off, QIcon::Active ); + button->setFixedSize( scaled( 48, 48 ) ); + button->move( m_view->visualRect( index ).center() - QPoint( button->width() / 2, + button->height() / 2 ) ); button->setContentsMargins( 0, 0, 0, 0 ); button->setFocusPolicy( Qt::NoFocus ); button->installEventFilter( this ); diff --git a/src/libtomahawk/playlist/GridItemDelegate.h b/src/libtomahawk/playlist/GridItemDelegate.h index 002daa589..a6b8e2f8e 100644 --- a/src/libtomahawk/playlist/GridItemDelegate.h +++ b/src/libtomahawk/playlist/GridItemDelegate.h @@ -24,6 +24,7 @@ #include #include "DllMacro.h" +#include "utils/DpiScaler.h" namespace Tomahawk { class PixmapDelegateFader; @@ -38,7 +39,7 @@ class QTimeLine; class PlayableProxyModel; class ImageButton; -class DLLEXPORT GridItemDelegate : public QStyledItemDelegate +class DLLEXPORT GridItemDelegate : public QStyledItemDelegate, private TomahawkUtils::DpiScaler { Q_OBJECT diff --git a/src/libtomahawk/playlist/GridView.cpp b/src/libtomahawk/playlist/GridView.cpp index 913fb5f6d..6a446a3e6 100644 --- a/src/libtomahawk/playlist/GridView.cpp +++ b/src/libtomahawk/playlist/GridView.cpp @@ -51,6 +51,7 @@ using namespace Tomahawk; GridView::GridView( QWidget* parent ) : QListView( parent ) + , TomahawkUtils::DpiScaler( this ) , m_model( 0 ) , m_proxyModel( 0 ) , m_delegate( 0 ) @@ -247,7 +248,7 @@ GridView::verifySize() scrollbar = 0; //don't count it any more const int rectWidth = contentsRect().width() - scrollbar - 3; - const int itemWidth = 160; + const int itemWidth = scaledX( 160 ); const int itemsPerRow = qMax( 1, qFloor( rectWidth / itemWidth ) ); const int overlapRows = m_model->rowCount( QModelIndex() ) % itemsPerRow; @@ -287,7 +288,7 @@ GridView::layoutItems() scrollbar = 0; //don't count it any more const int rectWidth = contentsRect().width() - scrollbar - 3; - const int itemWidth = 160; + const int itemWidth = scaledX( 160 ); const int itemsPerRow = qMax( 1, qFloor( rectWidth / itemWidth ) ); const int remSpace = rectWidth - ( itemsPerRow * itemWidth ); diff --git a/src/libtomahawk/playlist/GridView.h b/src/libtomahawk/playlist/GridView.h index 8b5de2c83..4cc5216ee 100644 --- a/src/libtomahawk/playlist/GridView.h +++ b/src/libtomahawk/playlist/GridView.h @@ -28,6 +28,8 @@ #include "PlayableProxyModel.h" #include "widgets/OverlayWidget.h" #include "DllMacro.h" +#include "utils/DpiScaler.h" + namespace Tomahawk { @@ -39,7 +41,9 @@ class GridItemDelegate; class PlayableModel; class GridPlaylistInterface; -class DLLEXPORT GridView : public QListView, public Tomahawk::ViewPage +class DLLEXPORT GridView : public QListView, + public Tomahawk::ViewPage, + private TomahawkUtils::DpiScaler { Q_OBJECT