Changed magic numbers to constant in AvatarImage.
[situare] / src / ui / avatarimage.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jukka Saastamoinen - jukka.saastamoinen@ixonos.com
6        Jussi Laitinen - jussi.laitinen@ixonos.com
7
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.
11
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.
16
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,
20    USA.
21 */
22
23 #include "avatarimage.h"
24 #include <QPainter>
25 #include <QDebug>
26
27 const int IMAGE_WIDTH = 60;     ///< Created image width
28 const int IMAGE_HEIGHT = 60;    ///< Created image height
29 const int ORIGINAL_IMAGE_X = 5; ///< Original image x position
30 const int ORIGINAL_IMAGE_Y = 5; ///< Original image y position
31 const int ROUNDNESS = 9;        ///< Image roundness
32 const int CLIP_X_OFFSET = 1;    ///< Clip
33
34 QPixmap AvatarImage::create(const QPixmap &image)
35 {
36     QPixmap avatarImage = QPixmap(IMAGE_WIDTH, IMAGE_HEIGHT);
37     avatarImage.fill(Qt::transparent);
38     QPainter painter(&avatarImage);
39
40     QRect imageRect = QRect(0, 0, image.width(), image.height());
41
42     QPainterPath roundedRect;
43     roundedRect.addRoundedRect(ORIGINAL_IMAGE_X-1, ORIGINAL_IMAGE_Y-1, imageRect.width()+1,
44                                imageRect.height()+1,ROUNDNESS,ROUNDNESS);
45     painter.save();
46     painter.setClipPath(roundedRect);
47     painter.drawPixmap(QPointF(ORIGINAL_IMAGE_X, ORIGINAL_IMAGE_Y), image);
48     painter.restore();
49     painter.drawPixmap(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,
50                        QPixmap(":/res/images/profile_pic_border.png"));
51
52     return avatarImage;
53 }