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.6 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 "rbalbumart.h" 23 24#include <QPainter> 25 26#include "parsetreenode.h" 27 28RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth, 29 int maxHeight, int artWidth, int artHeight, 30 ParseTreeNode* node, char hAlign, char vAlign) 31 : RBMovable(parent),artWidth(artWidth), 32 artHeight(artHeight), hAlign(hAlign), vAlign(vAlign), 33 texture(":/render/albumart.png"), node(node) 34{ 35 size = QRectF(0, 0, maxWidth, maxHeight); 36 setFlag(ItemSendsGeometryChanges, false); 37 38 setPos(x, y); 39 hide(); 40} 41 42void RBAlbumArt::paint(QPainter *painter, 43 const QStyleOptionGraphicsItem *option, QWidget *widget) 44{ 45 QRectF drawArea; 46 47 /* Making sure the alignment flags are sane */ 48 if(hAlign != 'c' && hAlign != 'l' && hAlign != 'r') 49 hAlign = 'c'; 50 if(vAlign != 'c' && vAlign != 't' && vAlign != 'b') 51 vAlign = 'c'; 52 53 if(artWidth <= size.width() && artHeight <= size.height()) 54 { 55 /* If the art is smaller than the viewport, just center it up */ 56 drawArea.setX((size.width() - artWidth) / 2); 57 drawArea.setY((size.height() - artHeight) / 2); 58 drawArea.setWidth(artWidth); 59 drawArea.setHeight(artHeight); 60 } 61 else 62 { 63 /* Otherwise, figure out our scale factor, and which dimension needs 64 * to be scaled, and how to align said dimension 65 */ 66 double xScale = size.width() / artWidth; 67 double yScale = size.height() / artHeight; 68 double scale = xScale < yScale ? xScale : yScale; 69 70 double scaleWidth = artWidth * scale; 71 double scaleHeight = artHeight * scale; 72 73 if(hAlign == 'l') 74 drawArea.setX(0); 75 else if(hAlign == 'c') 76 drawArea.setX((size.width() - scaleWidth) / 2 ); 77 else 78 drawArea.setX(size.width() - scaleWidth); 79 80 if(vAlign == 't') 81 drawArea.setY(0); 82 else if(vAlign == 'c') 83 drawArea.setY((size.height() - scaleHeight) / 2); 84 else 85 drawArea.setY(size.height() - scaleHeight); 86 87 drawArea.setWidth(scaleWidth); 88 drawArea.setHeight(scaleHeight); 89 90 } 91 92 painter->fillRect(drawArea, texture); 93 94 RBMovable::paint(painter, option, widget); 95} 96 97void RBAlbumArt::saveGeometry() 98{ 99 100 QPointF origin = pos(); 101 QRectF bounds = boundingRect(); 102 103 node->modParam(static_cast<int>(origin.x()), 0); 104 node->modParam(static_cast<int>(origin.y()), 1); 105 node->modParam(static_cast<int>(bounds.width()), 2); 106 node->modParam(static_cast<int>(bounds.height()), 3); 107}