diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-06-30 19:35:00 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-06-30 19:35:00 +0000 |
commit | 8114979e8e413caa876cda626fe0b6385bfc56ce (patch) | |
tree | 7b1a193dfbbc48941b93d7c5e2f21199d5bd2979 /utils/themeeditor/graphics/rbalbumart.cpp | |
parent | 3e599f4d379aeaa7ce5861c9818028e6d02d4490 (diff) | |
download | rockbox-8114979e8e413caa876cda626fe0b6385bfc56ce.tar.gz rockbox-8114979e8e413caa876cda626fe0b6385bfc56ce.zip |
Theme Editor: Added album art display
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27199 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/graphics/rbalbumart.cpp')
-rw-r--r-- | utils/themeeditor/graphics/rbalbumart.cpp | 95 |
1 files changed, 95 insertions, 0 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 | |||
27 | RBAlbumArt::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 | |||
39 | QRectF RBAlbumArt::boundingRect() const | ||
40 | { | ||
41 | return size; | ||
42 | } | ||
43 | |||
44 | void 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 | } | ||