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