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

KNewStuff

  • sources
  • kde-4.14
  • kdelibs
  • knewstuff
  • knewstuff2
  • ui
qstarframe.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KNewStuff2.
3  Copyright (c) 2006, 2007 Josef Spillner <spillner@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "qstarframe.h"
20 
21 #include <QtGui/QPainter>
22 #include <QtGui/QPixmap>
23 
24 #include <kstandarddirs.h>
25 
26 QStarFrame::QStarFrame(QWidget *parent)
27  : QFrame(parent)
28 {
29  setFixedHeight(24);
30  setFrameStyle(QFrame::Sunken | QFrame::Panel);
31 
32  m_rating = 0;
33 }
34 
35 void QStarFrame::slotRating(int rating)
36 {
37  m_rating = rating;
38 
39  drawstars();
40 }
41 
42 void QStarFrame::drawstars()
43 {
44  QString starpath = KStandardDirs::locate("data", "knewstuff/pics/ghns_star.png");
45  QString graystarpath = KStandardDirs::locate("data", "knewstuff/pics/ghns_star_gray.png");
46 
47  QPixmap star(starpath);
48  QPixmap graystar(graystarpath);
49 
50  int wpixels = (int)(width() * (float)m_rating / 100.0);
51 
52  QPainter p;
53  p.begin(this);
54  int w = star.width();
55  for (int i = 0; i < wpixels; i += star.width()) {
56  w = wpixels - i;
57  if (w > star.width()) w = star.width();
58  p.drawPixmap(i, 0, star, 0, 0, w, -1);
59  }
60  p.drawPixmap(wpixels, 0, graystar, w, 0, graystar.width() - w, -1);
61  wpixels += graystar.width() - w;
62  for (int i = wpixels; i < width(); i += graystar.width()) {
63  w = width() - i;
64  if (w > graystar.width()) w = graystar.width();
65  p.drawPixmap(i, 0, graystar, 0, 0, w, -1);
66  }
67  p.end();
68 }
69 
70 void QStarFrame::paintEvent(QPaintEvent *e)
71 {
72  Q_UNUSED(e);
73 
74  drawstars();
75 }
76 
77 #include "qstarframe.moc"
QWidget
QPainter::end
bool end()
KStandardDirs::locate
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
QStarFrame::paintEvent
void paintEvent(QPaintEvent *e)
Definition: qstarframe.cpp:70
QFrame::setFrameStyle
void setFrameStyle(int style)
QWidget::width
int width() const
QStarFrame::slotRating
void slotRating(int rating)
Definition: qstarframe.cpp:35
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QPainter
QString
QPixmap
QFrame
QWidget::setFixedHeight
void setFixedHeight(int h)
kstandarddirs.h
QPaintEvent
QPainter::begin
bool begin(QPaintDevice *device)
QStarFrame::QStarFrame
QStarFrame(QWidget *parent)
Definition: qstarframe.cpp:26
qstarframe.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal