Message info
 
To:kde-commits@kde.org From:Lamarque V. Souza Subject:[kdelibs/KDE/4.8] kdeui/widgets: Better stars rating in dolphin. Date:Thu, 5 Apr 2012 22:59:11 +0200 (CEST)
 

Git commit 0cc00c8096700946e8990499d5d9c2b7516915e1 by Lamarque V. Souza.
Committed on 05/04/2012 at 22:57.
Pushed by lvsouza into branch 'KDE/4.8'.

Better stars rating in dolphin.
Thanks to Anant Kamath for this patch.

REVIEW: 104479
BUG: 171343
FIXED-IN: 4.8.3

M +39 -4 kdeui/widgets/kratingwidget.cpp

http://commits.kde.org/kdelibs/0cc00c8096700946e8990499d5d9c2b7516915e1

diff --git a/kdeui/widgets/kratingwidget.cpp b/kdeui/widgets/kratingwidget.cpp
index 811ca0a..084555e 100644
--- a/kdeui/widgets/kratingwidget.cpp
+++ b/kdeui/widgets/kratingwidget.cpp
@@ -204,8 +204,30 @@ void KRatingWidget::setOnlyPaintFullSteps( bool fs )
void KRatingWidget::mousePressEvent( QMouseEvent* e )
{
if ( e->button() == Qt::LeftButton ) {
+ const int prevRating = d->rating;
d->hoverRating = d->ratingPainter.ratingFromPosition( contentsRect(), e->pos() );
- setRating( d->hoverRating );
+ if ( !( d->hoverRating % 2 ) ) {
+ if ( d->hoverRating == prevRating + 1 ) {
+ setRating( d->hoverRating - 2 );
+ }
+ else if ( d->hoverRating == prevRating ) {
+ setRating( d->hoverRating - 1 );
+ }
+ else {
+ setRating( d->hoverRating );
+ }
+ }
+ else {
+ if ( d->hoverRating == prevRating - 1 ) {
+ setRating( d->hoverRating );
+ }
+ else if ( d->hoverRating == prevRating ) {
+ setRating( d->hoverRating - 1 );
+ }
+ else {
+ setRating( d->hoverRating + 1 );
+ }
+ }
}
}

@@ -215,12 +237,25 @@ void KRatingWidget::mouseMoveEvent( QMouseEvent* e )
// when moving the mouse we show the user what the result of clicking will be
const int prevHoverRating = d->hoverRating;
d->hoverRating = d->ratingPainter.ratingFromPosition( contentsRect(), e->pos() );
+ if ( !( d->hoverRating % 2 ) ) {
+ if ( d->hoverRating == prevHoverRating + 1 ) {
+ d->hoverRating -= 2;
+ }
+ else if ( d->hoverRating == prevHoverRating ) {
+ d->hoverRating -= 1;
+ }
+ }
+ else {
+ if ( d->hoverRating == prevHoverRating ) {
+ d->hoverRating -= 1;
+ }
+ else {
+ d->hoverRating += 1;
+ }
+ }
if ( d->hoverRating != prevHoverRating ) {
update();
}
- if ( d->hoverRating >= 0 && e->buttons() & Qt::LeftButton ) {
- setRating( d->hoverRating );
- }
}