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

« back to all changes in this revision

Viewing changes to krunner/interfaces/quicksand/qs_matchitem.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 (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.com>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU General Public License as published by
 
6
 *   the Free Software Foundation; either version 2 of the License, 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 General Public License
 
15
 *   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 <QGraphicsItemAnimation>
 
21
#include <QIcon>
 
22
#include <QPainter>
 
23
 
 
24
#include <KIcon>
 
25
 
 
26
#include "qs_matchitem.h"
 
27
 
 
28
namespace QuickSand
 
29
{
 
30
 
 
31
MatchItem::MatchItem(const QIcon &icon, const QString &name, const QString &desc, QGraphicsWidget *parent)
 
32
    : QGraphicsWidget(parent),
 
33
      m_anim(0),
 
34
      m_name(name),
 
35
      m_desc(desc)
 
36
{
 
37
    if (icon.isNull()) {
 
38
        m_icon = KIcon(QLatin1String( "unknown" ));
 
39
    } else {
 
40
        m_icon = icon;
 
41
    }
 
42
    setFlag(QGraphicsItem::ItemIsFocusable);
 
43
    setFlag(QGraphicsItem::ItemIsSelectable);
 
44
    setAcceptHoverEvents(true);
 
45
    resize(ITEM_SIZE, ITEM_SIZE);
 
46
    setToolTip(QString(QLatin1String( "%1: %2" )).arg(name).arg(desc));
 
47
}
 
48
 
 
49
MatchItem::~MatchItem()
 
50
{
 
51
    delete m_anim;
 
52
}
 
53
 
 
54
QGraphicsItemAnimation* MatchItem::anim(bool create)
 
55
{
 
56
    if (create) {
 
57
        delete m_anim;
 
58
        m_anim = new QGraphicsItemAnimation();
 
59
        m_anim->setItem(this);
 
60
    }
 
61
    return m_anim;
 
62
}
 
63
 
 
64
void MatchItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 
65
{
 
66
    Q_UNUSED(option)
 
67
    Q_UNUSED(widget)
 
68
    painter->setRenderHint(QPainter::Antialiasing);
 
69
 
 
70
    if (hasFocus() || isSelected()) {
 
71
        painter->drawPixmap(0, 0, m_icon.pixmap(64, 64, QIcon::Active));
 
72
    } else {
 
73
        painter->drawPixmap(0, 0, m_icon.pixmap(64, 64, QIcon::Disabled));
 
74
    }
 
75
    //TODO: Make items glow on hover and draw text over them
 
76
}
 
77
 
 
78
void MatchItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
 
79
{
 
80
    Q_UNUSED(e)
 
81
    emit activated(this);
 
82
}
 
83
 
 
84
} // namespace QuickSand