Robert Bieber | 1423874 | 2010-07-10 06:43:50 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 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 Bieber | bae1836 | 2010-07-12 05:33:14 +0000 | [diff] [blame] | 27 | #include <QDebug> |
| 28 | #include <QGraphicsSceneMouseEvent> |
Robert Bieber | 1423874 | 2010-07-10 06:43:50 +0000 | [diff] [blame] | 29 | |
| 30 | RBTouchArea::RBTouchArea(int width, int height, QString action, |
Robert Bieber | 5c47872 | 2011-03-20 04:20:13 +0000 | [diff] [blame] | 31 | const RBRenderInfo& info, QGraphicsItem* parent) |
| 32 | : QGraphicsItem(parent), |
Robert Bieber | bae1836 | 2010-07-12 05:33:14 +0000 | [diff] [blame] | 33 | size(QRectF(0, 0, width, height)), action(action), |
| 34 | device(info.device()) |
Robert Bieber | 1423874 | 2010-07-10 06:43:50 +0000 | [diff] [blame] | 35 | { |
| 36 | debug = info.device()->data("showtouch").toBool(); |
| 37 | setZValue(5); |
Robert Bieber | bae1836 | 2010-07-12 05:33:14 +0000 | [diff] [blame] | 38 | setCursor(Qt::PointingHandCursor); |
Robert Bieber | 1423874 | 2010-07-10 06:43:50 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | RBTouchArea::~RBTouchArea() |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | QRectF RBTouchArea::boundingRect() const |
| 46 | { |
| 47 | return size; |
| 48 | } |
| 49 | |
| 50 | void 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 Bieber | bae1836 | 2010-07-12 05:33:14 +0000 | [diff] [blame] | 63 | |
| 64 | void 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 | } |