Now the list and dives will work in the same way that the GTK version does. The code got changed heavly because the old one was just looking at the dives and didn't worked like a tree. small adaptations on the list view and model delegates because of the changes done on this model. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#include "modeldelegates.h"
|
|
#include "../dive.h"
|
|
#include "../divelist.h"
|
|
#include "starwidget.h"
|
|
#include "models.h"
|
|
|
|
#include <QtDebug>
|
|
#include <QPainter>
|
|
#include <QSortFilterProxyModel>
|
|
|
|
void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
{
|
|
if (!index.isValid()){
|
|
return;
|
|
}
|
|
|
|
QVariant value = index.model()->data(index, Qt::DisplayRole);
|
|
|
|
if (!value.isValid()){
|
|
return;
|
|
}
|
|
|
|
int rating = value.toInt();
|
|
|
|
if(option.state & QStyle::State_Selected)
|
|
painter->fillRect(option.rect, option.palette.highlight());
|
|
|
|
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);
|
|
}
|