summaryrefslogtreecommitdiff
path: root/utils/themeeditor/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/graphics')
-rw-r--r--utils/themeeditor/graphics/rbalbumart.cpp95
-rw-r--r--utils/themeeditor/graphics/rbalbumart.h47
-rw-r--r--utils/themeeditor/graphics/rbscreen.cpp6
-rw-r--r--utils/themeeditor/graphics/rbscreen.h16
4 files changed, 161 insertions, 3 deletions
diff --git a/utils/themeeditor/graphics/rbalbumart.cpp b/utils/themeeditor/graphics/rbalbumart.cpp
new file mode 100644
index 0000000000..bd3a8791fb
--- /dev/null
+++ b/utils/themeeditor/graphics/rbalbumart.cpp
@@ -0,0 +1,95 @@
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#include <QDebug>
26
27RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth,
28 int maxHeight, int artWidth, int artHeight, char hAlign,
29 char vAlign)
30 : QGraphicsItem(parent), size(x, y, maxWidth,
31 maxHeight),
32 artWidth(artWidth), artHeight(artHeight),
33 hAlign(hAlign), vAlign(vAlign),
34 texture(":/render/albumart.png")
35{
36 hide();
37}
38
39QRectF RBAlbumArt::boundingRect() const
40{
41 return size;
42}
43
44void RBAlbumArt::paint(QPainter *painter,
45 const QStyleOptionGraphicsItem *option, QWidget *widget)
46{
47 QRectF drawArea;
48
49 /* Making sure the alignment flags are sane */
50 if(hAlign != 'c' && hAlign != 'l' && hAlign != 'r')
51 hAlign = 'c';
52 if(vAlign != 'c' && vAlign != 't' && vAlign != 'b')
53 vAlign = 'c';
54
55 if(artWidth <= size.width() && artHeight <= size.height())
56 {
57 /* If the art is smaller than the viewport, just center it up */
58 drawArea.setX((size.width() - artWidth) / 2);
59 drawArea.setY((size.height() - artHeight) / 2);
60 drawArea.setWidth(artWidth);
61 drawArea.setHeight(artHeight);
62 }
63 else
64 {
65 /* Otherwise, figure out our scale factor, and which dimension needs
66 * to be scaled, and how to align said dimension
67 */
68 double xScale = size.width() / artWidth;
69 double yScale = size.height() / artHeight;
70 double scale = xScale < yScale ? xScale : yScale;
71
72 double scaleWidth = artWidth * scale;
73 double scaleHeight = artHeight * scale;
74
75 if(hAlign == 'l')
76 drawArea.setX(0);
77 else if(hAlign == 'c')
78 drawArea.setX((size.width() - scaleWidth) / 2 );
79 else
80 drawArea.setX(size.width() - scaleWidth);
81
82 if(vAlign == 't')
83 drawArea.setY(0);
84 else if(vAlign == 'c')
85 drawArea.setY((size.height() - scaleHeight) / 2);
86 else
87 drawArea.setY(size.height() - scaleHeight);
88
89 drawArea.setWidth(scaleWidth);
90 drawArea.setHeight(scaleHeight);
91
92 }
93
94 painter->fillRect(drawArea, texture);
95}
diff --git a/utils/themeeditor/graphics/rbalbumart.h b/utils/themeeditor/graphics/rbalbumart.h
new file mode 100644
index 0000000000..381b715525
--- /dev/null
+++ b/utils/themeeditor/graphics/rbalbumart.h
@@ -0,0 +1,47 @@
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#ifndef RBALBUMART_H
23#define RBALBUMART_H
24
25#include <QGraphicsItem>
26
27class RBAlbumArt : public QGraphicsItem
28{
29public:
30 RBAlbumArt(QGraphicsItem* parent, int x, int y, int maxWidth, int maxHeight,
31 int artWidth, int artHeight, char hAlign = 'c',
32 char vAlign = 'c');
33
34 QRectF boundingRect() const;
35 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
36 QWidget *widget);
37
38private:
39 QRectF size;
40 int artWidth;
41 int artHeight;
42 char hAlign;
43 char vAlign;
44 QPixmap texture;
45};
46
47#endif // RBALBUMART_H
diff --git a/utils/themeeditor/graphics/rbscreen.cpp b/utils/themeeditor/graphics/rbscreen.cpp
index f82c60ce6c..924a37406e 100644
--- a/utils/themeeditor/graphics/rbscreen.cpp
+++ b/utils/themeeditor/graphics/rbscreen.cpp
@@ -28,7 +28,8 @@
28 28
29RBScreen::RBScreen(const RBRenderInfo& info, bool remote, 29RBScreen::RBScreen(const RBRenderInfo& info, bool remote,
30 QGraphicsItem *parent) 30 QGraphicsItem *parent)
31 :QGraphicsItem(parent), backdrop(0), project(project) 31 :QGraphicsItem(parent), backdrop(0), project(project),
32 albumArt(0)
32{ 33{
33 34
34 if(remote) 35 if(remote)
@@ -80,6 +81,9 @@ RBScreen::~RBScreen()
80 if(backdrop) 81 if(backdrop)
81 delete backdrop; 82 delete backdrop;
82 83
84 if(albumArt)
85 delete albumArt;
86
83 QMap<int, RBFont*>::iterator i; 87 QMap<int, RBFont*>::iterator i;
84 for(i = fonts.begin(); i != fonts.end(); i++) 88 for(i = fonts.begin(); i != fonts.end(); i++)
85 delete (*i); 89 delete (*i);
diff --git a/utils/themeeditor/graphics/rbscreen.h b/utils/themeeditor/graphics/rbscreen.h
index 7b8b83060a..358a49e4a7 100644
--- a/utils/themeeditor/graphics/rbscreen.h
+++ b/utils/themeeditor/graphics/rbscreen.h
@@ -28,8 +28,8 @@
28#include "rbrenderinfo.h" 28#include "rbrenderinfo.h"
29#include "rbimage.h" 29#include "rbimage.h"
30#include "rbfont.h" 30#include "rbfont.h"
31 31#include "rbalbumart.h"
32class RBViewport; 32#include "rbviewport.h"
33 33
34class RBScreen : public QGraphicsItem 34class RBScreen : public QGraphicsItem
35{ 35{
@@ -73,6 +73,16 @@ public:
73 QColor foreground(){ return fgColor; } 73 QColor foreground(){ return fgColor; }
74 QColor background(){ return bgColor; } 74 QColor background(){ return bgColor; }
75 75
76 void setAlbumArt(RBAlbumArt* art){ albumArt = art; }
77 void showAlbumArt(RBViewport* view)
78 {
79 if(albumArt)
80 {
81 albumArt->setParentItem(view);
82 albumArt->show();
83 }
84 }
85
76 86
77private: 87private:
78 int width; 88 int width;
@@ -90,6 +100,8 @@ private:
90 QMap<int, RBFont*> fonts; 100 QMap<int, RBFont*> fonts;
91 QList<QString> displayedViewports; 101 QList<QString> displayedViewports;
92 102
103 RBAlbumArt* albumArt;
104
93}; 105};
94 106
95#endif // RBSCREEN_H 107#endif // RBSCREEN_H