Initial commit
[raptor.git] / launcher / raptorscrollhandler.cpp
blob30ad8fe9e2fb21d4e029f0ec6a3f39d5b50ee01f
1 #include "raptorscrollhandler.h"
2 #include <QPainter>
3 #include "raptorscrollhandler.moc"
5 class RaptorScrollHandler::Private
7 public:
8 Private(){}
9 ~Private(){}
10 int height;
11 int width;
12 Plasma::Svg * m_theme;
13 QString comment;
14 QString tooltip;
15 MouseState state;
16 ThemeNames ids;
17 QSize size;
18 QSize elementSize;
19 Qt::Orientations orientation;
20 ArrowState arrow;
24 RaptorScrollHandler::RaptorScrollHandler(QGraphicsItem * parent) : QGraphicsItem(parent),d(new Private)
26 //TODO
27 setAcceptsHoverEvents(true);
28 //read from config
29 d->height = 240;
30 d->width = 340;
31 d->m_theme = new Plasma::Svg( "menu/raptorslide",this);
32 d->m_theme->resize(d->height,d->width);
33 //TODO don't do this!
34 setExpandingDirections(Qt::Vertical);
35 d->state = REGULAR;
36 d->size = d->m_theme->size();
37 //d->size = QSize(d->size.width()/10,d->size.height()/10);
38 d->elementSize = d->m_theme->elementSize("arrowUp");
39 d->arrow = UP;
40 d->orientation = Qt::Vertical;
43 void RaptorScrollHandler::setArrowState(RaptorScrollHandler::ArrowState state)
45 if (state == UP) {
46 d->ids[REGULAR] = "arrowUp";
47 d->ids[OVER] = "arrowUp";
48 d->ids[PRESSED] = "arrowUp";
49 } else if ( state == DOWN) {
50 d->ids[REGULAR] = "arrowDown";
51 d->ids[OVER] = "arrowDown";
52 d->ids[PRESSED] = "arrowDown";
53 } else if ( state == LEFT) {
54 d->ids[REGULAR] = "arrowLeft";
55 d->ids[OVER] = "arrowLeft";
56 d->ids[PRESSED] = "arrowLeft";
57 d->elementSize = d->m_theme->elementSize("arrowLeft");
58 } else if ( state == RIGHT) {
59 d->ids[REGULAR] = "arrowRight";
60 d->ids[OVER] = "arrowRight";
61 d->ids[PRESSED] = "arrowRight";
62 d->elementSize = d->m_theme->elementSize("arrowRight");
64 d->arrow = state;
68 RaptorScrollHandler::~RaptorScrollHandler()
70 delete d->m_theme;
71 delete d;
74 void RaptorScrollHandler::setExpandingDirections(Qt::Orientations ori)
77 d->orientation = ori;
78 if (d->orientation == Qt::Vertical) {
79 d->ids[REGULAR] = "arrowUp";
80 d->ids[OVER] = "arrowUp";
81 d->ids[PRESSED] = "arrowUp";
83 } else {
84 d->ids[REGULAR] = "arrowBot";
85 d->ids[OVER] = "arrowBot";
86 d->ids[PRESSED] = "arrowDown";
92 void RaptorScrollHandler::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
94 d->m_theme->resize(d->height,d->width);
95 painter->setRenderHint(QPainter::SmoothPixmapTransform);
96 QRectF source = boundingRect();//(x(), y(), d->width , d->height );
97 d->m_theme->paint(painter, x(),y(), d->ids[d->state]);
98 //painter->drawRect(boundingRect());
101 QString RaptorScrollHandler::loadSvg(MouseState state)
103 return d->ids[state];
106 QSize RaptorScrollHandler::sizeHint() const
108 return QSize(d->width,d->height);
111 QRectF RaptorScrollHandler::boundingRect() const
113 //kDebug() << QRectF (x(),y(),d->elementSize.width(),d->elementSize.height());
114 return QRectF (x(),y(),d->elementSize.width(),d->elementSize.height());
118 QRect RaptorScrollHandler::geometry () const
120 return QRect (x(),y(),d->width,d->height);
124 //Events
126 void RaptorScrollHandler::hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
128 d->state = OVER;
129 emit activated();
130 update();
133 void RaptorScrollHandler::hoverMoveEvent ( QGraphicsSceneHoverEvent * event )
136 d->m_theme->resize(d->width,d->height);
137 d->state = OVER;
138 update();
141 void RaptorScrollHandler::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )
143 d->state = REGULAR;
144 update();
147 void RaptorScrollHandler::mousePressEvent ( QGraphicsSceneMouseEvent * event )
149 d->state = OVER;
150 emit activated();
151 update();