KDEUI
#include <Nepomuk/KRatingPainter>
Public Member Functions | |
KRatingPainter () | |
~KRatingPainter () | |
Qt::Alignment | alignment () const |
QPixmap | customPixmap () const |
bool | halfStepsEnabled () const |
QIcon | icon () const |
bool | isEnabled () const |
Qt::LayoutDirection | layoutDirection () const |
int | maxRating () const |
void | paint (QPainter *painter, const QRect &rect, int rating, int hoverRating=-1) const |
int | ratingFromPosition (const QRect &rect, const QPoint &pos) const |
void | setAlignment (Qt::Alignment align) |
void | setCustomPixmap (const QPixmap &pixmap) |
void | setEnabled (bool enabled) |
void | setHalfStepsEnabled (bool enabled) |
void | setIcon (const QIcon &icon) |
void | setLayoutDirection (Qt::LayoutDirection direction) |
void | setMaxRating (int max) |
void | setSpacing (int spacing) |
int | spacing () const |
Static Public Member Functions | |
static int | getRatingFromPosition (const QRect &rect, Qt::Alignment align, Qt::LayoutDirection direction, const QPoint &pos) |
static void | paintRating (QPainter *p, const QRect &rect, Qt::Alignment align, int rating, int hoverRating=-1) |
Detailed Description
Utility class that draws a row of stars for a rating value.
The KRatingPainter also allows to determine a rating value from a position in the draw area. it supports all different alignments and custom icons.
For showing a rating in a widget see KRatingWidget.
- Since
- 4.1
Definition at line 50 of file kratingpainter.h.
Constructor & Destructor Documentation
KRatingPainter::KRatingPainter | ( | ) |
Create a new KRatingPainter.
For most cases the static methods paintRating and getRatingFromPosition should be sufficient.
Definition at line 75 of file kratingpainter.cpp.
KRatingPainter::~KRatingPainter | ( | ) |
Destructor.
Definition at line 81 of file kratingpainter.cpp.
Member Function Documentation
Qt::Alignment KRatingPainter::alignment | ( | ) | const |
QPixmap KRatingPainter::customPixmap | ( | ) | const |
The custom pixmap set to draw a star.
If no custom pixmap has been set, an invalid pixmap is returned.
- See also
- setCustomPixmap
Definition at line 123 of file kratingpainter.cpp.
|
static |
Get the rating that would be selected if the user clicked position pos within rect if the rating has been drawn with paintRating() using the same rect and align values.
- Returns
- The new rating or -1 if pos is outside of the rating area.
Definition at line 352 of file kratingpainter.cpp.
bool KRatingPainter::halfStepsEnabled | ( | ) | const |
If half steps are enabled one star equals to 2 rating points and uneven rating values result in half-stars being drawn.
- See also
- setHalfStepsEnabled
Definition at line 93 of file kratingpainter.cpp.
QIcon KRatingPainter::icon | ( | ) | const |
The icon used to draw a star.
In case a custom pixmap has been set this value is ignored.
- See also
- setIcon, setCustomPixmap
Definition at line 111 of file kratingpainter.cpp.
bool KRatingPainter::isEnabled | ( | ) | const |
The rating can be painted in a disabled state where no color is used and hover ratings are ignored.
- See also
- setEnabled
Definition at line 117 of file kratingpainter.cpp.
Qt::LayoutDirection KRatingPainter::layoutDirection | ( | ) | const |
The layout direction.
If RTL the stars representing the rating value will be drawn from the right.
- See also
- setLayoutDirection
Definition at line 105 of file kratingpainter.cpp.
int KRatingPainter::maxRating | ( | ) | const |
The maximum rating, i.e.
how many stars are drawn in total.
- See also
- setMaxRating
Definition at line 87 of file kratingpainter.cpp.
void KRatingPainter::paint | ( | QPainter * | painter, |
const QRect & | rect, | ||
int | rating, | ||
int | hoverRating = -1 |
||
) | const |
Draw the rating.
- Parameters
-
painter The painter to draw the rating to. rect The geometry of the rating. The alignment of the rating is used relative to this value. rating The actual rating value to draw. hoverRating The hover rating indicates the position the user hovers the mouse pointer at. This will provide visual feedback about the new rating if the user would actually click as well as the difference to the current rating.
Definition at line 183 of file kratingpainter.cpp.
|
static |
Convenience method that paints a rating into the given rect.
LayoutDirection is read from QPainter.
- Parameters
-
align can be aligned vertically and horizontally. Using Qt::AlignJustify will insert spacing between the stars.
Definition at line 343 of file kratingpainter.cpp.
Calculate the rating value from mouse position pos.
- Returns
- The rating corresponding to pos or -1 if pos is outside of the configured rect.
Definition at line 288 of file kratingpainter.cpp.
void KRatingPainter::setAlignment | ( | Qt::Alignment | align | ) |
The alignment of the stars in the drawing rect.
All alignment flags are supported.
Definition at line 147 of file kratingpainter.cpp.
void KRatingPainter::setCustomPixmap | ( | const QPixmap & | pixmap | ) |
Set a custom pixmap.
Definition at line 171 of file kratingpainter.cpp.
void KRatingPainter::setEnabled | ( | bool | enabled | ) |
Enable or disable the rating.
Default is enabled.
Definition at line 165 of file kratingpainter.cpp.
void KRatingPainter::setHalfStepsEnabled | ( | bool | enabled | ) |
If half steps are enabled (the default) then one rating step corresponds to half a star.
Definition at line 141 of file kratingpainter.cpp.
void KRatingPainter::setIcon | ( | const QIcon & | icon | ) |
void KRatingPainter::setLayoutDirection | ( | Qt::LayoutDirection | direction | ) |
LTR or RTL.
Definition at line 153 of file kratingpainter.cpp.
void KRatingPainter::setMaxRating | ( | int | max | ) |
void KRatingPainter::setSpacing | ( | int | spacing | ) |
Set the spacing between rating pixmaps.
Be aware that for justified horizontal alignment this values may be ignored.
Definition at line 177 of file kratingpainter.cpp.
int KRatingPainter::spacing | ( | ) | const |
The spacing between rating pixmaps.
- See also
- setSpacing
Definition at line 129 of file kratingpainter.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.