summaryrefslogtreecommitdiffstats
path: root/qt-ui/modeldelegates.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r--qt-ui/modeldelegates.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
new file mode 100644
index 000000000..be47198e2
--- /dev/null
+++ b/qt-ui/modeldelegates.cpp
@@ -0,0 +1,49 @@
+#include "modeldelegates.h"
+#include "../dive.h"
+#include "../divelist.h"
+#include "starwidget.h"
+#include "models.h"
+
+#include <QtDebug>
+#include <QPainter>
+#include <QSortFilterProxyModel>
+#include <QStyle>
+#include <QStyleOption>
+
+StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
+ QStyledItemDelegate(parent),
+ parentWidget(parent)
+{
+
+}
+
+void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+ QStyledItemDelegate::paint(painter, option, index);
+
+ if (!index.isValid())
+ return;
+
+ QVariant value = index.model()->data(index, TreeItemDT::STAR_ROLE);
+
+ if (!value.isValid())
+ return;
+
+ int rating = value.toInt();
+
+ 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);
+}