#include <QPen>
#include <QDebug>
+// constants for normal images
const int IMAGE_WIDTH = 64; ///< Created image width
const int IMAGE_HEIGHT = 64; ///< Created image height
const int ORIGINAL_IMAGE_X = 7; ///< Original image x position
const int ROUNDNESS = 9; ///< Image roundness
const int CLIP_X_OFFSET = 1; ///< Clip
-
-const int IMAGE_BORDER = 0;
-const int SMALL_IMAGE_SIZE = 50;
-const int IMAGE_MAX_HEIGHT = 200;
-const int LEFT_BORDER_WIDTH = 20;
-const int RIGHT_BORDER_WIDHT = 20;
-const int BORDER_HEIGHT = 118;
-const int MAX_IMAGE_WIDTH = 200;
-const int OFFSET = 9;
+// constants for large images
+const int BORDER_HEIGHT = 118; ///< Height of large profile image border
+const int BORDER_OFFSET = 9; ///< Transparent area in border graphics edges
+const int FORCED_IMAGE_HEIGHT = 100; ///< Height where user images are scaled
+const int IMAGE_MAX_WIDTH = 220; ///< Mamimum allowed width for profile image
+const int LEFT_BORDER_WIDTH = 20; ///< Width of large profile image left border
+const int RIGHT_BORDER_WIDHT = 20; ///< Width of large profile image right border
+const int SMALL_IMAGE_SIZE = 50; ///< Size of small facebook profile image
QPixmap AvatarImage::create(const QPixmap &image)
{
return avatarImage;
} else {
- qWarning() << "AVATARIMAGE: alkup koko " << image.width() << image.height();
-
- int imageHeight = image.height();
- if (imageHeight > IMAGE_MAX_HEIGHT)
- imageHeight = IMAGE_MAX_HEIGHT;
+ qWarning() << "Avatarimage original size: " << image.width() << image.height();
- int imageWidth = image.width();
- if (imageWidth < LEFT_BORDER_WIDTH + RIGHT_BORDER_WIDHT)
- imageWidth = LEFT_BORDER_WIDTH + RIGHT_BORDER_WIDHT;
- if (imageWidth > MAX_IMAGE_WIDTH)
- imageWidth = MAX_IMAGE_WIDTH;
+ QPixmap scaledProfileImage = image.scaledToHeight(FORCED_IMAGE_HEIGHT,
+ Qt::SmoothTransformation);
- qWarning() << "AVATARIMAGE: uusi koko " << image.width() << image.height();
- QPixmap avatarImage = QPixmap(imageWidth, imageHeight);
- avatarImage.fill(Qt::transparent);
- QPainter painter(&avatarImage);
- painter.drawPixmap(QPointF(OFFSET, OFFSET),image);
+ qWarning() << "Avatarimage scaled size: "
+ << scaledProfileImage.width() << scaledProfileImage.height();
- QRect left(0,0, LEFT_BORDER_WIDTH, imageHeight);
- QRect middle(LEFT_BORDER_WIDTH, 0, image.width() - LEFT_BORDER_WIDTH - RIGHT_BORDER_WIDHT,
- imageHeight);
- QRect right(LEFT_BORDER_WIDTH + middle.width(), 0, RIGHT_BORDER_WIDHT, imageHeight);
+ // unsupported image size ratios are drawn without borders.
+ if (scaledProfileImage.width() + 2*BORDER_OFFSET > IMAGE_MAX_WIDTH)
+ return image;
- QPixmap leftBorder(":/res/images/large_profile_pic_border_left.png");
- QPixmap middleBorder(":/res/images/large_profile_pic_border_middle.png");
- QPixmap rightBorder(":/res/images/large_profile_pic_border_right.png");
+ else if (scaledProfileImage.width() < 2*LEFT_BORDER_WIDTH)
+ return image;
- QPixmap topLeft(":/res/images/large_profile_pic_border_top_left.png");
- QPixmap topRight(":/res/images/large_profile_pic_border_top_right.png");
- QPixmap bottomLeft(":/res/images/large_profile_pic_border_bottom_left.png");
- QPixmap bottomRight(":/res/images/large_profile_pic_border_bottom_right.png");
+ else {
- painter.drawPixmap(QPointF(0,0), topLeft);
- painter.drawPixmap(QPointF(10,10), topRight);
- painter.drawPixmap(QPointF(10,20), bottomLeft);
- painter.drawPixmap(QPointF(10,30), bottomRight);
+ QPixmap avatarImage = QPixmap(scaledProfileImage.width()+BORDER_OFFSET*2,
+ BORDER_HEIGHT);
+ avatarImage.fill(Qt::transparent);
+ QPainter painter(&avatarImage);
+ painter.drawPixmap(QPointF(BORDER_OFFSET, BORDER_OFFSET),scaledProfileImage);
+ QRect leftFrameRectangle(0,0, LEFT_BORDER_WIDTH, BORDER_HEIGHT);
+ QRect middleFrameRectangle(LEFT_BORDER_WIDTH, 0,
+ scaledProfileImage.width() - LEFT_BORDER_WIDTH
+ - RIGHT_BORDER_WIDHT + 2*BORDER_OFFSET, BORDER_HEIGHT);
+ QRect rightFrameRectangle(LEFT_BORDER_WIDTH + middleFrameRectangle.width(), 0,
+ RIGHT_BORDER_WIDHT, BORDER_HEIGHT);
-// painter.drawPixmap(left, leftBorder);
-// painter.drawPixmap(middle, middleBorder);
-// painter.drawPixmap(right, rightBorder);
+ painter.drawPixmap(leftFrameRectangle,
+ QPixmap(":/res/images/large_profile_pic_border_left.png"));
+ painter.drawPixmap(middleFrameRectangle,
+ QPixmap(":/res/images/large_profile_pic_border_middle.png"));
+ painter.drawPixmap(rightFrameRectangle,
+ QPixmap(":/res/images/large_profile_pic_border_right.png"));
-
- return avatarImage;
+ return avatarImage;
+ }
}
}
-
-
-
-//// double scaleFactor = IMAGE_MAX_HEIGHT / image.height();
-//// painter.scale(scaleFactor, scaleFactor);
-// //painter.translate(image.width()/2, image.height()/2);
-
-
-
-
-// QPainterPath roundedRect;
-// roundedRect.addRoundedRect(QRect(0, 0, image.width(),
-// imageHeight), ROUNDNESS, ROUNDNESS, Qt::AbsoluteSize);
-// painter.setClipPath(roundedRect); //pyöristys laittaa reunat valkoisiksi
-// painter.drawPixmap(QPointF(IMAGE_BORDER, IMAGE_BORDER),image);
-
- //painter.drawTiledPixmap();
-
- //PYÖRISTÄ KUVAA
-// QRect imageRect = QRect(0, 0, image.width(), image.height());
-// QPainterPath roundedRect;
-// roundedRect.addRoundedRect(ORIGINAL_IMAGE_X-1, ORIGINAL_IMAGE_Y-1, imageRect.width()+1,
-// imageRect.height()+1,ROUNDNESS,ROUNDNESS);
-// painter.setClipPath(roundedRect);
-
- // PIIRRÄ KEHYS
-// painter.drawPixmap(0, 0, image.width(), image.height(),
-// QPixmap(":/res/images/profile_pic_border.png"));