• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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 Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 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     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
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"

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal