Search for usage in LXR

#include <KRatingPainter>

Public Member Functions

 KRatingPainter ()
 KRatingPainter (const KRatingPainter &)=delete
 ~KRatingPainter ()
Qt::Alignment alignment () const
QPixmap customPixmap () const
bool halfStepsEnabled () const
QIcon icon () const
bool isEnabled () const
Qt::LayoutDirection layoutDirection () const
int maxRating () const
KRatingPainteroperator= (const KRatingPainter &)=delete
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.

Sebastian Trueg trueg[email protected]@kde[email protected].org

Definition at line 37 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 62 of file kratingpainter.cpp.

KRatingPainter::~KRatingPainter ( )


Member Function Documentation

Qt::Alignment KRatingPainter::alignment ( ) const

The alignment of the stars.

See also

Definition at line 79 of file kratingpainter.cpp.

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

Definition at line 99 of file kratingpainter.cpp.

int KRatingPainter::getRatingFromPosition ( const QRect rect,
Qt::Alignment  align,
Qt::LayoutDirection  direction,
const QPoint pos 

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.

The new rating or -1 if pos is outside of the rating area.

Definition at line 367 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

Definition at line 74 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 89 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

Definition at line 94 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

Definition at line 84 of file kratingpainter.cpp.

int KRatingPainter::maxRating ( ) const

The maximum rating, i.e.

how many stars are drawn in total.

See also

Definition at line 69 of file kratingpainter.cpp.

void KRatingPainter::paint ( QPainter painter,
const QRect rect,
int  rating,
int  hoverRating = -1 
) const

Draw the rating.

painterThe painter to draw the rating to.
rectThe geometry of the rating. The alignment of the rating is used relative to this value.
ratingThe actual rating value to draw.
hoverRatingThe 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 177 of file kratingpainter.cpp.

void KRatingPainter::paintRating ( QPainter p,
const QRect rect,
Qt::Alignment  align,
int  rating,
int  hoverRating = -1 

Convenience method that paints a rating into the given rect.

LayoutDirection is read from QPainter.

aligncan be aligned vertically and horizontally. Using Qt::AlignJustify will insert spacing between the stars.

Definition at line 359 of file kratingpainter.cpp.

int KRatingPainter::ratingFromPosition ( const QRect rect,
const QPoint pos 
) const

Calculate the rating value from mouse position pos.

The rating corresponding to pos or -1 if pos is outside of the configured rect.

Definition at line 310 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 119 of file kratingpainter.cpp.

void KRatingPainter::setCustomPixmap ( const QPixmap pixmap)

Set a custom pixmap.

Definition at line 139 of file kratingpainter.cpp.

void KRatingPainter::setEnabled ( bool  enabled)

Enable or disable the rating.

Default is enabled.

Definition at line 134 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 114 of file kratingpainter.cpp.

void KRatingPainter::setIcon ( const QIcon icon)

Set a custom icon.

Defaults to "rating".

Definition at line 129 of file kratingpainter.cpp.

void KRatingPainter::setLayoutDirection ( Qt::LayoutDirection  direction)


Definition at line 124 of file kratingpainter.cpp.

void KRatingPainter::setMaxRating ( int  max)

The maximum rating.

Defaults to 10.

Definition at line 109 of file kratingpainter.cpp.

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 144 of file kratingpainter.cpp.

int KRatingPainter::spacing ( ) const

The spacing between rating pixmaps.

See also

Definition at line 104 of file kratingpainter.cpp.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Jun 18 2021 22:44:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.