<commit_before>/*****************************************************************************
 * icon_view.cpp : Icon view for the Playlist
 ****************************************************************************
 * Copyright © 2010 the VideoLAN team
 * $Id$
 *
 * Authors:         <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#include "components/playlist/icon_view.hpp"
#include "components/playlist/playlist_model.hpp"
#include "input_manager.hpp"

#include <QApplication>
#include <QPainter>
#include <QRect>
#include <QStyleOptionViewItem>
#include <QFontMetrics>
#include <QPixmapCache>

#include "assert.h"

#define RECT_SIZE           100
#define ART_SIZE            64
#define OFFSET              (RECT_SIZE-64)/2
#define ITEMS_SPACING       10
#define ART_RADIUS          5


static const QRect drawRect = QRect( 0, 0, RECT_SIZE, RECT_SIZE );
static const QRect artRect = drawRect.adjusted( OFFSET - 1, 0, - OFFSET, - OFFSET *2 );

void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
    PLItem *currentItem = static_cast<PLItem*>( index.internalPointer() );
    assert( currentItem );

    char *meta;

    meta = input_item_GetTitleFbName( currentItem->inputItem() );
    QString title = qfu( meta );
    free( meta );

    meta = input_item_GetArtist( currentItem->inputItem() );
    QString artist = qfu( meta );
    free( meta );

    QString artUrl = InputManager::decodeArtURL( currentItem->inputItem() );

    // look up through all children and use the first picture found
    if( artUrl.isEmpty() )
    {
        int children = currentItem->childCount();
        for( int i = 0; i < children; i++ )
        {
            PLItem *child = currentItem->child( i );
            artUrl = InputManager::decodeArtURL( child->inputItem() );
            if( !artUrl.isEmpty() )
                break;
        }
    }

    /*if( option.state & QStyle::State_Selected )
         painter->fillRect(option.rect, option.palette.highlight());*/
    QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option,
                                          painter );

    // picture where all the rendering happens and which will be cached
    QPixmap pix;

    QString key = title + artist + artUrl
                  + QString( index.data( PLModel::IsCurrentRole ).toBool() );
    if(QPixmapCache::find( key, pix ))
    {
        // cool, we found it in the cache
        painter->drawPixmap( option.rect, pix );
        return;
    }

    // load album art
    QPixmap artPix;
    if( artUrl.isEmpty() || !artPix.load( artUrl ) )
        artPix = QPixmap( ":/noart64" );
    else
        artPix = artPix.scaled( ART_SIZE, ART_SIZE,
                Qt::KeepAspectRatioByExpanding );

    pix = QPixmap( RECT_SIZE, RECT_SIZE );
    pix.fill( Qt::transparent );

    QPainter *pixpainter = new QPainter( &pix );

    pixpainter->setRenderHints(
            QPainter::Antialiasing | QPainter::SmoothPixmapTransform |
            QPainter::TextAntialiasing );

    if( index.data( PLModel::IsCurrentRole ).toBool() )
    {
       pixpainter->save();
       pixpainter->setOpacity( 0.2 );
       pixpainter->setBrush( QBrush( Qt::gray ) );
       pixpainter->drawRoundedRect( 0, -1, RECT_SIZE, RECT_SIZE+1, ART_RADIUS, ART_RADIUS );
       pixpainter->restore();
    }

    // Draw the drop shadow
    pixpainter->save();
    pixpainter->setOpacity( 0.7 );
    pixpainter->setBrush( QBrush( Qt::gray ) );
    pixpainter->drawRoundedRect( artRect.adjusted( 2, 2, 2, 2 ), ART_RADIUS, ART_RADIUS );
    pixpainter->restore();

    // Draw the art pix
    QPainterPath artRectPath;
    artRectPath.addRoundedRect( artRect, ART_RADIUS, ART_RADIUS );
    pixpainter->setClipPath( artRectPath );
    pixpainter->drawPixmap( artRect, artPix );
    pixpainter->setClipping( false );
<commit_msg>Qt4: adjust iconviews art position littlebit<commit_after>/*****************************************************************************
 * icon_view.cpp : Icon view for the Playlist
 ****************************************************************************
 * Copyright © 2010 the VideoLAN team
 * $Id$
 *
 * Authors:         <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#include "components/playlist/icon_view.hpp"
#include "components/playlist/playlist_model.hpp"
#include "input_manager.hpp"

#include <QApplication>
#include <QPainter>
#include <QRect>
#include <QStyleOptionViewItem>
#include <QFontMetrics>
#include <QPixmapCache>

#include "assert.h"

#define RECT_SIZE           100
#define ART_SIZE            64
#define OFFSET              (RECT_SIZE-64)/2
#define ITEMS_SPACING       10
#define ART_RADIUS          5


static const QRect drawRect = QRect( 0, 0, RECT_SIZE, RECT_SIZE );
static const QRect artRect = drawRect.adjusted( OFFSET - 1, 2, - OFFSET, - OFFSET *2 );

void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
    PLItem *currentItem = static_cast<PLItem*>( index.internalPointer() );
    assert( currentItem );

    char *meta;

    meta = input_item_GetTitleFbName( currentItem->inputItem() );
    QString title = qfu( meta );
    free( meta );

    meta = input_item_GetArtist( currentItem->inputItem() );
    QString artist = qfu( meta );
    free( meta );

    QString artUrl = InputManager::decodeArtURL( currentItem->inputItem() );

    // look up through all children and use the first picture found
    if( artUrl.isEmpty() )
    {
        int children = currentItem->childCount();
        for( int i = 0; i < children; i++ )
        {
            PLItem *child = currentItem->child( i );
            artUrl = InputManager::decodeArtURL( child->inputItem() );
            if( !artUrl.isEmpty() )
                break;
        }
    }

    /*if( option.state & QStyle::State_Selected )
         painter->fillRect(option.rect, option.palette.highlight());*/
    QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option,
                                          painter );

    // picture where all the rendering happens and which will be cached
    QPixmap pix;

    QString key = title + artist + artUrl
                  + QString( index.data( PLModel::IsCurrentRole ).toBool() );
    if(QPixmapCache::find( key, pix ))
    {
        // cool, we found it in the cache
        painter->drawPixmap( option.rect, pix );
        return;
    }

    // load album art
    QPixmap artPix;
    if( artUrl.isEmpty() || !artPix.load( artUrl ) )
        artPix = QPixmap( ":/noart64" );
    else
        artPix = artPix.scaled( ART_SIZE, ART_SIZE,
                Qt::KeepAspectRatioByExpanding );

    pix = QPixmap( RECT_SIZE, RECT_SIZE );
    pix.fill( Qt::transparent );

    QPainter *pixpainter = new QPainter( &pix );

    pixpainter->setRenderHints(
            QPainter::Antialiasing | QPainter::SmoothPixmapTransform |
            QPainter::TextAntialiasing );

    if( index.data( PLModel::IsCurrentRole ).toBool() )
    {
       pixpainter->save();
       pixpainter->setOpacity( 0.2 );
       pixpainter->setBrush( QBrush( Qt::gray ) );
       pixpainter->drawRoundedRect( 0, 0, RECT_SIZE, RECT_SIZE, ART_RADIUS, ART_RADIUS );
       pixpainter->restore();
    }

    // Draw the drop shadow
    pixpainter->save();
    pixpainter->setOpacity( 0.7 );
    pixpainter->setBrush( QBrush( Qt::gray ) );
    pixpainter->drawRoundedRect( artRect.adjusted( 2, 2, 2, 2 ), ART_RADIUS, ART_RADIUS );
    pixpainter->restore();

    // Draw the art pix
    QPainterPath artRectPath;
    artRectPath.addRoundedRect( artRect, ART_RADIUS, ART_RADIUS );
    pixpainter->setClipPath( artRectPath );
    pixpainter->drawPixmap( artRect, artPix );
    pixpainter->setClipping( false );

{'fraction_non_alphanumeric': 0.1532776349614396, 'fraction_numerical': 0.00985432733504713, 'mean_word_length': 3.104175824175824, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4662975', 'n_tokens_mistral': 2970, 'n_tokens_neox': 2688, 'n_words': 787}