File indexing completed on 2024-07-21 03:49:19

0001 /*
0002     SPDX-FileCopyrightText: 2010-2012 Alejandro Fiestas Olivares <afiestas@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "playgrounddelegate.h"
0008 #include <QPainter>
0009 
0010 PlaygroundDelegate::PlaygroundDelegate(QObject *parent): QAbstractItemDelegate(parent)
0011 { }
0012 
0013 QSize PlaygroundDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
0014 {
0015   Q_UNUSED(option);
0016   Q_UNUSED(index);
0017   return QSize(200,100);
0018 }
0019 
0020 void PlaygroundDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
0021 {
0022   QString title = index.model()->data(index, Qt::DisplayRole).toString();
0023   QPixmap pixmap = index.model()->data(index,Qt::UserRole).value<QPixmap>();
0024 
0025   //Paint background with highlight
0026   painter->save();
0027   if (option.state & QStyle::State_Selected) {
0028       painter->setBrush(option.palette.color(QPalette::Highlight));
0029   } else {
0030       painter->setBrush(Qt::gray);
0031   }
0032   painter->drawRect(option.rect);
0033   painter->restore();
0034 
0035   //Any way of do this more beatifuly?
0036   painter->drawPixmap(option.rect.x()+4,option.rect.y()+4,option.rect.width()-8,option.rect.height()-8,pixmap);
0037   QFont font = painter->font();
0038   font.setWeight(QFont::Bold);
0039 
0040   painter->setFont(font);
0041   painter->drawText(option.rect, Qt::AlignCenter | Qt::TextWordWrap, title);
0042   painter->save();
0043   painter->restore();
0044 }