2010-06-18 21:10:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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 <QPainter>
|
|
|
|
#include <QPainterPath>
|
|
|
|
|
|
|
|
#include "rbviewport.h"
|
|
|
|
#include "rbscreen.h"
|
|
|
|
#include "rbrenderinfo.h"
|
|
|
|
#include "parsetreemodel.h"
|
|
|
|
#include "tag_table.h"
|
|
|
|
#include "skin_parser.h"
|
|
|
|
|
|
|
|
RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
2010-07-06 19:19:11 +00:00
|
|
|
: QGraphicsItem(info.screen()), foreground(info.screen()->foreground()),
|
2010-06-25 05:14:13 +00:00
|
|
|
background(info.screen()->background()), textOffset(0,0),
|
2010-06-30 21:28:11 +00:00
|
|
|
screen(info.screen()), textAlign(Left), showStatusBar(false),
|
2010-07-02 05:17:57 +00:00
|
|
|
statusBarTexture(":/render/statusbar.png")
|
2010-06-18 21:10:01 +00:00
|
|
|
{
|
|
|
|
if(!node->tag)
|
|
|
|
{
|
|
|
|
/* Default viewport takes up the entire screen */
|
|
|
|
size = QRectF(0, 0, info.screen()->getWidth(),
|
|
|
|
info.screen()->getHeight());
|
2010-06-23 07:18:22 +00:00
|
|
|
customUI = false;
|
2010-07-06 19:19:11 +00:00
|
|
|
font = screen->getFont(1);
|
2010-06-18 21:10:01 +00:00
|
|
|
|
|
|
|
if(info.model()->rowCount(QModelIndex()) > 1)
|
|
|
|
{
|
|
|
|
/* If there is more than one viewport in the document */
|
2010-06-22 07:55:50 +00:00
|
|
|
setVisible(false);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-22 07:55:50 +00:00
|
|
|
setVisible(true);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-25 05:14:13 +00:00
|
|
|
int param = 0;
|
2010-06-21 20:11:58 +00:00
|
|
|
QString ident;
|
|
|
|
int x,y,w,h;
|
|
|
|
/* Rendering one of the other types of viewport */
|
2010-06-18 21:10:01 +00:00
|
|
|
switch(node->tag->name[1])
|
|
|
|
{
|
|
|
|
case '\0':
|
2010-06-21 20:11:58 +00:00
|
|
|
customUI = false;
|
|
|
|
param = 0;
|
2010-06-18 21:10:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
2010-06-21 20:11:58 +00:00
|
|
|
/* A preloaded viewport definition */
|
|
|
|
ident = node->params[0].data.text;
|
|
|
|
customUI = false;
|
2010-06-29 21:09:29 +00:00
|
|
|
if(!screen->viewPortDisplayed(ident))
|
|
|
|
hide();
|
2010-06-21 20:11:58 +00:00
|
|
|
info.screen()->loadViewport(ident, this);
|
|
|
|
param = 1;
|
2010-06-18 21:10:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i':
|
|
|
|
/* Custom UI Viewport */
|
2010-06-21 20:11:58 +00:00
|
|
|
customUI = true;
|
|
|
|
param = 1;
|
|
|
|
if(node->params[0].type == skin_tag_parameter::DEFAULT)
|
|
|
|
{
|
2010-06-22 07:55:50 +00:00
|
|
|
setVisible(true);
|
2010-06-21 20:11:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-22 07:55:50 +00:00
|
|
|
hide();
|
2010-06-21 20:11:58 +00:00
|
|
|
info.screen()->loadViewport(ident, this);
|
|
|
|
}
|
2010-06-18 21:10:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-06-21 20:11:58 +00:00
|
|
|
/* Now we grab the info common to all viewports */
|
|
|
|
x = node->params[param++].data.numeric;
|
2010-07-01 02:07:41 +00:00
|
|
|
if(x < 0)
|
|
|
|
x = info.screen()->boundingRect().right() + x;
|
2010-06-21 20:11:58 +00:00
|
|
|
y = node->params[param++].data.numeric;
|
2010-07-01 02:07:41 +00:00
|
|
|
if(y < 0)
|
|
|
|
y = info.screen()->boundingRect().bottom() + y;
|
2010-06-21 20:11:58 +00:00
|
|
|
|
|
|
|
if(node->params[param].type == skin_tag_parameter::DEFAULT)
|
|
|
|
w = info.screen()->getWidth() - x;
|
|
|
|
else
|
|
|
|
w = node->params[param].data.numeric;
|
2010-07-01 02:07:41 +00:00
|
|
|
if(w < 0)
|
|
|
|
w = info.screen()->getWidth() + w - x;
|
2010-06-21 20:11:58 +00:00
|
|
|
|
|
|
|
if(node->params[++param].type == skin_tag_parameter::DEFAULT)
|
|
|
|
h = info.screen()->getHeight() - y;
|
|
|
|
else
|
|
|
|
h = node->params[param].data.numeric;
|
2010-07-01 02:07:41 +00:00
|
|
|
if(h < 0)
|
|
|
|
h = info.screen()->getHeight() + h - y;
|
2010-06-21 20:11:58 +00:00
|
|
|
|
2010-07-03 22:57:42 +00:00
|
|
|
/* Adjusting to screen coordinates if necessary */
|
|
|
|
if(screen->parentItem() != 0)
|
|
|
|
{
|
|
|
|
x -= screen->parentItem()->pos().x();
|
|
|
|
y -= screen->parentItem()->pos().y();
|
|
|
|
}
|
|
|
|
|
2010-07-06 19:19:11 +00:00
|
|
|
if(node->params[++param].type == skin_tag_parameter::DEFAULT)
|
|
|
|
font = screen->getFont(1);
|
|
|
|
else
|
|
|
|
font = screen->getFont(node->params[param].data.numeric);
|
2010-07-03 22:57:42 +00:00
|
|
|
|
2010-06-23 07:23:47 +00:00
|
|
|
setPos(x, y);
|
|
|
|
size = QRectF(0, 0, w, h);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
2010-06-30 07:00:05 +00:00
|
|
|
|
2010-07-02 05:58:06 +00:00
|
|
|
debug = info.device()->data("showviewports").toBool();
|
2010-06-30 07:00:05 +00:00
|
|
|
lineHeight = font->lineHeight();
|
2010-07-03 22:57:42 +00:00
|
|
|
if(customUI)
|
|
|
|
screen->setCustomUI(this);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RBViewport::~RBViewport()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainterPath RBViewport::shape() const
|
|
|
|
{
|
|
|
|
QPainterPath retval;
|
|
|
|
retval.addRect(size);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF RBViewport::boundingRect() const
|
|
|
|
{
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RBViewport::paint(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
2010-06-25 05:14:13 +00:00
|
|
|
if(!screen->hasBackdrop() && background != screen->background())
|
|
|
|
{
|
|
|
|
painter->fillRect(size, QBrush(background));
|
|
|
|
}
|
|
|
|
|
2010-06-23 07:18:22 +00:00
|
|
|
painter->setBrush(Qt::NoBrush);
|
|
|
|
painter->setPen(customUI ? Qt::blue : Qt::red);
|
2010-06-26 05:51:07 +00:00
|
|
|
if(debug)
|
|
|
|
painter->drawRect(size);
|
2010-06-30 21:28:11 +00:00
|
|
|
|
|
|
|
if(showStatusBar)
|
|
|
|
painter->fillRect(QRectF(0, 0, size.width(), 8), statusBarTexture);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 20:30:19 +00:00
|
|
|
void RBViewport::newLine()
|
2010-06-22 07:55:50 +00:00
|
|
|
{
|
2010-07-01 20:30:19 +00:00
|
|
|
textOffset.setY(textOffset.y() + lineHeight);
|
|
|
|
textOffset.setX(0);
|
|
|
|
textAlign = Left;
|
|
|
|
leftText.clear();
|
|
|
|
rightText.clear();
|
|
|
|
centerText.clear();
|
2010-06-25 05:14:13 +00:00
|
|
|
}
|
2010-06-22 07:55:50 +00:00
|
|
|
|
2010-06-25 05:14:13 +00:00
|
|
|
void RBViewport::write(QString text)
|
|
|
|
{
|
2010-06-30 07:00:05 +00:00
|
|
|
if(textAlign == Left)
|
|
|
|
{
|
|
|
|
leftText.append(font->renderText(text, foreground, this));
|
|
|
|
alignLeft();
|
|
|
|
}
|
|
|
|
else if(textAlign == Center)
|
|
|
|
{
|
|
|
|
centerText.append(font->renderText(text, foreground, this));
|
|
|
|
alignCenter();
|
|
|
|
}
|
|
|
|
else if(textAlign == Right)
|
|
|
|
{
|
|
|
|
rightText.append(font->renderText(text, foreground, this));
|
|
|
|
alignRight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-01 21:49:55 +00:00
|
|
|
void RBViewport::showPlaylist(const RBRenderInfo &info, int start,
|
|
|
|
skin_element *id3, skin_element *noId3)
|
|
|
|
{
|
|
|
|
/* Determining whether ID3 info is available */
|
2010-07-02 05:17:57 +00:00
|
|
|
skin_element* root = id3;
|
2010-07-01 21:49:55 +00:00
|
|
|
|
|
|
|
/* The line will be a linked list */
|
2010-07-02 05:17:57 +00:00
|
|
|
if(root->children_count > 0)
|
|
|
|
root = root->children[0];
|
2010-07-01 21:49:55 +00:00
|
|
|
|
|
|
|
int song = start + info.device()->data("pp").toInt();
|
|
|
|
int numSongs = info.device()->data("pe").toInt();
|
2010-07-02 05:17:57 +00:00
|
|
|
int halfWay = (numSongs - song) / 2 + 1 + song;
|
2010-07-01 21:49:55 +00:00
|
|
|
|
|
|
|
while(song <= numSongs && textOffset.y() + lineHeight < size.height())
|
|
|
|
{
|
2010-07-02 05:17:57 +00:00
|
|
|
if(song == halfWay)
|
|
|
|
{
|
|
|
|
root = noId3;
|
|
|
|
if(root->children_count > 0)
|
|
|
|
root = root->children[0];
|
|
|
|
}
|
2010-07-01 21:49:55 +00:00
|
|
|
skin_element* current = root;
|
|
|
|
while(current)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(current->type == TEXT)
|
|
|
|
{
|
|
|
|
write(QString((char*)current->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(current->type == TAG)
|
|
|
|
{
|
|
|
|
QString tag(current->tag->name);
|
|
|
|
if(tag == "pp")
|
|
|
|
{
|
|
|
|
write(QString::number(song));
|
|
|
|
}
|
|
|
|
else if(tag == "pt")
|
|
|
|
{
|
|
|
|
write(QObject::tr("00:00"));
|
|
|
|
}
|
|
|
|
else if(tag[0] == 'i' || tag[0] == 'f')
|
|
|
|
{
|
|
|
|
if(song == info.device()->data("pp").toInt())
|
|
|
|
{
|
|
|
|
write(info.device()->data(tag).toString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If we're not on the current track, use the next
|
|
|
|
* track info
|
|
|
|
*/
|
|
|
|
if(tag[0] == 'i')
|
|
|
|
tag = QString("I") + tag.right(1);
|
|
|
|
else
|
|
|
|
tag = QString("F") + tag.right(1);
|
|
|
|
write(info.device()->data(tag).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
}
|
|
|
|
newLine();
|
|
|
|
song++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-30 07:00:05 +00:00
|
|
|
void RBViewport::alignLeft()
|
|
|
|
{
|
|
|
|
int y = textOffset.y();
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
for(int i = 0; i < leftText.count(); i++)
|
|
|
|
{
|
|
|
|
leftText[i]->setPos(x, y);
|
|
|
|
x += leftText[i]->boundingRect().width();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RBViewport::alignCenter()
|
|
|
|
{
|
|
|
|
int y = textOffset.y();
|
|
|
|
int x = 0;
|
|
|
|
int width = 0;
|
|
|
|
|
|
|
|
for(int i = 0; i < centerText.count(); i++)
|
|
|
|
width += centerText[i]->boundingRect().width();
|
|
|
|
|
|
|
|
x = (size.width() - width) / 2;
|
|
|
|
|
|
|
|
for(int i = 0; i < centerText.count(); i++)
|
|
|
|
{
|
|
|
|
centerText[i]->setPos(x, y);
|
|
|
|
x += centerText[i]->boundingRect().width();
|
|
|
|
}
|
2010-06-22 07:55:50 +00:00
|
|
|
}
|
2010-06-30 07:00:05 +00:00
|
|
|
|
|
|
|
void RBViewport::alignRight()
|
|
|
|
{
|
|
|
|
|
|
|
|
int y = textOffset.y();
|
|
|
|
int x = 0;
|
|
|
|
int width = 0;
|
|
|
|
|
|
|
|
for(int i = 0; i < rightText.count(); i++)
|
|
|
|
width += rightText[i]->boundingRect().width();
|
|
|
|
|
|
|
|
x = size.width() - width;
|
|
|
|
|
|
|
|
for(int i = 0; i < rightText.count(); i++)
|
|
|
|
{
|
|
|
|
rightText[i]->setPos(x, y);
|
|
|
|
x += rightText[i]->boundingRect().width();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|