summaryrefslogtreecommitdiffstats
path: root/qt-ui/modeldelegates.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-04-27 20:53:25 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-04-27 20:53:25 -0700
commit4179885da79d4d2ba0a4893331e162235765ad0f (patch)
treea01a38c68deab7ca159c11658fa053133c15254e /qt-ui/modeldelegates.cpp
parent4bb0cd8cef2bbbbe3df6fc3daa9ccca95f065038 (diff)
parent2f4d6bbe535a195046b4746fd3a771087ee4a6c4 (diff)
downloadsubsurface-4179885da79d4d2ba0a4893331e162235765ad0f.tar.gz
Merge branch 'RenderStarsOnTable' of https://github.com/tcanabrava/subsurface into Qt
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r--qt-ui/modeldelegates.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
new file mode 100644
index 000000000..1bbf1061b
--- /dev/null
+++ b/qt-ui/modeldelegates.cpp
@@ -0,0 +1,36 @@
+#include "modeldelegates.h"
+#include "../dive.h"
+#include "../divelist.h"
+#include "starwidget.h"
+#include "models.h"
+
+#include <QtDebug>
+#include <QPainter>
+
+void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+ if (!index.isValid()){
+ return;
+ }
+
+ int rating = index.model()->data(index, DiveTripModel::DelegatesRole).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);
+}