mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Added support for showing the Stars on the DiveTable
For the stars on the dive table I had to rework a bit my StarRating widget, because it used a pixmap for each widget that were created. Not it uses only 2 pixmaps: the active and inactive ones. A new file was created named modeldelegates(h, cpp) that should hold all delegates of the models. For the GTK / C folks, a 'Delegate' ia s way to bypass the default behavior of the view that's displaying the data. I also added the code to display the stars if no delegate is set ( good for debugging. ) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
1d0d42f861
commit
2f4d6bbe53
9 changed files with 115 additions and 59 deletions
36
qt-ui/modeldelegates.cpp
Normal file
36
qt-ui/modeldelegates.cpp
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue