Added Plasma::SpinBox.

svn path=/trunk/KDE/kdelibs/; revision=907258
This commit is contained in:
Davide Bettio 2009-01-07 18:54:43 +00:00
parent e009bc7382
commit 08104d35ba
3 changed files with 248 additions and 0 deletions

View File

@ -110,6 +110,7 @@ set(plasma_LIB_SRCS
widgets/scrollbar.cpp widgets/scrollbar.cpp
widgets/signalplotter.cpp widgets/signalplotter.cpp
widgets/slider.cpp widgets/slider.cpp
widgets/spinbox.cpp
widgets/toolbutton.cpp widgets/toolbutton.cpp
widgets/busywidget.cpp widgets/busywidget.cpp
widgets/svgwidget.cpp widgets/svgwidget.cpp
@ -234,6 +235,7 @@ install(FILES
widgets/scrollbar.h widgets/scrollbar.h
widgets/signalplotter.h widgets/signalplotter.h
widgets/slider.h widgets/slider.h
widgets/spinbox.h
widgets/busywidget.h widgets/busywidget.h
widgets/svgwidget.h widgets/svgwidget.h
widgets/tabbar.h widgets/tabbar.h

113
widgets/spinbox.cpp Normal file
View File

@ -0,0 +1,113 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
* Copyright 2009 Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "spinbox.h"
#include <QApplication>
#include <QPainter>
#include <knuminput.h>
#include <kmimetype.h>
namespace Plasma
{
class SpinBoxPrivate
{
public:
SpinBoxPrivate()
{
}
~SpinBoxPrivate()
{
}
};
SpinBox::SpinBox(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new SpinBoxPrivate)
{
KIntSpinBox *native = new KIntSpinBox;
connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
setWidget(native);
native->setAttribute(Qt::WA_NoSystemBackground);
}
SpinBox::~SpinBox()
{
delete d;
}
void SpinBox::setMaximum(int max)
{
static_cast<KIntSpinBox*>(widget())->setMaximum(max);
}
int SpinBox::maximum() const
{
return static_cast<KIntSpinBox*>(widget())->maximum();
}
void SpinBox::setMinimum(int min)
{
static_cast<KIntSpinBox*>(widget())->setMinimum(min);
}
int SpinBox::minimum() const
{
return static_cast<KIntSpinBox*>(widget())->minimum();
}
void SpinBox::setRange(int min, int max)
{
static_cast<KIntSpinBox*>(widget())->setRange(min, max);
}
void SpinBox::setValue(int value)
{
static_cast<KIntSpinBox*>(widget())->setValue(value);
}
int SpinBox::value() const
{
return static_cast<KIntSpinBox*>(widget())->value();
}
void SpinBox::setStyleSheet(const QString &stylesheet)
{
widget()->setStyleSheet(stylesheet);
}
QString SpinBox::styleSheet()
{
return widget()->styleSheet();
}
KIntSpinBox *SpinBox::nativeWidget() const
{
return static_cast<KIntSpinBox*>(widget());
}
} // namespace Plasma
#include <spinbox.moc>

133
widgets/spinbox.h Normal file
View File

@ -0,0 +1,133 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
* Copyright 2009 Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SPINBOX_H
#define PLASMA_SPINBOX_H
#include <QtGui/QGraphicsProxyWidget>
#include <plasma/plasma_export.h>
class KIntSpinBox;
namespace Plasma
{
class SpinBoxPrivate;
/**
* @class SpinBox plasma/widgets/slider.h <Plasma/Widgets/SpinBox>
*
* @short Provides a plasma-themed KIntSpinBox.
*/
class PLASMA_EXPORT SpinBox : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
Q_PROPERTY(int maximum READ maximum WRITE setMinimum)
Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
Q_PROPERTY(int value READ value WRITE setValue)
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
Q_PROPERTY(KIntSpinBox *nativeWidget READ nativeWidget)
public:
explicit SpinBox(QGraphicsWidget *parent = 0);
~SpinBox();
/**
* @return the maximum value
*/
int maximum() const;
/**
* @return the minimum value
*/
int minimum() const;
/**
* @return the current value
*/
int value() const;
/**
* Sets the stylesheet used to control the visual display of this SpinBox
*
* @arg stylesheet a CSS string
*/
void setStyleSheet(const QString &stylesheet);
/**
* @return the stylesheet currently used with this widget
*/
QString styleSheet();
/**
* @return the native widget wrapped by this SpinBox
*/
KIntSpinBox *nativeWidget() const;
public Q_SLOTS:
/**
* Sets the maximum value the slider can take.
*/
void setMaximum(int maximum);
/**
* Sets the minimum value the slider can take.
*/
void setMinimum(int minimum);
/**
* Sets the minimum and maximum values the slider can take.
*/
void setRange(int minimum, int maximum);
/**
* Sets the value of the slider.
*
* If it is outside the range specified by minimum() and maximum(),
* it will be adjusted to fit.
*/
void setValue(int value);
Q_SIGNALS:
/**
* This signal is emitted when the user drags the slider.
*
* In fact, it is emitted whenever the sliderMoved(int) signal
* of KIntSpinBox would be emitted. See the Qt documentation for
* more information.
*/
void sliderMoved(int value);
/**
* This signal is emitted when the slider value has changed,
* with the new slider value as argument.
*/
void valueChanged(int value);
private:
SpinBoxPrivate * const d;
};
} // namespace Plasma
#endif // multiple inclusion guard