• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Nepomuk

KRatingPainter Class Reference

Utility class that draws a row of stars for a rating value. More...

#include <kratingpainter.h>

List of all members.

Public Member Functions

Qt::Alignment alignment () const
QPixmap customPixmap () const
bool halfStepsEnabled () const
QIcon icon () const
bool isEnabled () const
 KRatingPainter ()
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
 ~KRatingPainter ()

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@kde.org>
Since:
4.1

Definition at line 48 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.

KRatingPainter::~KRatingPainter (  ) 

Destructor.


Member Function Documentation

Qt::Alignment KRatingPainter::alignment (  )  const

The alignment of the stars.

See also:
setAlignment
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
static 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.
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
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
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
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
int KRatingPainter::maxRating (  )  const

The maximum rating, i.e.

how many stars are drawn in total.

See also:
setMaxRating
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.
static 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:
align can be aligned vertically and horizontally. Using Qt::AlignJustify will insert spacing between the stars.
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.
void KRatingPainter::setAlignment ( Qt::Alignment  align  ) 

The alignment of the stars in the drawing rect.

All alignment flags are supported.

void KRatingPainter::setCustomPixmap ( const QPixmap &  pixmap  ) 

Set a custom pixmap.

void KRatingPainter::setEnabled ( bool  enabled  ) 

Enable or disable the rating.

Default is enabled.

void KRatingPainter::setHalfStepsEnabled ( bool  enabled  ) 

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

void KRatingPainter::setIcon ( const QIcon &  icon  ) 

Set a custom icon.

Defaults to "rating".

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

LTR or RTL.

void KRatingPainter::setMaxRating ( int  max  ) 

The maximum rating.

Defaults to 10.

void KRatingPainter::setSpacing ( int  spacing  ) 

Set the spacing between rating pixmaps.

Be aware that for justified horizontal alignment this values may be ignored.

int KRatingPainter::spacing (  )  const

The spacing between rating pixmaps.

See also:
setSpacing

The documentation for this class was generated from the following file:
  • kratingpainter.h

Nepomuk

Skip menu "Nepomuk"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal