~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/netbook/containments/sal/resultwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2009 Marco Martin <notmart@gmail.com>
 
3
 *
 
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.
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include "resultwidget.h"
 
21
 
 
22
#include <QGraphicsSceneMouseEvent>
 
23
#include <QPropertyAnimation>
 
24
 
 
25
ResultWidget::ResultWidget(QGraphicsItem *parent)
 
26
   : Plasma::IconWidget(parent),
 
27
     m_shouldBeVisible(true)
 
28
{
 
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()));
 
33
}
 
34
 
 
35
ResultWidget::~ResultWidget()
 
36
{
 
37
}
 
38
 
 
39
void ResultWidget::animateHide()
 
40
{
 
41
    m_shouldBeVisible = false;
 
42
    QGraphicsItem *parent = parentItem();
 
43
    if (parent) {
 
44
        animatePos(QPoint(parent->boundingRect().center().x(), parent->boundingRect().bottom()));
 
45
    }
 
46
}
 
47
 
 
48
void ResultWidget::animatePos(const QPointF &point)
 
49
{
 
50
    m_animation->stop();
 
51
    m_animation->setStartValue(pos());
 
52
    m_animation->setEndValue(point);
 
53
    m_animation->start();
 
54
}
 
55
 
 
56
void ResultWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
 
57
{
 
58
    Plasma::IconWidget::mousePressEvent(event);
 
59
}
 
60
 
 
61
void ResultWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 
62
{
 
63
    const int distance = QPointF(boundingRect().center() - event->pos()).manhattanLength();
 
64
 
 
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);
 
69
    }
 
70
 
 
71
    Plasma::IconWidget::mouseMoveEvent(event);
 
72
}
 
73
 
 
74
void ResultWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 
75
{
 
76
    Plasma::IconWidget::mouseReleaseEvent(event);
 
77
}
 
78
 
 
79
void ResultWidget::animationFinished()
 
80
{
 
81
    setVisible(m_shouldBeVisible);
 
82
}
 
83
 
 
84
QVariant ResultWidget::itemChange(GraphicsItemChange change, const QVariant &value)
 
85
{
 
86
    if (change == QGraphicsItem::ItemVisibleChange) {
 
87
        m_shouldBeVisible = value.toBool();
 
88
    }
 
89
 
 
90
    return QGraphicsWidget::itemChange(change, value);
 
91
}
 
92
 
 
93
 
 
94
#include "resultwidget.moc"