KNewStuff
qstarframe.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "qstarframe.h"
00022
00023 #include <QtGui/QPainter>
00024 #include <QtGui/QPixmap>
00025
00026 #include <kstandarddirs.h>
00027
00028 QStarFrame::QStarFrame(QWidget *parent)
00029 : QFrame(parent)
00030 {
00031 setFixedHeight(24);
00032 setFrameStyle(QFrame::Sunken | QFrame::Panel);
00033
00034 m_rating = 0;
00035 }
00036
00037 void QStarFrame::slotRating(int rating)
00038 {
00039 m_rating = rating;
00040
00041 drawstars();
00042 }
00043
00044 void QStarFrame::drawstars()
00045 {
00046 QString starpath = KStandardDirs::locate("data", "knewstuff/pics/ghns_star.png");
00047 QString graystarpath = KStandardDirs::locate("data", "knewstuff/pics/ghns_star_gray.png");
00048
00049 QPixmap star(starpath);
00050 QPixmap graystar(graystarpath);
00051
00052 int wpixels = (int)(width() * (float)m_rating / 100.0);
00053
00054 QPainter p;
00055 p.begin(this);
00056 int w = star.width();
00057 for (int i = 0; i < wpixels; i += star.width()) {
00058 w = wpixels - i;
00059 if (w > star.width()) w = star.width();
00060 p.drawPixmap(i, 0, star, 0, 0, w, -1);
00061 }
00062 p.drawPixmap(wpixels, 0, graystar, w, 0, graystar.width() - w, -1);
00063 wpixels += graystar.width() - w;
00064 for (int i = wpixels; i < width(); i += graystar.width()) {
00065 w = width() - i;
00066 if (w > graystar.width()) w = graystar.width();
00067 p.drawPixmap(i, 0, graystar, 0, 0, w, -1);
00068 }
00069 p.end();
00070 }
00071
00072 void QStarFrame::paintEvent(QPaintEvent *e)
00073 {
00074 Q_UNUSED(e);
00075
00076 drawstars();
00077 }
00078
00079 #include "qstarframe.moc"