![]() |
Mixxx
|
00001 /*************************************************************************** 00002 starrating.h 00003 ------------------- 00004 copyright : (C) 2010 Tobias Rafreider 00005 copyright : (C) 2009 Nokia Corporation 00006 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 00019 #ifndef STARRATING_H 00020 #define STARRATING_H 00021 00022 #include <QMetaType> 00023 #include <QPointF> 00024 #include <QVector> 00025 #include <QPainter> 00026 #include <QStyledItemDelegate> 00027 00028 /* 00029 * The StarRating class represents a rating as a number of stars. 00030 * In addition to holding the data, it is also capable of painting the stars on a QPaintDevice, 00031 * which in this example is either a view or an editor. 00032 * The myStarCount member variable stores the current rating, and myMaxStarCount stores 00033 * the highest possible rating (typically 5). 00034 */ 00035 class StarRating 00036 { 00037 public: 00038 enum EditMode { Editable, ReadOnly }; 00039 00040 00041 StarRating(int starCount = 1, int maxStarCount = 5); 00042 00043 void paint(QPainter *painter, const QRect &rect, const QPalette &palette, EditMode mode) const; 00044 QSize sizeHint() const; 00045 00046 int starCount() const { return m_myStarCount; } 00047 int maxStarCount() const { return m_myMaxStarCount; } 00048 void setStarCount(int starCount) { m_myStarCount = starCount; } 00049 void setMaxStarCount(int maxStarCount) { m_myMaxStarCount = maxStarCount; } 00050 00051 00052 private: 00053 QPolygonF m_starPolygon; 00054 QPolygonF m_diamondPolygon; 00055 int m_myStarCount; 00056 int m_myMaxStarCount; 00057 00058 }; 00059 00060 Q_DECLARE_METATYPE(StarRating) 00061 00062 #endif