Merge branch 'central-widget'
[krunner.git] / raptorclaw.cpp
blobba9efb145e0521c9c2af3fb3f1e7e68a8ed4fe91
1 #include "raptorclaw.h"
2 #include <QPainter>
3 #include <KIcon>
4 #include <kicontheme.h>
5 #include "raptorclaw.moc"
7 class RaptorClaw::Private
9 public:
10 Private(){}
11 ~Private(){}
12 int height;
13 int width;
14 Plasma::Svg * m_theme;
15 QString text;
16 QString comment;
17 QString tooltip;
18 QString icon;
19 int Rating;
20 MouseState state;
21 ThemeNames ids;
22 QSize size;
23 QSize elementSize;
24 QPixmap iconPixmap;
25 float opacity;
26 //Grid
27 int ncol;
28 int nrow;
32 RaptorClaw::RaptorClaw(QGraphicsItem *parent)
33 : QGraphicsItem(parent)
35 d = new Private;
36 //TODO
37 setAcceptsHoverEvents(true);
38 //read from config
39 d->height = 330;
40 d->width = 340;
41 d->m_theme = new Plasma::Svg( "menu/raptorslide",this);
42 d->m_theme->resize(d->width, d->height);
43 //FIXME
44 //Do not hardcode Get from config/xml
45 d->text = "RaptorItem";
46 d->ids[REGULAR] = "itemNormal";
47 d->ids[OVER] = "itemOver";
48 d->ids[PRESSED] = "itemOver";
49 d->state = REGULAR;
50 d->size = d->m_theme->size();
51 d->elementSize = d->m_theme->elementSize("itemNormal");
52 d->iconPixmap = QPixmap();
53 d->opacity = 1.0f;
54 //FIXME: need methods for these
55 d->nrow=4;
56 d->ncol=4;
59 RaptorClaw::~RaptorClaw()
61 delete d->m_theme;
62 delete d;
65 void RaptorClaw::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
67 Q_UNUSED(widget);
68 Q_UNUSED(option);
69 painter->setOpacity(d->opacity);
70 painter->setRenderHint(QPainter::SmoothPixmapTransform);
71 d->m_theme->resize(d->width,d->height);
72 QRectF source(x(), y(), d->elementSize.width() , d->elementSize.height());
73 d->m_theme->paint(painter, (int)x(),(int)y(), d->ids[d->state]);
74 if (!d->iconPixmap.isNull()) {
75 painter->drawPixmap(int(x()+((int)source.width()-d->iconPixmap.width())/2),int(y()+
76 ((int)source.height()-d->iconPixmap.height())/2),d->iconPixmap.height(),d->iconPixmap.width(),d->iconPixmap);
77 } else {
78 kDebug()<<"NUll Icon Pixmap"<<endl;
81 //painter->drawText(source,Qt::AlignCenter,d->text);
84 void RaptorClaw::setOpacity(float op)
86 d->opacity = op;
88 QString RaptorClaw::loadSvg(MouseState state)
90 return d->ids[state];
93 QSize RaptorClaw::sizeHint() const
95 return QSize(d->height,d->width);
98 QSize RaptorClaw::minimumSize() const
100 return QSize(d->height,d->width);
103 QRect RaptorClaw::geometry() const
105 return QRect((int)x(),(int)y(),d->height,d->width);
108 QSize RaptorClaw::maximumSize() const
110 return QSize(d->height,d->width);
113 QRectF RaptorClaw::boundingRect() const
115 return QRectF (x(),y(),d->elementSize.width(),d->elementSize.height());
118 //Events
119 void RaptorClaw::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
121 Q_UNUSED(event);
122 d->state = OVER;
123 update();
126 void RaptorClaw::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
128 Q_UNUSED(event);
129 d->state = OVER;
130 update();
133 void RaptorClaw::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
135 Q_UNUSED(event);
136 d->state = REGULAR;
137 update();
140 QString RaptorClaw::name()
142 return d->text;
145 void RaptorClaw::setName(const QString& name)
147 d->text = name;
150 void RaptorClaw::setIcon(QPixmap icon)
152 d->iconPixmap = QPixmap(icon);