2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jukka Saastamoinen - jukka.saastamoinen@ixonos.com
6 Jussi Laitinen - jussi.laitinen@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 #include "avatarimage.h"
28 const int IMAGE_WIDTH = 64; ///< Created image width
29 const int IMAGE_HEIGHT = 64; ///< Created image height
30 const int ORIGINAL_IMAGE_X = 7; ///< Original image x position
31 const int ORIGINAL_IMAGE_Y = 7; ///< Original image y position
32 const int ROUNDNESS = 9; ///< Image roundness
33 const int CLIP_X_OFFSET = 1; ///< Clip
36 const int IMAGE_BORDER = 0;
37 const int SMALL_IMAGE_SIZE = 50;
38 const int IMAGE_MAX_HEIGHT = 200;
39 const int LEFT_BORDER_WIDTH = 20;
40 const int RIGHT_BORDER_WIDHT = 20;
41 const int BORDER_HEIGHT = 118;
42 const int MAX_IMAGE_WIDTH = 200;
45 QPixmap AvatarImage::create(const QPixmap &image)
47 qWarning() << __PRETTY_FUNCTION__;
49 if (image.height() == SMALL_IMAGE_SIZE && image.width() == SMALL_IMAGE_SIZE)
51 QPixmap avatarImage = QPixmap(IMAGE_WIDTH, IMAGE_HEIGHT);
52 avatarImage.fill(Qt::transparent);
53 QPainter painter(&avatarImage);
55 QRect imageRect = QRect(0, 0, image.width(), image.height());
57 QPainterPath roundedRect;
58 roundedRect.addRoundedRect(ORIGINAL_IMAGE_X-1, ORIGINAL_IMAGE_Y-1, imageRect.width()+1,
59 imageRect.height()+1,ROUNDNESS,ROUNDNESS);
61 painter.setClipPath(roundedRect);
62 painter.drawPixmap(QPointF(ORIGINAL_IMAGE_X, ORIGINAL_IMAGE_Y), image);
64 painter.drawPixmap(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,
65 QPixmap(":/res/images/profile_pic_border.png"));
70 qWarning() << "AVATARIMAGE: alkup koko " << image.width() << image.height();
72 int imageHeight = image.height();
73 if (imageHeight > IMAGE_MAX_HEIGHT)
74 imageHeight = IMAGE_MAX_HEIGHT;
76 int imageWidth = image.width();
77 if (imageWidth < LEFT_BORDER_WIDTH + RIGHT_BORDER_WIDHT)
78 imageWidth = LEFT_BORDER_WIDTH + RIGHT_BORDER_WIDHT;
79 if (imageWidth > MAX_IMAGE_WIDTH)
80 imageWidth = MAX_IMAGE_WIDTH;
82 qWarning() << "AVATARIMAGE: uusi koko " << image.width() << image.height();
83 QPixmap avatarImage = QPixmap(imageWidth, imageHeight);
84 avatarImage.fill(Qt::transparent);
85 QPainter painter(&avatarImage);
86 painter.drawPixmap(QPointF(OFFSET, OFFSET),image);
88 QRect left(0,0, LEFT_BORDER_WIDTH, imageHeight);
89 QRect middle(LEFT_BORDER_WIDTH, 0, image.width() - LEFT_BORDER_WIDTH - RIGHT_BORDER_WIDHT,
91 QRect right(LEFT_BORDER_WIDTH + middle.width(), 0, RIGHT_BORDER_WIDHT, imageHeight);
93 QPixmap leftBorder(":/res/images/large_profile_pic_border_left.png");
94 QPixmap middleBorder(":/res/images/large_profile_pic_border_middle.png");
95 QPixmap rightBorder(":/res/images/large_profile_pic_border_right.png");
97 QPixmap topLeft(":/res/images/large_profile_pic_border_top_left.png");
98 QPixmap topRight(":/res/images/large_profile_pic_border_top_right.png");
99 QPixmap bottomLeft(":/res/images/large_profile_pic_border_bottom_left.png");
100 QPixmap bottomRight(":/res/images/large_profile_pic_border_bottom_right.png");
102 painter.drawPixmap(QPointF(0,0), topLeft);
103 painter.drawPixmap(QPointF(10,10), topRight);
104 painter.drawPixmap(QPointF(10,20), bottomLeft);
105 painter.drawPixmap(QPointF(10,30), bottomRight);
108 // painter.drawPixmap(left, leftBorder);
109 // painter.drawPixmap(middle, middleBorder);
110 // painter.drawPixmap(right, rightBorder);
119 //// double scaleFactor = IMAGE_MAX_HEIGHT / image.height();
120 //// painter.scale(scaleFactor, scaleFactor);
121 // //painter.translate(image.width()/2, image.height()/2);
126 // QPainterPath roundedRect;
127 // roundedRect.addRoundedRect(QRect(0, 0, image.width(),
128 // imageHeight), ROUNDNESS, ROUNDNESS, Qt::AbsoluteSize);
129 // painter.setClipPath(roundedRect); //pyöristys laittaa reunat valkoisiksi
130 // painter.drawPixmap(QPointF(IMAGE_BORDER, IMAGE_BORDER),image);
132 //painter.drawTiledPixmap();
135 // QRect imageRect = QRect(0, 0, image.width(), image.height());
136 // QPainterPath roundedRect;
137 // roundedRect.addRoundedRect(ORIGINAL_IMAGE_X-1, ORIGINAL_IMAGE_Y-1, imageRect.width()+1,
138 // imageRect.height()+1,ROUNDNESS,ROUNDNESS);
139 // painter.setClipPath(roundedRect);
142 // painter.drawPixmap(0, 0, image.width(), image.height(),
143 // QPixmap(":/res/images/profile_pic_border.png"));