2009-01-07 19:54:43 +01:00
|
|
|
/*
|
|
|
|
* 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>
|
2009-09-23 21:15:51 +02:00
|
|
|
#include <QStyleOptionSpinBox>
|
|
|
|
|
2009-01-07 19:54:43 +01:00
|
|
|
#include <knuminput.h>
|
|
|
|
#include <kmimetype.h>
|
|
|
|
|
2010-05-19 23:45:08 +02:00
|
|
|
#include <plasma/applet.h>
|
2009-01-17 19:00:33 +01:00
|
|
|
#include <plasma/theme.h>
|
2009-09-23 21:15:51 +02:00
|
|
|
#include <plasma/framesvg.h>
|
2009-01-17 19:00:33 +01:00
|
|
|
#include <plasma/private/style_p.h>
|
2009-10-19 23:13:54 +02:00
|
|
|
#include <plasma/private/focusindicator_p.h>
|
2009-01-17 19:00:33 +01:00
|
|
|
|
2009-01-07 19:54:43 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class SpinBoxPrivate
|
|
|
|
{
|
|
|
|
public:
|
2009-01-17 19:00:33 +01:00
|
|
|
SpinBoxPrivate(SpinBox *spinBox)
|
2009-09-13 21:18:29 +02:00
|
|
|
: q(spinBox),
|
2009-10-22 19:39:43 +02:00
|
|
|
focusIndicator(0),
|
2009-09-13 21:18:29 +02:00
|
|
|
customFont(false)
|
2009-01-07 19:54:43 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~SpinBoxPrivate()
|
|
|
|
{
|
|
|
|
}
|
2009-01-17 19:00:33 +01:00
|
|
|
|
|
|
|
void setPalette()
|
|
|
|
{
|
2009-11-26 17:56:46 +01:00
|
|
|
QColor color = Theme::defaultTheme()->color(Theme::ButtonTextColor);
|
2010-10-13 15:16:35 +02:00
|
|
|
QPalette p = q->palette();
|
2009-01-17 19:00:33 +01:00
|
|
|
|
|
|
|
p.setColor(QPalette::Normal, QPalette::Text, color);
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::Text, color);
|
|
|
|
p.setColor(QPalette::Normal, QPalette::ButtonText, color);
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::ButtonText, color);
|
|
|
|
p.setColor(QPalette::Normal, QPalette::Base, QColor(0,0,0,0));
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::Base, QColor(0,0,0,0));
|
2010-10-13 15:16:35 +02:00
|
|
|
q->setPalette(p);
|
2009-09-13 21:18:29 +02:00
|
|
|
|
|
|
|
if (!customFont) {
|
2010-10-13 15:16:35 +02:00
|
|
|
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
|
2010-10-20 12:07:40 +02:00
|
|
|
customFont = false;
|
2009-09-13 21:18:29 +02:00
|
|
|
}
|
2009-01-17 19:00:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SpinBox *q;
|
|
|
|
Plasma::Style::Ptr style;
|
2009-09-23 21:15:51 +02:00
|
|
|
Plasma::FrameSvg *background;
|
2009-10-19 23:13:54 +02:00
|
|
|
FocusIndicator *focusIndicator;
|
2009-09-13 21:18:29 +02:00
|
|
|
bool customFont;
|
2009-01-07 19:54:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
SpinBox::SpinBox(QGraphicsWidget *parent)
|
|
|
|
: QGraphicsProxyWidget(parent),
|
2009-01-17 19:00:33 +01:00
|
|
|
d(new SpinBoxPrivate(this))
|
2009-01-07 19:54:43 +01:00
|
|
|
{
|
|
|
|
KIntSpinBox *native = new KIntSpinBox;
|
|
|
|
|
|
|
|
connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
|
2009-01-10 20:35:29 +01:00
|
|
|
connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
|
2009-01-07 19:54:43 +01:00
|
|
|
|
2009-10-22 19:39:43 +02:00
|
|
|
d->focusIndicator = new FocusIndicator(this, "widgets/lineedit");
|
|
|
|
|
2009-01-07 19:54:43 +01:00
|
|
|
setWidget(native);
|
2010-07-13 23:32:07 +02:00
|
|
|
native->setWindowIcon(QIcon());
|
2009-01-07 19:54:43 +01:00
|
|
|
native->setAttribute(Qt::WA_NoSystemBackground);
|
2009-01-17 19:00:33 +01:00
|
|
|
native->setAutoFillBackground(false);
|
|
|
|
|
2009-09-23 21:15:51 +02:00
|
|
|
d->background = new Plasma::FrameSvg(this);
|
|
|
|
d->background->setImagePath("widgets/lineedit");
|
|
|
|
d->background->setCacheAllRenderedFrames(true);
|
|
|
|
|
2009-10-22 19:39:43 +02:00
|
|
|
|
2009-01-17 19:00:33 +01:00
|
|
|
d->style = Plasma::Style::sharedStyle();
|
|
|
|
native->setStyle(d->style.data());
|
|
|
|
d->setPalette();
|
|
|
|
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(setPalette()));
|
2009-01-07 19:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SpinBox::~SpinBox()
|
|
|
|
{
|
|
|
|
delete d;
|
2009-01-17 19:00:33 +01:00
|
|
|
Plasma::Style::doneWithSharedStyle();
|
2009-01-07 19:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2009-09-13 21:18:29 +02:00
|
|
|
void SpinBox::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::FontChange) {
|
|
|
|
d->customFont = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsProxyWidget::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
2009-09-23 21:15:51 +02:00
|
|
|
void SpinBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpinBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2010-04-07 23:42:19 +02:00
|
|
|
void SpinBox::resizeEvent(QGraphicsSceneResizeEvent *event)
|
2009-10-19 23:13:54 +02:00
|
|
|
{
|
2010-04-07 23:45:09 +02:00
|
|
|
QGraphicsProxyWidget::resizeEvent(event);
|
2009-10-19 23:13:54 +02:00
|
|
|
QStyleOptionSpinBox spinOpt;
|
|
|
|
spinOpt.initFrom(nativeWidget());
|
|
|
|
QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
|
2009-10-22 19:39:43 +02:00
|
|
|
if (d->focusIndicator) {
|
|
|
|
d->focusIndicator->setCustomGeometry(controlrect);
|
|
|
|
}
|
2009-10-19 23:13:54 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 21:15:51 +02:00
|
|
|
void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(option)
|
|
|
|
Q_UNUSED(widget)
|
|
|
|
|
|
|
|
QGraphicsProxyWidget::paint(painter, option, widget);
|
|
|
|
}
|
|
|
|
|
2010-05-19 23:45:08 +02:00
|
|
|
void SpinBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsWidget *widget = parentWidget();
|
|
|
|
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
|
|
|
|
|
|
|
|
while (!applet && widget) {
|
|
|
|
widget = widget->parentWidget();
|
|
|
|
applet = qobject_cast<Plasma::Applet *>(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (applet) {
|
|
|
|
applet->setStatus(Plasma::AcceptingInputStatus);
|
|
|
|
}
|
|
|
|
QGraphicsProxyWidget::mousePressEvent(event);
|
|
|
|
}
|
2009-09-23 21:15:51 +02:00
|
|
|
|
2010-05-19 23:45:08 +02:00
|
|
|
void SpinBox::focusOutEvent(QFocusEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsWidget *widget = parentWidget();
|
|
|
|
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
|
|
|
|
|
|
|
|
while (!applet && widget) {
|
|
|
|
widget = widget->parentWidget();
|
|
|
|
applet = qobject_cast<Plasma::Applet *>(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (applet) {
|
|
|
|
applet->setStatus(Plasma::UnknownStatus);
|
|
|
|
}
|
|
|
|
QGraphicsProxyWidget::focusOutEvent(event);
|
|
|
|
}
|
2009-09-23 21:15:51 +02:00
|
|
|
|
2009-01-07 19:54:43 +01:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include <spinbox.moc>
|
|
|
|
|