1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Robert Bieber
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 #include "rbviewport.h"
25 #include "devicestate.h"
29 #include <QGraphicsSceneHoverEvent>
30 #include <QGraphicsSceneMouseEvent>
32 RBScreen::RBScreen(const RBRenderInfo
& info
, bool remote
,
33 QGraphicsItem
*parent
)
34 :QGraphicsItem(parent
), backdrop(0), project(project
),
35 albumArt(0), customUI(0), defaultView(0), ax(false)
38 setAcceptHoverEvents(true);
42 fullWidth
= info
.device()->data("remotewidth").toInt();
43 fullHeight
= info
.device()->data("remoteheight").toInt();
47 fullWidth
= info
.device()->data("screenwidth").toInt();
48 fullHeight
= info
.device()->data("screenheight").toInt();
51 QString bg
= info
.settings()->value("background color", "FFFFFF");
52 bgColor
= stringToColor(bg
, Qt::white
);
54 QString fg
= info
.settings()->value("foreground color", "000000");
55 fgColor
= stringToColor(fg
, Qt::black
);
57 settings
= info
.settings();
59 /* Loading backdrop if available */
60 themeBase
= info
.settings()->value("themebase", "");
61 QString backdropFile
= info
.settings()->value("backdrop", "");
62 backdropFile
.replace("/.rockbox/backdrops/", "");
64 if(QFile::exists(themeBase
+ "/backdrops/" + backdropFile
))
66 backdrop
= new QPixmap(themeBase
+ "/backdrops/" + backdropFile
);
68 /* If a backdrop has been found, use its width and height */
69 if(!backdrop
->isNull())
71 fullWidth
= backdrop
->width();
72 fullHeight
= backdrop
->height();
81 fonts
.insert(0, new RBFont("Default"));
82 QString defaultFont
= settings
->value("font", "");
85 defaultFont
.replace("/.rockbox", settings
->value("themebase", ""));
86 fonts
.insert(1, new RBFont(defaultFont
));
96 width
= parent
->boundingRect().width();
97 height
= parent
->boundingRect().height();
101 RBScreen::~RBScreen()
109 QMap
<int, RBFont
*>::iterator i
;
110 for(i
= fonts
.begin(); i
!= fonts
.end(); i
++)
113 QMap
<QString
, QList
<RBViewport
*>*>::iterator it
;
114 for(it
= namedViewports
.begin(); it
!= namedViewports
.end(); it
++)
118 QPainterPath
RBScreen::shape() const
121 retval
.addRect(0, 0, width
, height
);
125 QRectF
RBScreen::boundingRect() const
127 return QRectF(0, 0, width
, height
);
130 void RBScreen::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
,
133 if(parentItem() != 0)
138 painter
->drawPixmap(0, 0, width
, height
, *backdrop
);
142 painter
->fillRect(0, 0, width
, height
, bgColor
);
147 void RBScreen::loadViewport(QString name
, RBViewport
*view
)
149 QList
<RBViewport
*>* list
;
150 if(namedViewports
.value(name
, 0) == 0)
152 list
= new QList
<RBViewport
*>;
154 namedViewports
.insert(name
, list
);
158 list
= namedViewports
.value(name
, 0);
163 void RBScreen::showViewport(QString name
)
165 if(namedViewports
.value(name
, 0) == 0)
167 displayedViewports
.append(name
);
171 QList
<RBViewport
*>* list
= namedViewports
.value(name
, 0);
172 for(int i
= 0; i
< list
->count(); i
++)
176 void RBScreen::loadFont(int id
, RBFont
* font
)
181 fonts
.insert(id
, font
);
184 RBFont
* RBScreen::getFont(int id
)
186 if(fonts
.value(id
, 0) != 0)
187 return fonts
.value(id
);
189 return fonts
.value(0, 0);
193 void RBScreen::setBackdrop(QString filename
)
199 filename
= settings
->value("imagepath", "") + "/" + filename
;
201 if(QFile::exists(filename
))
202 backdrop
= new QPixmap(filename
);
205 RBScene
* s
= dynamic_cast<RBScene
*>(scene());
206 s
->addWarning(QObject::tr("Image not found: ") + filename
);
211 void RBScreen::makeCustomUI(QString id
)
213 if(namedViewports
.value(id
, 0) != 0)
215 QMap
<QString
, QList
<RBViewport
*>*>::iterator i
;
216 for(i
= namedViewports
.begin(); i
!= namedViewports
.end(); i
++)
217 for(int j
= 0; j
< (*i
)->count(); j
++)
218 (*i
)->at(j
)->clearCustomUI();
219 for(int i
= 0; i
< namedViewports
.value(id
)->count(); i
++)
220 namedViewports
.value(id
)->at(i
)->makeCustomUI();
221 for(int i
= 0; i
< namedViewports
.value(id
)->count(); i
++)
222 namedViewports
.value(id
)->at(i
)->show();
224 customUI
= namedViewports
.value(id
)->at(0);
228 void RBScreen::endSbsRender()
230 sbsChildren
= children();
232 QList
<int> keys
= fonts
.keys();
233 for(QList
<int>::iterator i
= keys
.begin(); i
!= keys
.end(); i
++)
240 namedViewports
.clear();
241 displayedViewports
.clear();
244 void RBScreen::breakSBS()
246 for(QList
<QGraphicsItem
*>::iterator i
= sbsChildren
.begin()
247 ; i
!= sbsChildren
.end(); i
++)
250 defaultView
->makeFullScreen();
253 QColor
RBScreen::stringToColor(QString str
, QColor fallback
)
258 if(str
.length() == 6)
260 for(int i
= 0; i
< 6; i
++)
262 char c
= str
[i
].toAscii();
263 if(!((c
>= 'a' && c
<= 'f') || (c
>= 'A' && c
<= 'F') ||
271 retval
= QColor("#" + str
);
275 else if(str
.length() == 1)
277 if(isdigit(str
[0].toAscii()) && str
[0].toAscii() <= '3')
279 int shade
= 255 * (str
[0].toAscii() - '0') / 3;
280 retval
= QColor(shade
, shade
, shade
);
296 void RBScreen::hoverMoveEvent(QGraphicsSceneHoverEvent
*event
)
298 RBScene
* s
= dynamic_cast<RBScene
*>(scene());
299 QPoint p
= event
->scenePos().toPoint();
300 s
->moveMouse("(" + QString::number(p
.x()) + ", "
301 + QString::number(p
.y()) + ")");
303 QGraphicsItem::hoverMoveEvent(event
);