animate the highlight with the new animation framework. we got a glow
item called FocusIndicaotr, it's private for now and probably it should remain so svn path=/trunk/KDE/kdelibs/; revision=1037733
This commit is contained in:
parent
e9f98cd0d8
commit
89e73cecd2
@ -81,6 +81,7 @@ set(plasma_LIB_SRCS
|
|||||||
private/desktoptoolbox.cpp
|
private/desktoptoolbox.cpp
|
||||||
private/extenderapplet.cpp
|
private/extenderapplet.cpp
|
||||||
private/extenderitemmimedata.cpp
|
private/extenderitemmimedata.cpp
|
||||||
|
private/focusindicator.cpp
|
||||||
private/getsource.cpp
|
private/getsource.cpp
|
||||||
private/nativetabbar.cpp
|
private/nativetabbar.cpp
|
||||||
private/packages.cpp
|
private/packages.cpp
|
||||||
|
114
private/focusindicator.cpp
Normal file
114
private/focusindicator.cpp
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009 Marco Martin <notmart@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 "focusindicator_p.h"
|
||||||
|
|
||||||
|
#include <QGraphicsSceneResizeEvent>
|
||||||
|
|
||||||
|
#include <plasma/theme.h>
|
||||||
|
#include <plasma/framesvg.h>
|
||||||
|
#include <plasma/animations/fade.h>
|
||||||
|
|
||||||
|
namespace Plasma
|
||||||
|
{
|
||||||
|
|
||||||
|
FocusIndicator::FocusIndicator(QGraphicsWidget *parent)
|
||||||
|
: QGraphicsWidget(parent),
|
||||||
|
m_parent(parent)
|
||||||
|
{
|
||||||
|
setFlag(QGraphicsItem::ItemStacksBehindParent);
|
||||||
|
setAcceptsHoverEvents(true);
|
||||||
|
m_background = new Plasma::FrameSvg(this);
|
||||||
|
m_background->setImagePath("widgets/lineedit");
|
||||||
|
m_background->setElementPrefix("hover");
|
||||||
|
m_background->setCacheAllRenderedFrames(true);
|
||||||
|
|
||||||
|
m_fadeIn = new FadeAnimation(1.0);
|
||||||
|
m_fadeIn->setWidget(this);
|
||||||
|
m_fadeOut = new FadeAnimation(0.0);
|
||||||
|
m_fadeOut->setWidget(this);
|
||||||
|
setOpacity(0);
|
||||||
|
|
||||||
|
parent->installEventFilter(this);
|
||||||
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncGeometry()));
|
||||||
|
}
|
||||||
|
|
||||||
|
FocusIndicator::~FocusIndicator()
|
||||||
|
{
|
||||||
|
delete m_fadeIn;
|
||||||
|
delete m_fadeOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FocusIndicator::setCustomGeometry(const QRectF &geometry)
|
||||||
|
{
|
||||||
|
m_customGeometry = geometry;
|
||||||
|
syncGeometry();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FocusIndicator::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
{
|
||||||
|
if (static_cast<QGraphicsWidget *>(watched) != m_parent) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverEnter) {
|
||||||
|
m_background->setElementPrefix("hover");
|
||||||
|
m_fadeIn->start();
|
||||||
|
} else if (!m_parent->hasFocus() && event->type() == QEvent::GraphicsSceneHoverLeave) {
|
||||||
|
m_fadeOut->start();
|
||||||
|
} else if (event->type() == QEvent::GraphicsSceneResize) {
|
||||||
|
syncGeometry();
|
||||||
|
} else if (event->type() == QEvent::FocusIn) {
|
||||||
|
m_background->setElementPrefix("focus");
|
||||||
|
m_fadeIn->start();
|
||||||
|
} else if (!m_parent->isUnderMouse() && event->type() == QEvent::FocusOut) {
|
||||||
|
m_fadeOut->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||||
|
{
|
||||||
|
m_background->resizeFrame(event->newSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FocusIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
|
{
|
||||||
|
m_background->paintFrame(painter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FocusIndicator::syncGeometry()
|
||||||
|
{
|
||||||
|
QRectF geom;
|
||||||
|
if (!m_customGeometry.isNull()) {
|
||||||
|
geom = m_customGeometry;
|
||||||
|
} else {
|
||||||
|
geom = boundingRect();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal left, top, right, bottom;
|
||||||
|
m_background->getMargins(left, top, right, bottom);
|
||||||
|
setGeometry(QRectF(geom.topLeft() + QPointF(-left, -top), geom.size() + QSize(left+right, top+bottom)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <focusindicator_p.moc>
|
||||||
|
|
56
private/focusindicator_p.h
Normal file
56
private/focusindicator_p.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009 Marco Martin <notmart@gmail.com>
|
||||||
|
*
|
||||||
|
* 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_FOCUSINDICATOR_P
|
||||||
|
#define PLASMA_FOCUSINDICATOR_P
|
||||||
|
|
||||||
|
#include <QGraphicsWidget>
|
||||||
|
|
||||||
|
namespace Plasma
|
||||||
|
{
|
||||||
|
class FrameSvg;
|
||||||
|
class FadeAnimation;
|
||||||
|
|
||||||
|
class FocusIndicator : public QGraphicsWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
FocusIndicator(QGraphicsWidget *parent);
|
||||||
|
~FocusIndicator();
|
||||||
|
|
||||||
|
void setCustomGeometry(const QRectF &geometry);
|
||||||
|
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void syncGeometry();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QGraphicsWidget *m_parent;
|
||||||
|
Plasma::FrameSvg *m_background;
|
||||||
|
FadeAnimation *m_fadeIn;
|
||||||
|
FadeAnimation *m_fadeOut;
|
||||||
|
QRectF m_customGeometry;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
@ -21,10 +21,13 @@
|
|||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
#include <QGraphicsSceneResizeEvent>
|
||||||
|
|
||||||
#include <klineedit.h>
|
#include <klineedit.h>
|
||||||
#include <kmimetype.h>
|
#include <kmimetype.h>
|
||||||
|
|
||||||
#include <plasma/private/style_p.h>
|
#include <plasma/private/style_p.h>
|
||||||
|
#include <plasma/private/focusindicator_p.h>
|
||||||
|
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
@ -72,6 +75,7 @@ LineEdit::LineEdit(QGraphicsWidget *parent)
|
|||||||
: QGraphicsProxyWidget(parent),
|
: QGraphicsProxyWidget(parent),
|
||||||
d(new LineEditPrivate(this))
|
d(new LineEditPrivate(this))
|
||||||
{
|
{
|
||||||
|
FocusIndicator *focusIndicator = new FocusIndicator(this);
|
||||||
d->style = Plasma::Style::sharedStyle();
|
d->style = Plasma::Style::sharedStyle();
|
||||||
d->background = new Plasma::FrameSvg(this);
|
d->background = new Plasma::FrameSvg(this);
|
||||||
d->background->setImagePath("widgets/lineedit");
|
d->background->setImagePath("widgets/lineedit");
|
||||||
@ -160,18 +164,6 @@ void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||||||
Q_UNUSED(option)
|
Q_UNUSED(option)
|
||||||
Q_UNUSED(widget)
|
Q_UNUSED(widget)
|
||||||
|
|
||||||
if (hasFocus() || isUnderMouse()) {
|
|
||||||
if (hasFocus()) {
|
|
||||||
d->background->setElementPrefix("focus");
|
|
||||||
} else {
|
|
||||||
d->background->setElementPrefix("hover");
|
|
||||||
}
|
|
||||||
qreal left, top, right, bottom;
|
|
||||||
d->background->getMargins(left, top, right, bottom);
|
|
||||||
d->background->resizeFrame(size()+QSizeF(left+right, top+bottom));
|
|
||||||
d->background->paintFrame(painter, QPoint(-left, -top));
|
|
||||||
}
|
|
||||||
|
|
||||||
nativeWidget()->render(painter, QPoint(0, 0), QRegion(), QWidget::DrawChildren|QWidget::IgnoreMask);
|
nativeWidget()->render(painter, QPoint(0, 0), QRegion(), QWidget::DrawChildren|QWidget::IgnoreMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <plasma/theme.h>
|
#include <plasma/theme.h>
|
||||||
#include <plasma/framesvg.h>
|
#include <plasma/framesvg.h>
|
||||||
#include <plasma/private/style_p.h>
|
#include <plasma/private/style_p.h>
|
||||||
|
#include <plasma/private/focusindicator_p.h>
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
@ -69,6 +70,7 @@ public:
|
|||||||
SpinBox *q;
|
SpinBox *q;
|
||||||
Plasma::Style::Ptr style;
|
Plasma::Style::Ptr style;
|
||||||
Plasma::FrameSvg *background;
|
Plasma::FrameSvg *background;
|
||||||
|
FocusIndicator *focusIndicator;
|
||||||
bool customFont;
|
bool customFont;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -78,6 +80,8 @@ SpinBox::SpinBox(QGraphicsWidget *parent)
|
|||||||
{
|
{
|
||||||
KIntSpinBox *native = new KIntSpinBox;
|
KIntSpinBox *native = new KIntSpinBox;
|
||||||
|
|
||||||
|
d->focusIndicator = new FocusIndicator(this);
|
||||||
|
|
||||||
connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
|
connect(native, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
|
||||||
connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
|
connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
|
||||||
|
|
||||||
@ -173,28 +177,19 @@ void SpinBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpinBox::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||||
|
{
|
||||||
|
QStyleOptionSpinBox spinOpt;
|
||||||
|
spinOpt.initFrom(nativeWidget());
|
||||||
|
QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
|
||||||
|
d->focusIndicator->setCustomGeometry(controlrect);
|
||||||
|
}
|
||||||
|
|
||||||
void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void SpinBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
Q_UNUSED(option)
|
Q_UNUSED(option)
|
||||||
Q_UNUSED(widget)
|
Q_UNUSED(widget)
|
||||||
|
|
||||||
if (hasFocus() || isUnderMouse()) {
|
|
||||||
if (hasFocus()) {
|
|
||||||
d->background->setElementPrefix("focus");
|
|
||||||
} else {
|
|
||||||
d->background->setElementPrefix("hover");
|
|
||||||
}
|
|
||||||
qreal left, top, right, bottom;
|
|
||||||
d->background->getMargins(left, top, right, bottom);
|
|
||||||
|
|
||||||
QStyleOptionSpinBox spinOpt;
|
|
||||||
spinOpt.initFrom(nativeWidget());
|
|
||||||
QRect controlrect = nativeWidget()->style()->subControlRect(QStyle::CC_SpinBox, &spinOpt, QStyle::SC_SpinBoxFrame, nativeWidget());
|
|
||||||
|
|
||||||
d->background->resizeFrame(controlrect.size()+QSizeF(left+right, top+bottom));
|
|
||||||
d->background->paintFrame(painter, QPoint(-left, -top));
|
|
||||||
}
|
|
||||||
|
|
||||||
QGraphicsProxyWidget::paint(painter, option, widget);
|
QGraphicsProxyWidget::paint(painter, option, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ protected:
|
|||||||
void changeEvent(QEvent *event);
|
void changeEvent(QEvent *event);
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user