add more spacing
[personal-kdebase.git] / workspace / krunner / interfaces / quicksand / qs_matchitem.cpp
blob70feca622e0a64387df666d3dba16e61a77fb732
1 /*
2 * Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.com>
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.
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 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 .
20 #include <QGraphicsItemAnimation>
21 #include <QIcon>
22 #include <QPainter>
24 #include <KIcon>
26 #include "qs_matchitem.h"
28 namespace QuickSand
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)
37 if (icon.isNull()) {
38 m_icon = KIcon("unknown");
39 } else {
40 m_icon = icon;
42 setFlag(QGraphicsItem::ItemIsFocusable);
43 setFlag(QGraphicsItem::ItemIsSelectable);
44 setAcceptHoverEvents(true);
45 resize(ITEM_SIZE, ITEM_SIZE);
46 m_bgColor = QColor(Qt::white);
47 setToolTip(QString("%1: %2").arg(name).arg(desc));
50 MatchItem::~MatchItem()
52 delete m_anim;
55 QGraphicsItemAnimation* MatchItem::anim(bool create)
57 if (create) {
58 delete m_anim;
59 m_anim = new QGraphicsItemAnimation();
60 m_anim->setItem(this);
62 return m_anim;
65 void MatchItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
67 Q_UNUSED(option)
68 Q_UNUSED(widget)
69 painter->setRenderHint(QPainter::Antialiasing);
71 if (hasFocus() || isSelected()) {
72 painter->drawPixmap(0, 0, m_icon.pixmap(64, 64, QIcon::Active));
73 } else {
74 painter->drawPixmap(0, 0, m_icon.pixmap(64, 64, QIcon::Disabled));
76 //TODO: Make items glow on hover and draw text over them
79 void MatchItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
81 Q_UNUSED(e)
82 emit activated(this);
85 } // namespace QuickSand