finalising big profile images
authorVille Tiensuu <ville.tiensuu@ixonos.com>
Mon, 31 May 2010 10:41:36 +0000 (13:41 +0300)
committerVille Tiensuu <ville.tiensuu@ixonos.com>
Mon, 31 May 2010 10:41:36 +0000 (13:41 +0300)
src/situareservice/situarecommon.h
src/situareservice/situareservice.cpp
src/ui/avatarimage.cpp

index ddfdd46..c5deb06 100644 (file)
@@ -35,7 +35,7 @@ const QString TEST_API_KEY = "cf77865a5070f2c2ba3b52cbf3371579";
 // Situare PHP scripts
 const QString UPDATE_LOCATION = "updateLocation.php";
 const QString REVERSE_GEO = "reversegeo.php";
-const QString GET_LOCATIONS = "getLocations.php?extra_user_data=pic"; //pic_big
+const QString GET_LOCATIONS = "getLocations.php?extra_user_data=pic_big"; //use pic_big or pic
 
 // Cookies
 const QString COOKIE = "Cookie";
index 043fc93..afdc7c9 100644 (file)
@@ -328,7 +328,7 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
 
     QUrl imageUrl = userMap["profile_pic"].toUrl();
     qWarning() << "JOOO1" << imageUrl;
-    QUrl imageUrlBig = userMap["pic"].toUrl();
+    QUrl imageUrlBig = userMap["pic_big"].toUrl();
     qWarning() << "JOOO2" << imageUrlBig;
 
     if(imageUrl.isEmpty()) {
@@ -348,7 +348,7 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
       QPointF coordinates(friendMap["longitude"].toReal(), friendMap["latitude"].toReal());
 
       QUrl imageUrl = friendMap["profile_pic"].toUrl();
-      QUrl imageUrlBig = friendMap["pic"].toUrl();
+      QUrl imageUrlBig = friendMap["pic_big"].toUrl();
 
       if(imageUrl.isEmpty()) {
           // friend doesn't have profile image, so we need to get him a silhouette image
index 9778e0d..c52615a 100644 (file)
@@ -25,6 +25,7 @@
 #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
@@ -32,15 +33,14 @@ const int ORIGINAL_IMAGE_Y = 7; ///< Original image y 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)
 {
@@ -67,77 +67,44 @@ 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"));