KNewStuff
qstarframe.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of KNewStuff2. 00003 Copyright (c) 2006, 2007 Josef Spillner <spillner@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include "qstarframe.h" 00020 00021 #include <QtGui/QPainter> 00022 #include <QtGui/QPixmap> 00023 00024 #include <kstandarddirs.h> 00025 00026 QStarFrame::QStarFrame(QWidget *parent) 00027 : QFrame(parent) 00028 { 00029 setFixedHeight(24); 00030 setFrameStyle(QFrame::Sunken | QFrame::Panel); 00031 00032 m_rating = 0; 00033 } 00034 00035 void QStarFrame::slotRating(int rating) 00036 { 00037 m_rating = rating; 00038 00039 drawstars(); 00040 } 00041 00042 void QStarFrame::drawstars() 00043 { 00044 QString starpath = KStandardDirs::locate("data", "knewstuff/pics/ghns_star.png"); 00045 QString graystarpath = KStandardDirs::locate("data", "knewstuff/pics/ghns_star_gray.png"); 00046 00047 QPixmap star(starpath); 00048 QPixmap graystar(graystarpath); 00049 00050 int wpixels = (int)(width() * (float)m_rating / 100.0); 00051 00052 QPainter p; 00053 p.begin(this); 00054 int w = star.width(); 00055 for (int i = 0; i < wpixels; i += star.width()) { 00056 w = wpixels - i; 00057 if (w > star.width()) w = star.width(); 00058 p.drawPixmap(i, 0, star, 0, 0, w, -1); 00059 } 00060 p.drawPixmap(wpixels, 0, graystar, w, 0, graystar.width() - w, -1); 00061 wpixels += graystar.width() - w; 00062 for (int i = wpixels; i < width(); i += graystar.width()) { 00063 w = width() - i; 00064 if (w > graystar.width()) w = graystar.width(); 00065 p.drawPixmap(i, 0, graystar, 0, 0, w, -1); 00066 } 00067 p.end(); 00068 } 00069 00070 void QStarFrame::paintEvent(QPaintEvent *e) 00071 { 00072 Q_UNUSED(e); 00073 00074 drawstars(); 00075 } 00076 00077 #include "qstarframe.moc"
KDE 4.6 API Reference