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

KNewStuff

kdxsrating.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 "kdxsrating.h"
00020 
00021 #include "qstarframe.h"
00022 
00023 #include <QtGui/QLayout>
00024 #include <QtGui/QSlider>
00025 #include <QtGui/QLabel>
00026 
00027 #include <klocale.h>
00028 #include <kstandarddirs.h>
00029 
00030 KDXSRating::KDXSRating(QWidget *parent)
00031         : KDialog(parent)
00032 {
00033     setCaption(i18n("Rate this entry"));
00034     setButtons(KDialog::Ok | KDialog::Cancel);
00035 
00036     QVBoxLayout *vbox;
00037     QHBoxLayout *hbox;
00038 
00039     QWidget *root = new QWidget(this);
00040     setMainWidget(root);
00041 
00042     m_slider = new QSlider(root);
00043     m_slider->setOrientation(Qt::Horizontal);
00044     m_slider->setTickPosition(QSlider::TicksBelow);
00045     m_slider->setMinimum(0);
00046     m_slider->setMaximum(100);
00047 
00048     m_starrating = new QStarFrame(root);
00049     m_starrating->setMinimumWidth(100);
00050 
00051     m_rating = new QLabel(QString("0/100"), root);
00052     m_rating->setFixedWidth(100);
00053 
00054     vbox = new QVBoxLayout(root);
00055     hbox = new QHBoxLayout();
00056     hbox->addWidget(m_rating);
00057     hbox->addWidget(m_starrating);
00058     vbox->addLayout(hbox);
00059     vbox->addWidget(m_slider);
00060 
00061     connect(m_slider, SIGNAL(valueChanged(int)),
00062             m_starrating, SLOT(slotRating(int)));
00063     connect(m_slider, SIGNAL(valueChanged(int)), SLOT(slotRating(int)));
00064 }
00065 
00066 int KDXSRating::rating()
00067 {
00068     return m_slider->value();
00069 }
00070 
00071 void KDXSRating::slotRating(int rating)
00072 {
00073     m_rating->setText(QString("%1/100").arg(rating));
00074 }
00075 
00076 /*
00077 void KDXSRating::slotRating(int rating)
00078 {
00079  QString starpath = locate("data", "kpdf/pics/ghns_star.png");
00080  QString graystarpath = locate("data", "kpdf/pics/ghns_star_gray.png");
00081 
00082  QPixmap star(starpath);
00083  QPixmap graystar(graystarpath);
00084 
00085  int wpixels = (int)(m_starrating->width() * (float)rating / 100.0);
00086 
00087  QPainter p;
00088  p.begin(m_starrating);
00089  int w = star.width();
00090  for(int i = 0; i < wpixels; i += star.width())
00091  {
00092   w = wpixels - i;
00093   if(w > star.width()) w = star.width();
00094   p.drawPixmap(i, 0, star, 0, 0, w, -1);
00095  }
00096  p.drawPixmap(wpixels, 0, graystar, w, 0, graystar.width() - w, -1);
00097  wpixels += graystar.width() - w;
00098  for(int i = wpixels; i < m_starrating->width(); i += graystar.width())
00099  {
00100   w = m_starrating->width() - i;
00101   if(w > graystar.width()) w = graystar.width();
00102   p.drawPixmap(i, 0, graystar, 0, 0, w, -1);
00103  }
00104  p.end();
00105 
00106  m_rating->setText(QString("%1/100").arg(rating));
00107 }
00108 
00109 void KDXSRating::paintEvent(QPaintEvent e)
00110 {
00111  Q_UNUSED(e);
00112 
00113  kDebug() << "paint event!";
00114 
00115  int rating = m_slider->value();
00116  slotRating(rating);
00117 }
00118 */
00119 
00120 #include "kdxsrating.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
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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