A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 111 lines 3.1 kB view raw
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> 27#include <QDebug> 28#include <QGraphicsSceneMouseEvent> 29 30RBTouchArea::RBTouchArea(int width, int height, QString action, 31 const RBRenderInfo& info, QGraphicsItem* parent) 32 : QGraphicsItem(parent), 33 size(QRectF(0, 0, width, height)), action(action), 34 device(info.device()) 35{ 36 debug = info.device()->data("showtouch").toBool(); 37 setZValue(5); 38 setCursor(Qt::PointingHandCursor); 39} 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} 63 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}