Copyright (C) 2010 Ixonos Plc. Authors:
Jukka Saastamoinen - jukka.saastamoinen@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#include <QPainter>
#include <QDebug>
-const int BORDER_X_OFFSET = 7;
-const int BORDER_Y_OFFSET = 7;
-const int RECT_WIDTH_OFFSET = 1;
-const int RECT_HEIGHT_OFFSET = 1;
-const int ROUNDNESS = 9;
-const int IMAGE_SIZE_X = 60;
-const int IMAGE_SIZE_Y = 60;
+const int IMAGE_WIDTH = 60; ///< Created image width
+const int IMAGE_HEIGHT = 60; ///< Created image height
+const int ORIGINAL_IMAGE_X = 5; ///< Original image x position
+const int ORIGINAL_IMAGE_Y = 5; ///< Original image y position
+const int ROUNDNESS = 9; ///< Image roundness
+const int CLIP_X_OFFSET = 1; ///< Clip
-
-QPixmap AvatarImage::make(const QPixmap &image)
+QPixmap AvatarImage::create(const QPixmap &image)
{
- QPixmap avatarImage; // = QPixmap(IMAGE_SIZE_X, IMAGE_SIZE_Y);
+ QPixmap avatarImage = QPixmap(60, 60);
+ avatarImage.fill(Qt::transparent);
QPainter painter(&avatarImage);
-// QLabel label;
-// label.setPixmap(image);
- QRect widgetRect = QRect(0, 0, image.width(), image.height());
+ QRect imageRect = QRect(0, 0, image.width(), image.height());
- painter.setRenderHint(QPainter::Antialiasing);
QPainterPath roundedRect;
- roundedRect.addRoundedRect(5, 5, widgetRect.width()+RECT_WIDTH_OFFSET,
- widgetRect.height()+RECT_HEIGHT_OFFSET,ROUNDNESS,ROUNDNESS);
+ roundedRect.addRoundedRect(ORIGINAL_IMAGE_X-1, ORIGINAL_IMAGE_Y-1, imageRect.width()+1,
+ imageRect.height()+1,ROUNDNESS,ROUNDNESS);
+ painter.save();
painter.setClipPath(roundedRect);
- //QRegion maskRegion = painter.clipRegion();
-
- //label.setMask(maskRegion);
-
- painter.drawPixmap(QPointF(5, 5), image);
- //label.clearMask();
-
- painter.drawPixmap(QPoint(0, 0), QPixmap(":/res/images/profile_pic_border.png"));
-
+ painter.drawPixmap(QPointF(ORIGINAL_IMAGE_X, ORIGINAL_IMAGE_Y), image);
+ painter.restore();
+ painter.drawPixmap(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,
+ QPixmap(":/res/images/profile_pic_border.png"));
return avatarImage;
}