~ubuntu-branches/ubuntu/trusty/kdeplasma-addons/trusty

« back to all changes in this revision

Viewing changes to applets/lancelot/libs/lancelot/widgets/HoverIcon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-05-25 09:50:14 UTC
  • mfrom: (1.1.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100525095014-6mlrm9z9bkws0zkt
Tags: 4:4.4.80-0ubuntu1
* New upstream beta release:
  - Bump kde-sc-dev-latest build-dep version to 4.4.80
  - Refresh kubuntu_04_kimpanel_disable_scim.diff
  - Update various .install files
  - Drop liblancelot0a and liblancelot-dev packages; Upstream has broken ABI
    without an .so version bump, and after discussion with Debian it was
    decided it was not worth it to ship an unstable library.
  - Add liblancelot files to plasma-widget-lancelot, adding appropriate
    Replaces: entries
* Switch to source format 3.0 (quilt):
  - Bump debhelper build-depend version to 7.3.16 or greater

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *   Copyright (C) 2007 Ivan Cukic <ivan.cukic(at)kde.org>
3
 
 *
4
 
 *   This program is free software; you can redistribute it and/or modify
5
 
 *   it under the terms of the GNU Lesser/Library General Public License version 2,
6
 
 *   or (at your option) any later version, as published by the Free
7
 
 *   Software Foundation
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 Lesser/Library General Public License for more details
13
 
 *
14
 
 *   You should have received a copy of the GNU Lesser/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 "HoverIcon.h"
21
 
 
22
 
#include <QBasicTimer>
23
 
 
24
 
#define ACTIVATION_TIME 300
25
 
 
26
 
namespace Lancelot
27
 
{
28
 
 
29
 
class HoverIcon::Private {
30
 
public:
31
 
    Private(HoverIcon * parent)
32
 
      : q(parent),
33
 
        activationMethod(ClickActivate)
34
 
    {
35
 
    }
36
 
 
37
 
    void startTimer()
38
 
    {
39
 
        timer.start(ACTIVATION_TIME, q);
40
 
    }
41
 
 
42
 
    void stopTimer()
43
 
    {
44
 
        timer.stop();
45
 
    }
46
 
 
47
 
 
48
 
    HoverIcon * q;
49
 
    int activationMethod;
50
 
    static QBasicTimer timer;
51
 
};
52
 
 
53
 
QBasicTimer HoverIcon::Private::timer = QBasicTimer();
54
 
 
55
 
HoverIcon::HoverIcon(QGraphicsItem * parent)
56
 
  : Plasma::IconWidget(parent),
57
 
    d(new Private(this))
58
 
{
59
 
 
60
 
}
61
 
 
62
 
HoverIcon::HoverIcon(const QString & text, QGraphicsItem * parent)
63
 
  : Plasma::IconWidget(text, parent),
64
 
    d(new Private(this))
65
 
{
66
 
 
67
 
}
68
 
 
69
 
HoverIcon::HoverIcon(const QIcon & icon, const QString & text, QGraphicsItem * parent)
70
 
  : Plasma::IconWidget(icon, text, parent),
71
 
    d(new Private(this))
72
 
{
73
 
 
74
 
}
75
 
 
76
 
HoverIcon::~HoverIcon()
77
 
{
78
 
    delete d;
79
 
}
80
 
 
81
 
void HoverIcon::timerEvent(QTimerEvent * event)
82
 
{
83
 
    if (event->timerId() == d->timer.timerId()) {
84
 
        d->stopTimer();
85
 
        if (d->activationMethod == HoverActivate) {
86
 
            emit activated();
87
 
        }
88
 
    }
89
 
    Plasma::IconWidget::timerEvent(event);
90
 
}
91
 
 
92
 
void HoverIcon::hoverEnterEvent(QGraphicsSceneHoverEvent * event)
93
 
{
94
 
    if (d->activationMethod == HoverActivate) {
95
 
        d->startTimer();
96
 
    }
97
 
    Plasma::IconWidget::hoverEnterEvent(event);
98
 
}
99
 
 
100
 
void HoverIcon::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)
101
 
{
102
 
    d->stopTimer();
103
 
    Plasma::IconWidget::hoverLeaveEvent(event);
104
 
}
105
 
 
106
 
void HoverIcon::setActivationMethod(int method)
107
 
{
108
 
    if (method == ExtenderActivate) {
109
 
        method = ClickActivate;
110
 
    }
111
 
    if (d->activationMethod == method)
112
 
        return;
113
 
    d->activationMethod = method;
114
 
}
115
 
 
116
 
int HoverIcon::activationMethod() const
117
 
{
118
 
    return d->activationMethod;
119
 
}
120
 
 
121
 
} // namespace Lancelot
122
 
 
123
 
#include "HoverIcon.moc"
124