Theme Editor: Added album art display

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27199 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-06-30 19:35:00 +00:00
parent 3e599f4d37
commit 8114979e8e
10 changed files with 207 additions and 17 deletions

View file

@ -0,0 +1,95 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2010 Robert Bieber
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "rbalbumart.h"
#include <QPainter>
#include <QDebug>
RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth,
int maxHeight, int artWidth, int artHeight, char hAlign,
char vAlign)
: QGraphicsItem(parent), size(x, y, maxWidth,
maxHeight),
artWidth(artWidth), artHeight(artHeight),
hAlign(hAlign), vAlign(vAlign),
texture(":/render/albumart.png")
{
hide();
}
QRectF RBAlbumArt::boundingRect() const
{
return size;
}
void RBAlbumArt::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF drawArea;
/* Making sure the alignment flags are sane */
if(hAlign != 'c' && hAlign != 'l' && hAlign != 'r')
hAlign = 'c';
if(vAlign != 'c' && vAlign != 't' && vAlign != 'b')
vAlign = 'c';
if(artWidth <= size.width() && artHeight <= size.height())
{
/* If the art is smaller than the viewport, just center it up */
drawArea.setX((size.width() - artWidth) / 2);
drawArea.setY((size.height() - artHeight) / 2);
drawArea.setWidth(artWidth);
drawArea.setHeight(artHeight);
}
else
{
/* Otherwise, figure out our scale factor, and which dimension needs
* to be scaled, and how to align said dimension
*/
double xScale = size.width() / artWidth;
double yScale = size.height() / artHeight;
double scale = xScale < yScale ? xScale : yScale;
double scaleWidth = artWidth * scale;
double scaleHeight = artHeight * scale;
if(hAlign == 'l')
drawArea.setX(0);
else if(hAlign == 'c')
drawArea.setX((size.width() - scaleWidth) / 2 );
else
drawArea.setX(size.width() - scaleWidth);
if(vAlign == 't')
drawArea.setY(0);
else if(vAlign == 'c')
drawArea.setY((size.height() - scaleHeight) / 2);
else
drawArea.setY(size.height() - scaleHeight);
drawArea.setWidth(scaleWidth);
drawArea.setHeight(scaleHeight);
}
painter->fillRect(drawArea, texture);
}

View file

@ -0,0 +1,47 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2010 Robert Bieber
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef RBALBUMART_H
#define RBALBUMART_H
#include <QGraphicsItem>
class RBAlbumArt : public QGraphicsItem
{
public:
RBAlbumArt(QGraphicsItem* parent, int x, int y, int maxWidth, int maxHeight,
int artWidth, int artHeight, char hAlign = 'c',
char vAlign = 'c');
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
private:
QRectF size;
int artWidth;
int artHeight;
char hAlign;
char vAlign;
QPixmap texture;
};
#endif // RBALBUMART_H

View file

@ -28,7 +28,8 @@
RBScreen::RBScreen(const RBRenderInfo& info, bool remote,
QGraphicsItem *parent)
:QGraphicsItem(parent), backdrop(0), project(project)
:QGraphicsItem(parent), backdrop(0), project(project),
albumArt(0)
{
if(remote)
@ -80,6 +81,9 @@ RBScreen::~RBScreen()
if(backdrop)
delete backdrop;
if(albumArt)
delete albumArt;
QMap<int, RBFont*>::iterator i;
for(i = fonts.begin(); i != fonts.end(); i++)
delete (*i);

View file

@ -28,8 +28,8 @@
#include "rbrenderinfo.h"
#include "rbimage.h"
#include "rbfont.h"
class RBViewport;
#include "rbalbumart.h"
#include "rbviewport.h"
class RBScreen : public QGraphicsItem
{
@ -73,6 +73,16 @@ public:
QColor foreground(){ return fgColor; }
QColor background(){ return bgColor; }
void setAlbumArt(RBAlbumArt* art){ albumArt = art; }
void showAlbumArt(RBViewport* view)
{
if(albumArt)
{
albumArt->setParentItem(view);
albumArt->show();
}
}
private:
int width;
@ -90,6 +100,8 @@ private:
QMap<int, RBFont*> fonts;
QList<QString> displayedViewports;
RBAlbumArt* albumArt;
};
#endif // RBSCREEN_H

View file

@ -582,8 +582,8 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport)
QString filename;
QString id;
int x, y, tiles, tile;
char c;
int x, y, tiles, tile, maxWidth, maxHeight, width, height;
char c, hAlign, vAlign;
RBImage* image;
/* Two switch statements to narrow down the tag name */
@ -609,7 +609,7 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport)
return true;
}
break;
return false;
case 'x':
switch(element->tag->name[1])
@ -672,7 +672,35 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport)
}
return true;
return false;
case 'C':
switch(element->tag->name[1])
{
case 'd':
/* %Cd */
info.screen()->showAlbumArt(viewport);
return true;
case 'l':
/* %Cl */
x = element->params[0].data.numeric;
y = element->params[1].data.numeric;
maxWidth = element->params[2].data.numeric;
maxHeight = element->params[3].data.numeric;
hAlign = element->params_count > 4
? element->params[4].data.text[0] : 'c';
vAlign = element->params_count > 5
? element->params[5].data.text[0] : 'c';
width = info.device()->data("artwidth").toInt();
height = info.device()->data("artheight").toInt();
info.screen()->setAlbumArt(new RBAlbumArt(viewport, x, y, maxWidth,
maxHeight, width, height,
hAlign, vAlign));
return true;
}
return false;
case 'F':
@ -689,7 +717,7 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport)
}
return true;
return false;
case 'V':
@ -725,7 +753,7 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport)
}
return true;
return false;
case 'X':
@ -738,7 +766,7 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport)
return true;
}
return true;
return false;
}

View file

@ -12,5 +12,6 @@
</qresource>
<qresource prefix="/render">
<file alias="scenebg.png">resources/render/scenebg.png</file>
<file alias="albumart.png">resources/render/albumart.png</file>
</qresource>
</RCC>

View file

@ -1,6 +1,5 @@
The files appicon.xcf and windowicon.png, and all the magnifying glass
graphics are authored by Robert Bieber, and made available in the public domain.
The files document-new.png, document-open.png, and document-save.png came from
the Tango Desktop Project (http://www.tango.freedesktop.org) and are also in
the Tango Desktop Project (http://www.tango.freedesktop.org) and are in
the public domain.
All other graphics are authored by Robert Bieber, and also in the public domain.

View file

@ -35,7 +35,7 @@ screenwidth ; Screen Width ; spin(0,800) ; 300
screenheight ; Screen Height ; spin(0,800) ; 200
remotewidth ; Remote Width ; spin(0,800) ; 100
remoteheight ; Remote Height ; spin(0,800); 50
showviewports ; Show Viewports ; check ; true
showviewports ; Show Viewports ; check ; false
[ID3 Info]
ia ; Artist ; text ; Current Artist
@ -112,6 +112,8 @@ rp ; Song Playcount ; spin(0,10000) ; 20
rr ; Song Rating ; spin(0,10) ; 5
ra ; Autoscore ; spin(0,10) ; 7
?C ; Album Art Available ; check ; true
artwidth ; Album Art Width ; spin(0,500) ; 100
artheight; Album Art Height ; spin(0,500) ; 100
[Hardware Status]
bl ; Battery Level (-1 for unknown) ; spin(-1,100) ; 50

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

View file

@ -43,7 +43,8 @@ HEADERS += models/parsetreemodel.h \
graphics/rbfont.h \
gui/devicestate.h \
findreplace/findreplaceform.h \
findreplace/findreplacedialog.h
findreplace/findreplacedialog.h \
graphics/rbalbumart.h
SOURCES += main.cpp \
models/parsetreemodel.cpp \
models/parsetreenode.cpp \
@ -62,7 +63,8 @@ SOURCES += main.cpp \
graphics/rbfont.cpp \
gui/devicestate.cpp \
findreplace/findreplaceform.cpp \
findreplace/findreplacedialog.cpp
findreplace/findreplacedialog.cpp \
graphics/rbalbumart.cpp
OTHER_FILES += README \
resources/windowicon.png \
resources/appicon.xcf \