const int CLIP_X_OFFSET = 1; ///< Clip
-const int IMAGE_BORDER = 8;
+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;
QPixmap AvatarImage::create(const QPixmap &image)
{
-// QPixmap avatarImage = QPixmap(IMAGE_WIDTH, IMAGE_HEIGHT);
-// avatarImage.fill(Qt::transparent);
-// QPainter painter(&avatarImage);
-//
-// 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.save();
-// painter.setClipPath(roundedRect);
-// 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;
-
-
-
- //addroundedRect taitaa olla aika turhaa koodia
-
- //QPen pen(Qt::SolidLine, 5, Qt::green, Qt::RoundCap, Qt::RoundJoin); // creates a default pen
-QPen pen;
- //pen.setStyle(Qt::SolidLine);
-pen.setWidth(5);
- pen.setBrush(Qt::green);
-// pen.setCapStyle(Qt::RoundCap);
-// pen.setJoinStyle(Qt::RoundJoin);
-
- QPixmap avatarImage = QPixmap(image.width()+IMAGE_BORDER*2, image.height()+IMAGE_BORDER*2);
- //avatarImage.fill(Qt::transparent);
- //avatarImage.fill(Qt::blue);
+ qWarning() << __PRETTY_FUNCTION__;
+
+ if (image.height() == SMALL_IMAGE_SIZE && image.width() == SMALL_IMAGE_SIZE)
+ {
+ QPixmap avatarImage = QPixmap(IMAGE_WIDTH, IMAGE_HEIGHT);
+ avatarImage.fill(Qt::transparent);
+ QPainter painter(&avatarImage);
+
+ 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.save();
+ painter.setClipPath(roundedRect);
+ 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;
+ } else {
+
+ qWarning() << "AVATARIMAGE: alkup koko " << image.width() << image.height();
+
+ int imageHeight = image.height();
+ if (imageHeight > IMAGE_MAX_HEIGHT)
+ imageHeight = IMAGE_MAX_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;
+
+ qWarning() << "AVATARIMAGE: uusi koko " << image.width() << image.height();
+ QPixmap avatarImage = QPixmap(imageWidth, imageHeight);
+ avatarImage.fill(Qt::transparent);
QPainter painter(&avatarImage);
- painter.setPen(pen);
- //painter.drawPixmap(QPointF(10, 10),image);
- QPixmap ownLocationIcon(":/res/images/led_red.png");
- painter.drawPixmap(QPointF(image.width()-20, image.height()-30), ownLocationIcon);
- //painter.eraseRect(QRect(QPoint(0,0),QPoint(100,100)));
- //painter.setWindow(QRect(0, 0, avatarImage.width()/2, avatarImage.height()/2)); ei vaikuta
- //painter.setViewport(QRect(0, 0, avatarImage.width()/2, avatarImage.height()/2)); ei vaikuta
- painter.drawRect(QRect(0,0,image.width()+IMAGE_BORDER, image.height()+IMAGE_BORDER));
- //painter.drawRoundedRect(QRect(0,0,image.width()+IMAGE_BORDER, image.height()+IMAGE_BORDER),IMAGE_BORDER, IMAGE_BORDER,Qt::AbsoluteSize);
- //painter.drawRoundedRect(QRect(0,0,image.width()+IMAGE_BORDER, image.width()+IMAGE_BORDER),5,5,Qt::AbsoluteSize);
+ painter.drawPixmap(QPointF(OFFSET, OFFSET),image);
+ 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);
+ 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");
+
+ 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");
+
+ painter.drawPixmap(QPointF(0,0), topLeft);
+ painter.drawPixmap(QPointF(10,10), topRight);
+ painter.drawPixmap(QPointF(10,20), bottomLeft);
+ painter.drawPixmap(QPointF(10,30), bottomRight);
+
+
+// painter.drawPixmap(left, leftBorder);
+// painter.drawPixmap(middle, middleBorder);
+// painter.drawPixmap(right, rightBorder);
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"));