2010-06-17 20:44:11 +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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-08-06 20:53:50 +00:00
|
|
|
#include "rbscene.h"
|
2010-06-17 20:44:11 +00:00
|
|
|
#include "rbscreen.h"
|
2010-06-21 20:11:58 +00:00
|
|
|
#include "rbviewport.h"
|
2010-06-26 05:18:21 +00:00
|
|
|
#include "devicestate.h"
|
2010-06-17 20:44:11 +00:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QFile>
|
2010-08-06 20:53:50 +00:00
|
|
|
#include <QGraphicsSceneHoverEvent>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2010-06-17 20:44:11 +00:00
|
|
|
|
2010-06-26 05:51:07 +00:00
|
|
|
RBScreen::RBScreen(const RBRenderInfo& info, bool remote,
|
|
|
|
QGraphicsItem *parent)
|
2010-06-30 19:35:00 +00:00
|
|
|
:QGraphicsItem(parent), backdrop(0), project(project),
|
2010-08-12 23:05:53 +00:00
|
|
|
albumArt(0), customUI(0), defaultView(0), ax(false)
|
2010-06-17 20:44:11 +00:00
|
|
|
{
|
|
|
|
|
2010-08-06 20:53:50 +00:00
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
|
2010-06-26 05:51:07 +00:00
|
|
|
if(remote)
|
|
|
|
{
|
2010-07-03 22:57:42 +00:00
|
|
|
fullWidth = info.device()->data("remotewidth").toInt();
|
|
|
|
fullHeight = info.device()->data("remoteheight").toInt();
|
2010-06-26 05:51:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-03 22:57:42 +00:00
|
|
|
fullWidth = info.device()->data("screenwidth").toInt();
|
|
|
|
fullHeight = info.device()->data("screenheight").toInt();
|
2010-06-26 05:51:07 +00:00
|
|
|
}
|
2010-06-17 20:44:11 +00:00
|
|
|
|
2010-06-25 05:14:13 +00:00
|
|
|
QString bg = info.settings()->value("background color", "FFFFFF");
|
2010-06-17 20:44:11 +00:00
|
|
|
bgColor = stringToColor(bg, Qt::white);
|
|
|
|
|
2010-06-25 05:14:13 +00:00
|
|
|
QString fg = info.settings()->value("foreground color", "000000");
|
2010-06-17 20:44:11 +00:00
|
|
|
fgColor = stringToColor(fg, Qt::black);
|
|
|
|
|
2010-06-22 07:55:50 +00:00
|
|
|
settings = info.settings();
|
|
|
|
|
2010-06-17 20:44:11 +00:00
|
|
|
/* Loading backdrop if available */
|
2010-06-22 07:55:50 +00:00
|
|
|
themeBase = info.settings()->value("themebase", "");
|
2010-06-21 20:11:58 +00:00
|
|
|
QString backdropFile = info.settings()->value("backdrop", "");
|
2010-06-22 07:55:50 +00:00
|
|
|
backdropFile.replace("/.rockbox/backdrops/", "");
|
2010-06-21 20:11:58 +00:00
|
|
|
|
2010-06-22 07:55:50 +00:00
|
|
|
if(QFile::exists(themeBase + "/backdrops/" + backdropFile))
|
2010-06-17 20:44:11 +00:00
|
|
|
{
|
2010-06-22 07:55:50 +00:00
|
|
|
backdrop = new QPixmap(themeBase + "/backdrops/" + backdropFile);
|
2010-06-17 20:44:11 +00:00
|
|
|
|
2010-06-21 20:11:58 +00:00
|
|
|
/* If a backdrop has been found, use its width and height */
|
|
|
|
if(!backdrop->isNull())
|
2010-06-17 20:44:11 +00:00
|
|
|
{
|
2010-07-03 22:57:42 +00:00
|
|
|
fullWidth = backdrop->width();
|
|
|
|
fullHeight = backdrop->height();
|
2010-06-21 20:11:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete backdrop;
|
|
|
|
backdrop = 0;
|
2010-06-17 20:44:11 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-25 05:14:13 +00:00
|
|
|
|
2010-07-06 19:32:12 +00:00
|
|
|
fonts.insert(0, new RBFont("Default"));
|
|
|
|
QString defaultFont = settings->value("font", "");
|
|
|
|
if(defaultFont != "")
|
|
|
|
{
|
|
|
|
defaultFont.replace("/.rockbox", settings->value("themebase", ""));
|
|
|
|
fonts.insert(1, new RBFont(defaultFont));
|
|
|
|
}
|
2010-07-03 22:57:42 +00:00
|
|
|
|
|
|
|
if(parent == 0)
|
|
|
|
{
|
|
|
|
width = fullWidth;
|
|
|
|
height = fullHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = parent->boundingRect().width();
|
|
|
|
height = parent->boundingRect().height();
|
|
|
|
}
|
2010-06-17 20:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RBScreen::~RBScreen()
|
|
|
|
{
|
|
|
|
if(backdrop)
|
|
|
|
delete backdrop;
|
2010-06-23 20:18:31 +00:00
|
|
|
|
2010-06-30 19:35:00 +00:00
|
|
|
if(albumArt)
|
|
|
|
delete albumArt;
|
|
|
|
|
2010-06-23 20:18:31 +00:00
|
|
|
QMap<int, RBFont*>::iterator i;
|
|
|
|
for(i = fonts.begin(); i != fonts.end(); i++)
|
2010-06-24 18:55:04 +00:00
|
|
|
delete (*i);
|
|
|
|
|
|
|
|
QMap<QString, QList<RBViewport*>*>::iterator it;
|
|
|
|
for(it = namedViewports.begin(); it != namedViewports.end(); it++)
|
|
|
|
delete (*it);
|
2010-06-17 20:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPainterPath RBScreen::shape() const
|
|
|
|
{
|
|
|
|
QPainterPath retval;
|
|
|
|
retval.addRect(0, 0, width, height);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF RBScreen::boundingRect() const
|
|
|
|
{
|
|
|
|
return QRectF(0, 0, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RBScreen::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *widget)
|
|
|
|
{
|
2010-07-03 22:57:42 +00:00
|
|
|
if(parentItem() != 0)
|
|
|
|
return;
|
|
|
|
|
2010-06-17 20:44:11 +00:00
|
|
|
if(backdrop)
|
|
|
|
{
|
|
|
|
painter->drawPixmap(0, 0, width, height, *backdrop);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter->fillRect(0, 0, width, height, bgColor);
|
|
|
|
}
|
2010-06-30 21:28:11 +00:00
|
|
|
|
2010-06-17 20:44:11 +00:00
|
|
|
}
|
|
|
|
|
2010-06-24 18:55:04 +00:00
|
|
|
void RBScreen::loadViewport(QString name, RBViewport *view)
|
|
|
|
{
|
|
|
|
QList<RBViewport*>* list;
|
|
|
|
if(namedViewports.value(name, 0) == 0)
|
|
|
|
{
|
|
|
|
list = new QList<RBViewport*>;
|
|
|
|
list->append(view);
|
|
|
|
namedViewports.insert(name, list);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list = namedViewports.value(name, 0);
|
|
|
|
list->append(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-21 20:11:58 +00:00
|
|
|
void RBScreen::showViewport(QString name)
|
|
|
|
{
|
|
|
|
if(namedViewports.value(name, 0) == 0)
|
2010-06-29 21:09:29 +00:00
|
|
|
{
|
|
|
|
displayedViewports.append(name);
|
2010-06-21 20:11:58 +00:00
|
|
|
return;
|
2010-06-29 21:09:29 +00:00
|
|
|
}
|
2010-06-21 20:11:58 +00:00
|
|
|
|
2010-06-24 18:55:04 +00:00
|
|
|
QList<RBViewport*>* list = namedViewports.value(name, 0);
|
|
|
|
for(int i = 0; i < list->count(); i++)
|
|
|
|
list->at(i)->show();
|
2010-06-21 20:11:58 +00:00
|
|
|
}
|
|
|
|
|
2010-06-23 20:18:31 +00:00
|
|
|
void RBScreen::loadFont(int id, RBFont* font)
|
|
|
|
{
|
|
|
|
if(id < 2 || id > 9)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fonts.insert(id, font);
|
|
|
|
}
|
|
|
|
|
|
|
|
RBFont* RBScreen::getFont(int id)
|
|
|
|
{
|
|
|
|
if(fonts.value(id, 0) != 0)
|
|
|
|
return fonts.value(id);
|
|
|
|
else
|
|
|
|
return fonts.value(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-22 07:55:50 +00:00
|
|
|
void RBScreen::setBackdrop(QString filename)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(backdrop)
|
|
|
|
delete backdrop;
|
|
|
|
|
|
|
|
filename = settings->value("imagepath", "") + "/" + filename;
|
|
|
|
|
|
|
|
if(QFile::exists(filename))
|
|
|
|
backdrop = new QPixmap(filename);
|
|
|
|
else
|
2010-08-13 19:14:54 +00:00
|
|
|
{
|
|
|
|
RBScene* s = dynamic_cast<RBScene*>(scene());
|
|
|
|
s->addWarning(QObject::tr("Image not found: ") + filename);
|
2010-06-22 07:55:50 +00:00
|
|
|
backdrop = 0;
|
2010-08-13 19:14:54 +00:00
|
|
|
}
|
2010-06-22 07:55:50 +00:00
|
|
|
}
|
2010-06-21 20:11:58 +00:00
|
|
|
|
2010-06-23 19:41:30 +00:00
|
|
|
void RBScreen::makeCustomUI(QString id)
|
|
|
|
{
|
|
|
|
if(namedViewports.value(id, 0) != 0)
|
|
|
|
{
|
2010-06-24 18:55:04 +00:00
|
|
|
QMap<QString, QList<RBViewport*>*>::iterator i;
|
2010-06-23 19:41:30 +00:00
|
|
|
for(i = namedViewports.begin(); i != namedViewports.end(); i++)
|
2010-06-24 18:55:04 +00:00
|
|
|
for(int j = 0; j < (*i)->count(); j++)
|
|
|
|
(*i)->at(j)->clearCustomUI();
|
|
|
|
for(int i = 0; i < namedViewports.value(id)->count(); i++)
|
|
|
|
namedViewports.value(id)->at(i)->makeCustomUI();
|
|
|
|
for(int i = 0; i < namedViewports.value(id)->count(); i++)
|
|
|
|
namedViewports.value(id)->at(i)->show();
|
2010-07-03 22:57:42 +00:00
|
|
|
|
|
|
|
customUI = namedViewports.value(id)->at(0);
|
2010-06-23 19:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-09 19:37:23 +00:00
|
|
|
void RBScreen::endSbsRender()
|
|
|
|
{
|
2020-09-03 16:33:12 +00:00
|
|
|
sbsChildren = childItems();
|
2010-08-09 19:37:23 +00:00
|
|
|
|
|
|
|
QList<int> keys = fonts.keys();
|
|
|
|
for(QList<int>::iterator i = keys.begin(); i != keys.end(); i++)
|
|
|
|
{
|
|
|
|
if(*i > 2)
|
|
|
|
fonts.remove(*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
images.clear();
|
|
|
|
namedViewports.clear();
|
|
|
|
displayedViewports.clear();
|
|
|
|
}
|
|
|
|
|
2010-07-03 22:57:42 +00:00
|
|
|
void RBScreen::breakSBS()
|
|
|
|
{
|
2010-08-09 19:37:23 +00:00
|
|
|
for(QList<QGraphicsItem*>::iterator i = sbsChildren.begin()
|
|
|
|
; i != sbsChildren.end(); i++)
|
|
|
|
(*i)->hide();
|
|
|
|
if(defaultView)
|
|
|
|
defaultView->makeFullScreen();
|
2010-07-03 22:57:42 +00:00
|
|
|
}
|
|
|
|
|
2010-06-17 20:44:11 +00:00
|
|
|
QColor RBScreen::stringToColor(QString str, QColor fallback)
|
|
|
|
{
|
|
|
|
|
|
|
|
QColor retval;
|
|
|
|
|
|
|
|
if(str.length() == 6)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 6; i++)
|
|
|
|
{
|
2020-09-03 16:33:12 +00:00
|
|
|
char c = str[i].toLatin1();
|
2010-06-17 20:44:11 +00:00
|
|
|
if(!((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ||
|
|
|
|
isdigit(c)))
|
|
|
|
{
|
|
|
|
str = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(str != "")
|
|
|
|
retval = QColor("#" + str);
|
|
|
|
else
|
|
|
|
retval = fallback;
|
|
|
|
}
|
|
|
|
else if(str.length() == 1)
|
|
|
|
{
|
2020-09-03 16:33:12 +00:00
|
|
|
if(isdigit(str[0].toLatin1()) && str[0].toLatin1() <= '3')
|
2010-06-17 20:44:11 +00:00
|
|
|
{
|
2020-09-03 16:33:12 +00:00
|
|
|
int shade = 255 * (str[0].toLatin1() - '0') / 3;
|
2010-06-17 20:44:11 +00:00
|
|
|
retval = QColor(shade, shade, shade);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
retval = fallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
retval = fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
}
|
2010-08-06 20:53:50 +00:00
|
|
|
|
|
|
|
void RBScreen::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
RBScene* s = dynamic_cast<RBScene*>(scene());
|
|
|
|
QPoint p = event->scenePos().toPoint();
|
|
|
|
s->moveMouse("(" + QString::number(p.x()) + ", "
|
|
|
|
+ QString::number(p.y()) + ")");
|
|
|
|
|
|
|
|
QGraphicsItem::hoverMoveEvent(event);
|
|
|
|
}
|