2
* Copyright 2009 Marco Martin <notmart@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU Library General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "resultwidget.h"
22
#include <QGraphicsSceneMouseEvent>
23
#include <QPropertyAnimation>
25
ResultWidget::ResultWidget(QGraphicsItem *parent)
26
: Plasma::IconWidget(parent),
27
m_shouldBeVisible(true)
29
m_animation = new QPropertyAnimation(this, "pos", this);
30
m_animation->setEasingCurve(QEasingCurve::InOutQuad);
31
m_animation->setDuration(250);
32
connect(m_animation, SIGNAL(finished()), this, SLOT(animationFinished()));
35
ResultWidget::~ResultWidget()
39
void ResultWidget::animateHide()
41
m_shouldBeVisible = false;
42
QGraphicsItem *parent = parentItem();
44
animatePos(QPoint(parent->boundingRect().center().x(), parent->boundingRect().bottom()));
48
void ResultWidget::animatePos(const QPointF &point)
51
m_animation->setStartValue(pos());
52
m_animation->setEndValue(point);
56
void ResultWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
58
Plasma::IconWidget::mousePressEvent(event);
61
void ResultWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
63
const int distance = QPointF(boundingRect().center() - event->pos()).manhattanLength();
65
//arbitrary drag distance: this has to be way more than the usual:
66
//double of the average of width and height
67
if (distance > ((size().width() + size().height())/2)*2) {
68
emit dragStartRequested(this);
71
Plasma::IconWidget::mouseMoveEvent(event);
74
void ResultWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
76
Plasma::IconWidget::mouseReleaseEvent(event);
79
void ResultWidget::animationFinished()
81
setVisible(m_shouldBeVisible);
84
QVariant ResultWidget::itemChange(GraphicsItemChange change, const QVariant &value)
86
if (change == QGraphicsItem::ItemVisibleChange) {
87
m_shouldBeVisible = value.toBool();
90
return QGraphicsWidget::itemChange(change, value);
94
#include "resultwidget.moc"