File indexing completed on 2024-05-12 05:09:49
0001 /* 0002 * Copyright (C) 2010 Stefan Burnicki (stefan.burnicki@gmx.de) 0003 * <https://bangarangkde.wordpress.com> BANGARANG MEDIA PLAYER 0004 * Copyright 2011 Jörg Ehrichs <joerg.ehrichs@gmx.de> 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef STARRATING_H 0021 #define STARRATING_H 0022 0023 #include <QMetaType> 0024 #include <QPainter> 0025 0026 /** 0027 * @brief This file provides the StarRating for painting rating stars. 0028 * It supports ratings from 1 to 10 in different sizes. 0029 */ 0030 class StarRating { 0031 0032 public: 0033 enum Size { Small = 8, Medium = 12, Big = 16, Huge = 22 }; 0034 enum MinMax{ InvalidRating = -1, MinRating = 0, MaxRating = 10 }; 0035 0036 static const int Margin = 1; 0037 0038 explicit StarRating(int rating = 0, int size = Small, QPoint point = QPoint(0, 0)); 0039 0040 void setRating(int rating); 0041 void setMaxRating(int maxRating); 0042 void setSize(int size); 0043 void setPoint(QPoint point) { m_point = point; } 0044 0045 bool valid(int rating) const; 0046 int rating() const { return m_rating; } 0047 void paint(QPainter *painter); 0048 0049 QSize sizeHint() const { return sizeHint(m_starSize); } 0050 static QSize sizeHint(int size); 0051 0052 protected: 0053 QPixmap m_starNormal; 0054 QPixmap m_starInactive; 0055 0056 int m_rating; 0057 int m_maxRating; 0058 QPoint m_point; 0059 int m_starSize; 0060 }; 0061 0062 Q_DECLARE_METATYPE(StarRating) 0063 0064 #endif