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>
|
2013-05-22 17:11:49 +00:00
|
|
|
#include <QComboBox>
|
2013-05-02 22:27:36 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2013-05-22 17:11:49 +00:00
|
|
|
|
|
|
|
QWidget* TankInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
QComboBox *comboDelegate = new QComboBox(parent);
|
|
|
|
TankInfoModel *model = new TankInfoModel;
|
|
|
|
QString data = index.model()->data(index, Qt::DisplayRole).toString();
|
|
|
|
comboDelegate->setModel(model);
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < model->rowCount(); i++){
|
|
|
|
if (model->data(model->index(i,0), Qt::DisplayRole).toString() == data){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i != model->rowCount())
|
|
|
|
comboDelegate->setCurrentIndex(i);
|
|
|
|
return comboDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
TankInfoDelegate::TankInfoDelegate(QObject* parent): QStyledItemDelegate(parent)
|
|
|
|
{
|
|
|
|
}
|