[vlc-devel] commit: Qt: get a correct icon_View design (Jean-Baptiste Kempf )
git version control
git at videolan.org
Mon Jan 25 11:50:27 CET 2010
vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Mon Jan 25 11:49:47 2010 +0100| [9a26920ddbba39e495ffe5ff4456f314518d6393] | committer: Jean-Baptiste Kempf
Qt: get a correct icon_View design
This is not top quality yet, but it is usable.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9a26920ddbba39e495ffe5ff4456f314518d6393
---
modules/gui/qt4/components/playlist/icon_view.cpp | 43 +++++++++++++++++++-
1 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/icon_view.cpp b/modules/gui/qt4/components/playlist/icon_view.cpp
index 47519c2..a5ee237 100644
--- a/modules/gui/qt4/components/playlist/icon_view.cpp
+++ b/modules/gui/qt4/components/playlist/icon_view.cpp
@@ -23,17 +23,55 @@
#include "components/playlist/icon_view.hpp"
#include "components/playlist/playlist_model.hpp"
+#include "input_manager.hpp"
#include <QPainter>
+#include <QRect>
+#include <QStyleOptionViewItem>
+
+#include "assert.h"
+
+#define RECT_SIZE 100
+#define ART_SIZE 64
+#define OFFSET (100-64)/2
void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
- QStyledItemDelegate::paint( painter, option, index );
+ painter->setRenderHint( QPainter::Antialiasing );
+
+ if( option.state & QStyle::State_Selected )
+ painter->fillRect(option.rect, option.palette.highlight());
+
+ PLItem *currentItem = static_cast<PLItem*>( index.internalPointer() );
+ assert( currentItem );
+
+ QPixmap pix;
+ QString url = InputManager::decodeArtURL( currentItem->inputItem() );
+
+ if( !url.isEmpty() && pix.load( url ) )
+ {
+ pix = pix.scaled( ART_SIZE, ART_SIZE, Qt::KeepAspectRatioByExpanding );
+ }
+ else
+ {
+ pix = QPixmap( ":/noart.png" );
+ }
+
+ QRect art_rect = option.rect.adjusted( OFFSET - 1, 0, - OFFSET, - OFFSET *2 );
+
+ painter->drawPixmap( art_rect, pix );
+
+ painter->setFont( QFont( "Verdana", 7 ) );
+
+ QRect textRect = option.rect.adjusted( 1, ART_SIZE + 2, -1, -1 );
+ painter->drawText( textRect, qfu( input_item_GetTitle( currentItem->inputItem() ) ),
+ QTextOption( Qt::AlignCenter ) );
+
}
QSize PlListViewItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
- return QSize(100, 100);
+ return QSize( RECT_SIZE, RECT_SIZE);
}
@@ -46,4 +84,3 @@ PlIconView::PlIconView( PLModel *model, QWidget *parent ) : QListView( parent )
PlListViewItemDelegate *pl = new PlListViewItemDelegate();
setItemDelegate( pl );
}
-
More information about the vlc-devel
mailing list