rpcs3/rpcs3/rpcs3qt/game_list_grid_delegate.cpp
Megamouse a3d1f7b7b0 Grid Mode + Tool Bar (#2857)
* Grid layout

* Add Tiny Mode
fix scrolling
fix maxGamesPerRow calculation

* prime empty toolbar

* Add Search Bar, Icon Size and List Mode to ToolBar
Fix some minor glitches

* fix toolbar save and adjust default margin

* fix toolbar regression
minor simplification in Refresh

* Implement search and rename PopulateUI to PopulateGameList

* minor refactoring hehehehehehe

* Fix crash

* refresh speedboost optimizations

* Small refactoring of refresh to have default argument of false.

* add icons to toolbar

* fix scrambed order

* search for serial as well
2017-06-11 15:07:00 +01:00

54 lines
1.7 KiB
C++

#include "game_list_grid_delegate.h"
game_list_grid_delegate::game_list_grid_delegate(const QSize& size, const qreal& margin_factor, const qreal& text_factor, QObject *parent)
: QAbstractItemDelegate(parent), m_size(size), m_margin_factor(margin_factor), m_text_factor(text_factor)
{
}
game_list_grid_delegate::~game_list_grid_delegate()
{
}
void game_list_grid_delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QRect r = option.rect;
painter->eraseRect(r);
//Color: #333
QPen fontPen(QColor::fromRgb(51, 51, 51), 1, Qt::SolidLine);
//Get title and image
QPixmap image = (qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)));
QString title = index.data(Qt::DisplayRole).toString();
// image
if (image.isNull() == false)
{
painter->drawPixmap(r, image);
}
// Add selection overlay
if (option.state & QStyle::State_Selected)
{
QLinearGradient gradientSelected(r.left(), r.top(), r.left(), r.height() + r.top());
gradientSelected.setColorAt(0.0, QColor::fromRgba(qRgba(119, 213, 247, 128)));
gradientSelected.setColorAt(0.9, QColor::fromRgba(qRgba(27, 134, 183, 128)));
gradientSelected.setColorAt(1.0, QColor::fromRgba(qRgba(0, 120, 174, 128)));
painter->fillRect(r, gradientSelected);
}
int h = r.height() / (1 + m_margin_factor + m_margin_factor*m_text_factor);
int height = r.height() - h - h * m_margin_factor;
int top = r.bottom() - height;
// title
painter->setPen(fontPen);
painter->setFont(QFont("Lucida Grande", 8, QFont::DemiBold));
painter->drawText(QRect(r.left(), top, r.width(), height), Qt::TextWordWrap | Qt::AlignCenter, title);
}
QSize game_list_grid_delegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{
return m_size;
}