| 1 | /* |
| 2 | Copyright 2010, David Sansome <[email protected]> |
| 3 | Copyright (C) 2005-2014 Mario Stephan <[email protected]> |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU Lesser General Public License as published |
| 7 | by the Free Software Foundation; either version 2.1 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public License |
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "ratingwidget.h"cxx . . $ `<file>/src/ratingwidget.h`/ |
| 20 | |
| 21 | #include <QMouseEvent> |
| 22 | #include <QStylePainter> |
| 23 | #include <QtDebug> |
| 24 | |
| 25 | const int RatingPaintercxx . . $ RatingPainter#::kStarCountcxx . . $ RatingPainter#kStarCount.; |
| 26 | const int RatingPaintercxx . . $ RatingPainter#::kStarSizecxx . . $ RatingPainter#kStarSize.; |
| 27 | |
| 28 | RatingPaintercxx . . $ RatingPainter#::RatingPaintercxx . . $ RatingPainter#RatingPainter(49f6e7a06ebc5aa8).() |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | QRectcxx . . $ QRect# RatingPaintercxx . . $ RatingPainter#::Contentscxx . . $ RatingPainter#Contents(e8513ffb6f2deb1c).(const QRectcxx . . $ QRect#& rect) |
| 33 | { |
| 34 | const int width = kStarSizecxx . . $ RatingPainter#kStarSize. * kStarCountcxx . . $ RatingPainter#kStarCount.; |
| 35 | return QRectcxx . . $ QRect#QRect(2261ffe5112eab06).(rect.xcxx . . $ QRect#x(ea6fe5115c70a13f).(), rect.ycxx . . $ QRect#y(ea6fe5115c70a13f).(), width, rect.heightcxx . . $ QRect#height(ea6fe5115c70a13f).()); |
| 36 | } |
| 37 | |
| 38 | double RatingPaintercxx . . $ RatingPainter#::RatingForPoscxx . . $ RatingPainter#RatingForPos(374ff46153e1d7d1).(const QPointcxx . . $ QPoint#& pos, const QRectcxx . . $ QRect#& rect) |
| 39 | { |
| 40 | const QRectcxx . . $ QRect# contents = Contentscxx . . $ RatingPainter#Contents(e8513ffb6f2deb1c).(rect); |
| 41 | const double raw = double(pos.xcxx . . $ QPoint#x(455f465bc33b4cdf).() - contents.leftcxx . . $ QRect#left(ea6fe5115c70a13f).()) / contents.widthcxx . . $ QRect#width(ea6fe5115c70a13f).(); |
| 42 | |
| 43 | // Round to the nearest 0.1 |
| 44 | return double(int(raw * kStarCountcxx . . $ RatingPainter#kStarCount. * 2 + 0.5)) / (kStarCountcxx . . $ RatingPainter#kStarCount. * 2); |
| 45 | } |
| 46 | |
| 47 | void RatingPaintercxx . . $ RatingPainter#::Paintcxx . . $ RatingPainter#Paint(bf4fba74770409a7).(QPaintercxx . . $ QPainter#* painter, const QRectcxx . . $ QRect#& rect, float rating) const |
| 48 | { |
| 49 | Q_UNUSEDcxx . . $ `<external>/15045578679651060896/qglobal.h:117:9`!(rect); |
| 50 | |
| 51 | // save some time here |
| 52 | if (rating == 0) |
| 53 | return; |
| 54 | |
| 55 | rating *= kStarCountcxx . . $ RatingPainter#kStarCount.; |
| 56 | QPixmapcxx . . $ QPixmap# oncxx . . $ QPixmap#QPixmap(dec4543235ec9b46).(":/star-on.png"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 57 | QPixmapcxx . . $ QPixmap# offcxx . . $ QPixmap#QPixmap(dec4543235ec9b46).(":/star-off.png"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 58 | |
| 59 | // Draw the stars |
| 60 | int x = kStarSizecxx . . $ RatingPainter#kStarSize. / 2; |
| 61 | for (int i = 0; i < kStarCountcxx . . $ RatingPainter#kStarCount.; i++, x += kStarSizecxx . . $ RatingPainter#kStarSize.) { |
| 62 | const QRectcxx . . $ QRect# t_rectcxx . . $ QRect#QRect(2261ffe5112eab06).(x, 0, kStarSizecxx . . $ RatingPainter#kStarSize., kStarSizecxx . . $ RatingPainter#kStarSize.); |
| 63 | |
| 64 | if (rating - 0.25 <= i) { |
| 65 | // Totally empty |
| 66 | painter->drawPixmapcxx . . $ QPainter#drawPixmap(579b881b2368aa78).(t_rect, off); |
| 67 | } else if (rating - 0.75 <= i) { |
| 68 | // Half full |
| 69 | const QRectcxx . . $ QRect# target_leftcxx . . $ QRect#QRect(2261ffe5112eab06).(t_rect.xcxx . . $ QRect#x(ea6fe5115c70a13f).(), t_rect.ycxx . . $ QRect#y(ea6fe5115c70a13f).(), kStarSizecxx . . $ RatingPainter#kStarSize. / 2, kStarSizecxx . . $ RatingPainter#kStarSize.); |
| 70 | const QRectcxx . . $ QRect# target_rightcxx . . $ QRect#QRect(2261ffe5112eab06).(t_rect.xcxx . . $ QRect#x(ea6fe5115c70a13f).() + kStarSizecxx . . $ RatingPainter#kStarSize. / 2, t_rect.ycxx . . $ QRect#y(ea6fe5115c70a13f).(), kStarSizecxx . . $ RatingPainter#kStarSize. / 2, kStarSizecxx . . $ RatingPainter#kStarSize.); |
| 71 | const QRectcxx . . $ QRect# source_leftcxx . . $ QRect#QRect(2261ffe5112eab06).(0, 0, kStarSizecxx . . $ RatingPainter#kStarSize. / 2, kStarSizecxx . . $ RatingPainter#kStarSize.); |
| 72 | const QRectcxx . . $ QRect# source_rightcxx . . $ QRect#QRect(2261ffe5112eab06).(kStarSizecxx . . $ RatingPainter#kStarSize. / 2, 0, kStarSizecxx . . $ RatingPainter#kStarSize. / 2, kStarSizecxx . . $ RatingPainter#kStarSize.); |
| 73 | painter->drawPixmapcxx . . $ QPainter#drawPixmap(583800ea2588537e).(target_left, on, source_left); |
| 74 | painter->drawPixmapcxx . . $ QPainter#drawPixmap(583800ea2588537e).(target_right, off, source_right); |
| 75 | } else { |
| 76 | // Totally full |
| 77 | painter->drawPixmapcxx . . $ QPainter#drawPixmap(579b881b2368aa78).(t_rect, on); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | RatingWidgetcxx . . $ RatingWidget#::RatingWidgetcxx . . $ RatingWidget#RatingWidget(108f35f7aa7f3cf9).(QWidgetcxx . . $ QWidget#* parent) |
| 83 | : QWidgetcxx . . $ QWidget#QWidget(872e7b0c281abd8d).(parent) |
| 84 | , rating_cxx . . $ RatingWidget#rating_.(0.0) |
| 85 | , hover_rating_cxx . . $ RatingWidget#hover_rating_.(-1.0) |
| 86 | { |
| 87 | setSizePolicycxx . . $ QWidget#setSizePolicy(457db7fe1842b3dc).(QSizePolicycxx . . $ QSizePolicy#::Minimumcxx . . $ QSizePolicy#Minimum., QSizePolicycxx . . $ QSizePolicy#::Minimumcxx . . $ QSizePolicy#Minimum.); |
| 88 | setMouseTrackingcxx . . $ QWidget#setMouseTracking(b45ddcbc8423892c).(true); |
| 89 | } |
| 90 | |
| 91 | QSizecxx . . $ QSize# RatingWidgetcxx . . $ RatingWidget#::sizeHintcxx . . $ RatingWidget#sizeHint(4b3b776e5ee2b367).() const |
| 92 | { |
| 93 | return QSizecxx . . $ QSize#QSize(c0d38f4800714fae).(RatingPaintercxx . . $ RatingPainter#::kStarSizecxx . . $ RatingPainter#kStarSize. * (RatingPaintercxx . . $ RatingPainter#::kStarCountcxx . . $ RatingPainter#kStarCount. + 2), |
| 94 | RatingPaintercxx . . $ RatingPainter#::kStarSizecxx . . $ RatingPainter#kStarSize.); |
| 95 | } |
| 96 | |
| 97 | void RatingWidgetcxx . . $ RatingWidget#::setRatingcxx . . $ RatingWidget#setRating(9364e6e7bff7660).(float rating) |
| 98 | { |
| 99 | rating_cxx . . $ RatingWidget#rating_. = rating; |
| 100 | updatecxx . . $ QWidget#update(49f6e7a06ebc5aa8).(); |
| 101 | } |
| 102 | |
| 103 | void RatingWidgetcxx . . $ RatingWidget#::paintEventcxx . . $ RatingWidget#paintEvent(f239c9e85d61a220).(QPaintEventcxx . . $ QPaintEvent#* e) |
| 104 | { |
| 105 | Q_UNUSEDcxx . . $ `<external>/15045578679651060896/qglobal.h:117:9`!(e); |
| 106 | QStylePaintercxx . . $ QStylePainter# pcxx . . $ QStylePainter#QStylePainter(108f35f7aa7f3cf9).(this); |
| 107 | |
| 108 | // Draw the stars |
| 109 | painter_cxx . . $ RatingWidget#painter_..Paintcxx . . $ RatingPainter#Paint(bf4fba74770409a7).(&p, rectcxx . . $ QWidget#rect(d857385bac04cbf7).(), hover_rating_cxx . . $ RatingWidget#hover_rating_. == -1.0 ? rating_cxx . . $ RatingWidget#rating_. : hover_rating_cxx . . $ RatingWidget#hover_rating_.); |
| 110 | } |
| 111 | |
| 112 | void RatingWidgetcxx . . $ RatingWidget#::mousePressEventcxx . . $ RatingWidget#mousePressEvent(702858a82d06265c).(QMouseEventcxx . . $ QMouseEvent#* e) |
| 113 | { |
| 114 | rating_cxx . . $ RatingWidget#rating_. = RatingPaintercxx . . $ RatingPainter#::RatingForPoscxx . . $ RatingPainter#RatingForPos(374ff46153e1d7d1).(e->poscxx . . $ QMouseEvent#pos(75d69cfbd3c4b2dd).(), rectcxx . . $ QWidget#rect(d857385bac04cbf7).()); |
| 115 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! RatingChangedcxx . . $ RatingWidget#RatingChanged(9364e6e7bff7660).(rating_cxx . . $ RatingWidget#rating_.); |
| 116 | } |
| 117 | |
| 118 | void RatingWidgetcxx . . $ RatingWidget#::mouseMoveEventcxx . . $ RatingWidget#mouseMoveEvent(702858a82d06265c).(QMouseEventcxx . . $ QMouseEvent#* e) |
| 119 | { |
| 120 | hover_rating_cxx . . $ RatingWidget#hover_rating_. = RatingPaintercxx . . $ RatingPainter#::RatingForPoscxx . . $ RatingPainter#RatingForPos(374ff46153e1d7d1).(e->poscxx . . $ QMouseEvent#pos(75d69cfbd3c4b2dd).(), rectcxx . . $ QWidget#rect(d857385bac04cbf7).()); |
| 121 | updatecxx . . $ QWidget#update(49f6e7a06ebc5aa8).(); |
| 122 | } |
| 123 | |
| 124 | void RatingWidgetcxx . . $ RatingWidget#::leaveEventcxx . . $ RatingWidget#leaveEvent(c2473e2e70986fd7).(QEventcxx . . $ QEvent#*) |
| 125 | { |
| 126 | hover_rating_cxx . . $ RatingWidget#hover_rating_. = -1.0; |
| 127 | updatecxx . . $ QWidget#update(49f6e7a06ebc5aa8).(); |
| 128 | } |