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

KNewStuff

  • knewstuff
  • knewstuff2
  • ui
kdxsrating.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 "kdxsrating.h"
20
21#include "qstarframe.h"
22
23#include <QtGui/QLayout>
24#include <QtGui/QSlider>
25#include <QtGui/QLabel>
26
27#include <klocale.h>
28#include <kstandarddirs.h>
29
30KDXSRating::KDXSRating(QWidget *parent)
31 : KDialog(parent)
32{
33 setCaption(i18n("Rate this entry"));
34 setButtons(KDialog::Ok | KDialog::Cancel);
35
36 QVBoxLayout *vbox;
37 QHBoxLayout *hbox;
38
39 QWidget *root = new QWidget(this);
40 setMainWidget(root);
41
42 m_slider = new QSlider(root);
43 m_slider->setOrientation(Qt::Horizontal);
44 m_slider->setTickPosition(QSlider::TicksBelow);
45 m_slider->setMinimum(0);
46 m_slider->setMaximum(100);
47
48 m_starrating = new QStarFrame(root);
49 m_starrating->setMinimumWidth(100);
50
51 m_rating = new QLabel(QString("0/100"), root);
52 m_rating->setFixedWidth(100);
53
54 vbox = new QVBoxLayout(root);
55 hbox = new QHBoxLayout();
56 hbox->addWidget(m_rating);
57 hbox->addWidget(m_starrating);
58 vbox->addLayout(hbox);
59 vbox->addWidget(m_slider);
60
61 connect(m_slider, SIGNAL(valueChanged(int)),
62 m_starrating, SLOT(slotRating(int)));
63 connect(m_slider, SIGNAL(valueChanged(int)), SLOT(slotRating(int)));
64}
65
66int KDXSRating::rating()
67{
68 return m_slider->value();
69}
70
71void KDXSRating::slotRating(int rating)
72{
73 m_rating->setText(QString("%1/100").arg(rating));
74}
75
76/*
77void KDXSRating::slotRating(int rating)
78{
79 QString starpath = locate("data", "kpdf/pics/ghns_star.png");
80 QString graystarpath = locate("data", "kpdf/pics/ghns_star_gray.png");
81
82 QPixmap star(starpath);
83 QPixmap graystar(graystarpath);
84
85 int wpixels = (int)(m_starrating->width() * (float)rating / 100.0);
86
87 QPainter p;
88 p.begin(m_starrating);
89 int w = star.width();
90 for(int i = 0; i < wpixels; i += star.width())
91 {
92 w = wpixels - i;
93 if(w > star.width()) w = star.width();
94 p.drawPixmap(i, 0, star, 0, 0, w, -1);
95 }
96 p.drawPixmap(wpixels, 0, graystar, w, 0, graystar.width() - w, -1);
97 wpixels += graystar.width() - w;
98 for(int i = wpixels; i < m_starrating->width(); i += graystar.width())
99 {
100 w = m_starrating->width() - i;
101 if(w > graystar.width()) w = graystar.width();
102 p.drawPixmap(i, 0, graystar, 0, 0, w, -1);
103 }
104 p.end();
105
106 m_rating->setText(QString("%1/100").arg(rating));
107}
108
109void KDXSRating::paintEvent(QPaintEvent e)
110{
111 Q_UNUSED(e);
112
113 kDebug() << "paint event!";
114
115 int rating = m_slider->value();
116 slotRating(rating);
117}
118*/
119
120#include "kdxsrating.moc"
KDXSRating::rating
int rating()
Definition: kdxsrating.cpp:66
KDXSRating::slotRating
void slotRating(int rating)
Definition: kdxsrating.cpp:71
KDXSRating::KDXSRating
KDXSRating(QWidget *parent)
Definition: kdxsrating.cpp:30
KDialog
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
KDialog::Ok
Ok
KDialog::Cancel
Cancel
KDialog::setCaption
virtual void setCaption(const QString &caption)
QLabel
QStarFrame
Rating visualization class.
Definition: qstarframe.h:36
QWidget
kdxsrating.h
klocale.h
i18n
QString i18n(const char *text)
kstandarddirs.h
qstarframe.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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