2013-04-27 15:27:27 +00:00
|
|
|
#include "modeldelegates.h"
|
|
|
|
#include "../dive.h"
|
|
|
|
#include "../divelist.h"
|
|
|
|
#include "starwidget.h"
|
|
|
|
#include "models.h"
|
|
|
|
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QPainter>
|
2013-04-28 11:45:22 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2013-05-02 22:27:36 +00:00
|
|
|
#include <QStyle>
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
|
|
|
StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
|
|
|
|
QStyledItemDelegate(parent),
|
|
|
|
parentWidget(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2013-04-27 15:27:27 +00:00
|
|
|
|
|
|
|
void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
|
|
{
|
2013-05-02 22:27:36 +00:00
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
2013-05-02 23:32:57 +00:00
|
|
|
|
2013-05-02 05:00:08 +00:00
|
|
|
if (!index.isValid())
|
2013-04-27 15:27:27 +00:00
|
|
|
return;
|
|
|
|
|
2013-05-02 23:32:57 +00:00
|
|
|
QVariant value = index.model()->data(index, TreeItemDT::STAR_ROLE);
|
2013-05-02 21:19:15 +00:00
|
|
|
|
2013-05-02 05:00:08 +00:00
|
|
|
if (!value.isValid())
|
2013-05-02 02:51:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int rating = value.toInt();
|
|
|
|
|
2013-04-27 15:27:27 +00:00
|
|
|
painter->save();
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
|
|
|
|
for(int i = 0; i < rating; i++)
|
|
|
|
painter->drawPixmap(option.rect.x() + i * IMG_SIZE + SPACING, option.rect.y(), StarWidget::starActive());
|
|
|
|
|
|
|
|
for(int i = rating; i < TOTALSTARS; i++)
|
|
|
|
painter->drawPixmap(option.rect.x() + i * IMG_SIZE + SPACING, option.rect.y(), StarWidget::starInactive());
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize StarWidgetsDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS-1), IMG_SIZE);
|
|
|
|
}
|