A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 107 lines 3.0 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 <QPainter> 23#include <QFile> 24#include <QBitmap> 25 26#include "rbimage.h" 27#include "parsetreenode.h" 28#include <rbscene.h> 29 30RBImage::RBImage(QString file, int tiles, int x, int y, ParseTreeNode* node, 31 QGraphicsItem* parent) 32 : RBMovable(parent), tiles(tiles), currentTile(0), 33 node(node) 34{ 35 /* Prevents RBMovable from interfering with initial position setting */ 36 setFlag(ItemSendsGeometryChanges, false); 37 38 if(QFile::exists(file)) 39 { 40 image = new QPixmap(file); 41 42 if(image->isNull()) 43 { 44 delete image; 45 image = 0; 46 return; 47 } 48 else 49 { 50 image->setMask(image->createMaskFromColor(QColor(255,0,255))); 51 52 } 53 54 size = QRectF(0, 0, image->width(), image->height() / tiles); 55 setPos(x, y); 56 57 } 58 else 59 { 60 RBScene* s = dynamic_cast<RBScene*>(scene()); 61 s->addWarning(QObject::tr("Image not found: ") + file); 62 63 size = QRectF(0, 0, 0, 0); 64 image = 0; 65 } 66} 67 68RBImage::RBImage(const RBImage &other, QGraphicsItem* parent) 69 : RBMovable(parent), tiles(other.tiles), currentTile(other.currentTile), 70 node(other.node) 71{ 72 if(other.image) 73 image = new QPixmap(*(other.image)); 74 else 75 image = 0; 76 size = other.size; 77 setPos(other.x(), other.y()); 78} 79 80RBImage::~RBImage() 81{ 82 if(image) 83 delete image; 84} 85 86void RBImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 87 QWidget *widget) 88{ 89 if(!image) 90 return; 91 92 painter->drawPixmap(size, *image, QRect(0, currentTile * image->height() 93 / tiles, image->width(), 94 image->height() / tiles)); 95 96 RBMovable::paint(painter, option, widget); 97} 98 99 100 101void RBImage::saveGeometry() 102{ 103 QPointF origin = pos(); 104 105 node->modParam(static_cast<int>(origin.x()), 2); 106 node->modParam(static_cast<int>(origin.y()), 3); 107}