blob: eee858e28f4709c5e8574437f7fbb0bcfe0986af [file] [log] [blame]
Robert Bieber14238742010-07-10 06:43:50 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "rbtoucharea.h"
23#include "rbscreen.h"
24#include "devicestate.h"
25
26#include <QPainter>
Robert Bieberbae18362010-07-12 05:33:14 +000027#include <QDebug>
28#include <QGraphicsSceneMouseEvent>
Robert Bieber14238742010-07-10 06:43:50 +000029
30RBTouchArea::RBTouchArea(int width, int height, QString action,
Robert Bieber5c478722011-03-20 04:20:13 +000031 const RBRenderInfo& info, QGraphicsItem* parent)
32 : QGraphicsItem(parent),
Robert Bieberbae18362010-07-12 05:33:14 +000033 size(QRectF(0, 0, width, height)), action(action),
34 device(info.device())
Robert Bieber14238742010-07-10 06:43:50 +000035{
36 debug = info.device()->data("showtouch").toBool();
37 setZValue(5);
Robert Bieberbae18362010-07-12 05:33:14 +000038 setCursor(Qt::PointingHandCursor);
Robert Bieber14238742010-07-10 06:43:50 +000039}
40
41RBTouchArea::~RBTouchArea()
42{
43}
44
45QRectF RBTouchArea::boundingRect() const
46{
47 return size;
48}
49
50void RBTouchArea::paint(QPainter *painter,
51 const QStyleOptionGraphicsItem *option,
52 QWidget *widget)
53{
54 if(debug)
55 {
56 QColor fill = Qt::green;
57 fill.setAlpha(50);
58 painter->setBrush(fill);
59 painter->setPen(Qt::NoPen);
60 painter->drawRect(size);
61 }
62}
Robert Bieberbae18362010-07-12 05:33:14 +000063
64void RBTouchArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
65{
66 if(action[0] == '&')
67 action = action.right(action.count() - 1);
68
69 action = action.toLower();
70
71 if(action == "play")
72 {
73 if(device->data("?mp").toInt() == 2)
74 device->setData("mp", "Play");
75 else
76 device->setData("mp", "Pause");
77 }
78 else if(action == "ffwd")
79 {
80 device->setData("mp", "Fast Forward");
81 }
82 else if(action == "rwd")
83 {
84 device->setData("mp", "Rewind");
85 }
86 else if(action == "repmode")
87 {
88 int index = device->data("?mm").toInt();
89 index = (index + 1) % 5;
90 device->setData("mm", index);
91 }
92 else if(action == "shuffle")
93 {
94 device->setData("ps", !device->data("ps").toBool());
95 }
96 else if(action == "volup")
97 {
98 device->setData("pv", device->data("pv").toInt() + 1);
99 }
100 else if(action == "voldown")
101 {
102 device->setData("pv", device->data("pv").toInt() - 1);
103 }
104 else
105 {
106 event->ignore();
107 return;
108 }
109
110 event->accept();
111}