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

Plasma

slider.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "slider.h"
00021 
00022 #include <QApplication>
00023 #include <QPainter>
00024 #include <QSlider>
00025 #include <QStyleOptionSlider>
00026 #include <QGraphicsSceneWheelEvent>
00027 #include <kmimetype.h>
00028 
00029 #include "theme.h"
00030 #include "framesvg.h"
00031 
00032 namespace Plasma
00033 {
00034 
00035 class SliderPrivate
00036 {
00037 public:
00038     SliderPrivate()
00039     {
00040     }
00041 
00042     ~SliderPrivate()
00043     {
00044     }
00045 
00046     Plasma::FrameSvg *background;
00047     Plasma::FrameSvg *handle;
00048 };
00049 
00050 Slider::Slider(QGraphicsWidget *parent)
00051     : QGraphicsProxyWidget(parent),
00052       d(new SliderPrivate)
00053 {
00054     QSlider *native = new QSlider;
00055 
00056     connect(native, SIGNAL(sliderMoved(int)), this, SIGNAL(sliderMoved(int)));
00057     connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
00058 
00059     setWidget(native);
00060     native->setAttribute(Qt::WA_NoSystemBackground);
00061 
00062     d->background = new Plasma::FrameSvg(this);
00063     d->background->setImagePath("widgets/frame");
00064     d->background->setElementPrefix("sunken");
00065 
00066     d->handle = new Plasma::FrameSvg(this);
00067     d->handle->setImagePath("widgets/button");
00068     d->handle->setElementPrefix("normal");
00069 }
00070 
00071 Slider::~Slider()
00072 {
00073     delete d;
00074 }
00075 
00076 void Slider::paint(QPainter *painter,
00077                        const QStyleOptionGraphicsItem *option,
00078                        QWidget *widget)
00079 {
00080     if (!styleSheet().isNull()) {
00081         QGraphicsProxyWidget::paint(painter, option, widget);
00082         return;
00083     }
00084 
00085     QSlider *slider = nativeWidget();
00086     QStyle *style = slider->style();
00087     QStyleOptionSlider sliderOpt;
00088     sliderOpt.initFrom(slider);
00089 
00090     //init the other stuff in the slider, taken from initStyleOption()
00091     sliderOpt.subControls = QStyle::SC_None;
00092     sliderOpt.activeSubControls = QStyle::SC_None;
00093     sliderOpt.orientation = slider->orientation();
00094     sliderOpt.maximum = slider->maximum();
00095     sliderOpt.minimum = slider->minimum();
00096     sliderOpt.tickPosition = (QSlider::TickPosition)slider->tickPosition();
00097     sliderOpt.tickInterval = slider->tickInterval();
00098     sliderOpt.upsideDown = (slider->orientation() == Qt::Horizontal) ?
00099                      (slider->invertedAppearance() != (sliderOpt.direction == Qt::RightToLeft))
00100                      : (!slider->invertedAppearance());
00101     sliderOpt.direction = Qt::LeftToRight; // we use the upsideDown option instead
00102     sliderOpt.sliderPosition = slider->sliderPosition();
00103     sliderOpt.sliderValue = slider->value();
00104     sliderOpt.singleStep = slider->singleStep();
00105     sliderOpt.pageStep = slider->pageStep();
00106     if (slider->orientation() == Qt::Horizontal) {
00107         sliderOpt.state |= QStyle::State_Horizontal;
00108     }
00109 
00110     QRect backgroundRect =
00111         style->subControlRect(QStyle::CC_Slider, &sliderOpt, QStyle::SC_SliderGroove, slider);
00112     d->background->resizeFrame(backgroundRect.size());
00113     d->background->paintFrame(painter, backgroundRect.topLeft());
00114 
00115     //Thickmarks
00116     if (sliderOpt.tickPosition != QSlider::NoTicks) {
00117         sliderOpt.subControls = QStyle::SC_SliderTickmarks;
00118         sliderOpt.palette.setColor(
00119             QPalette::WindowText, Plasma::Theme::defaultTheme()->color(Theme::TextColor));
00120         style->drawComplexControl(QStyle::CC_Slider, &sliderOpt, painter, slider);
00121     }
00122 
00123     QRect handleRect =
00124         style->subControlRect(QStyle::CC_Slider, &sliderOpt, QStyle::SC_SliderHandle, slider);
00125     d->handle->resizeFrame(handleRect.size());
00126     d->handle->paintFrame(painter, handleRect.topLeft());
00127 }
00128 
00129 void Slider::wheelEvent(QGraphicsSceneWheelEvent *event)
00130 {
00131     QWheelEvent e(event->pos().toPoint(), event->delta(),event->buttons(),event->modifiers(),event->orientation());
00132     QApplication::sendEvent(widget(), &e);
00133     event->accept();
00134 }
00135 
00136 void Slider::setMaximum(int max)
00137 {
00138     static_cast<QSlider*>(widget())->setMaximum(max);
00139 }
00140 
00141 int Slider::maximum() const
00142 {
00143     return static_cast<QSlider*>(widget())->maximum();
00144 }
00145 
00146 void Slider::setMinimum(int min)
00147 {
00148     static_cast<QSlider*>(widget())->setMinimum(min);
00149 }
00150 
00151 int Slider::minimum() const
00152 {
00153     return static_cast<QSlider*>(widget())->minimum();
00154 }
00155 
00156 void Slider::setRange(int min, int max)
00157 {
00158     static_cast<QSlider*>(widget())->setRange(min, max);
00159 }
00160 
00161 void Slider::setValue(int value)
00162 {
00163     static_cast<QSlider*>(widget())->setValue(value);
00164 }
00165 
00166 int Slider::value() const
00167 {
00168     return static_cast<QSlider*>(widget())->value();
00169 }
00170 
00171 void Slider::setOrientation(Qt::Orientation orientation)
00172 {
00173     static_cast<QSlider*>(widget())->setOrientation(orientation);
00174 }
00175 
00176 Qt::Orientation Slider::orientation() const
00177 {
00178     return static_cast<QSlider*>(widget())->orientation();
00179 }
00180 
00181 void Slider::setStyleSheet(const QString &stylesheet)
00182 {
00183     widget()->setStyleSheet(stylesheet);
00184 }
00185 
00186 QString Slider::styleSheet()
00187 {
00188     return widget()->styleSheet();
00189 }
00190 
00191 QSlider *Slider::nativeWidget() const
00192 {
00193     return static_cast<QSlider*>(widget());
00194 }
00195 
00196 } // namespace Plasma
00197 
00198 #include <slider.moc>
00199 

Plasma

Skip menu "Plasma"
  • 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