KRatingPainter

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.

Author
Sebastian Trueg trueg.nosp@m.@kde.nosp@m..org
Since
4.1

Definition at line 37 of file kratingpainter.h.

Constructor & Destructor Documentation

◆ KRatingPainter()

KRatingPainter::KRatingPainter ( )

Create a new KRatingPainter.

For most cases the static methods paintRating and getRatingFromPosition should be sufficient.

Definition at line 66 of file kratingpainter.cpp.

◆ ~KRatingPainter()

KRatingPainter::~KRatingPainter ( )
default

Destructor.

Member Function Documentation

◆ alignment()

Qt::Alignment KRatingPainter::alignment ( ) const

The alignment of the stars.

See also
setAlignment

Definition at line 83 of file kratingpainter.cpp.

◆ customPixmap()

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

◆ getRatingFromPosition()

int KRatingPainter::getRatingFromPosition ( const QRect & rect,
Qt::Alignment align,
Qt::LayoutDirection direction,
const QPoint & pos )
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 371 of file kratingpainter.cpp.

◆ halfStepsEnabled()

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

◆ icon()

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

◆ isEnabled()

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

◆ layoutDirection()

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

◆ maxRating()

int KRatingPainter::maxRating ( ) const

The maximum rating, i.e.

how many stars are drawn in total.

See also
setMaxRating

Definition at line 73 of file kratingpainter.cpp.

◆ paint()

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

Draw the rating.

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

◆ paintRating()

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

Convenience method that paints a rating into the given rect.

LayoutDirection is read from QPainter.

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

Definition at line 363 of file kratingpainter.cpp.

◆ ratingFromPosition()

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

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

◆ setAlignment()

void KRatingPainter::setAlignment ( Qt::Alignment align)

The alignment of the stars in the drawing rect.

All alignment flags are supported.

Definition at line 123 of file kratingpainter.cpp.

◆ setCustomPixmap()

void KRatingPainter::setCustomPixmap ( const QPixmap & pixmap)

Set a custom pixmap.

Definition at line 143 of file kratingpainter.cpp.

◆ setEnabled()

void KRatingPainter::setEnabled ( bool enabled)

Enable or disable the rating.

Default is enabled.

Definition at line 138 of file kratingpainter.cpp.

◆ setHalfStepsEnabled()

void KRatingPainter::setHalfStepsEnabled ( bool enabled)

If half steps are enabled (the default) then one rating step corresponds to half a star.

Definition at line 118 of file kratingpainter.cpp.

◆ setIcon()

void KRatingPainter::setIcon ( const QIcon & icon)

Set a custom icon.

Defaults to "rating".

Definition at line 133 of file kratingpainter.cpp.

◆ setLayoutDirection()

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

LTR or RTL.

Definition at line 128 of file kratingpainter.cpp.

◆ setMaxRating()

void KRatingPainter::setMaxRating ( int max)

The maximum rating.

Defaults to 10.

Definition at line 113 of file kratingpainter.cpp.

◆ setSpacing()

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

◆ spacing()

int KRatingPainter::spacing ( ) const

The spacing between rating pixmaps.

See also
setSpacing

Definition at line 108 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-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:04:19 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.