src/hbcore/image/hbbadgeicon.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
--- a/src/hbcore/image/hbbadgeicon.cpp	Thu Jul 15 14:03:49 2010 +0100
+++ b/src/hbcore/image/hbbadgeicon.cpp	Thu Jul 22 16:36:53 2010 +0100
@@ -23,9 +23,9 @@
 **
 ****************************************************************************/
 
+#include "hbbadgeicon_p.h"
 #include "hbicon.h"
 #include "hbbadgeiconinfo_p.h"
-#include "hbbadgeicon_p.h"
 #include <QPainter>
 
 /*!
@@ -73,18 +73,19 @@
  */
 void HbBadgeIcon::addBadge(Qt::Alignment alignment,
                            const HbIcon &icon,
-                           int zValue)
+                           int zValue,
+                           const QSizeF &sizeFactor,
+                           Qt::AspectRatioMode aspectRatio)
 {
-    HbBadgeIconInfo info(icon, alignment, zValue);
-    int size = mBadgeIcons.size();
-    if (size == 0) {
+    HbBadgeIconInfo info(icon, alignment, zValue, sizeFactor, aspectRatio);
+    int badgeCount = mBadgeIcons.count();
+    if (badgeCount == 0) {
         mBadgeIcons.append(info);
-    }
-    else {
+    } else {
         bool added = false;
         //Find a spot to insert the badgeinfo in the list.
-        for (int i = size - 1; i >= 0; i--){
-            if (mBadgeIcons[i].zValue() > zValue){
+        for (int i = badgeCount - 1; i >= 0; i--) {
+            if (mBadgeIcons[i].zValue() > zValue) {
                 mBadgeIcons.insert(i + 1, info);
                 added = true;
                 break;
@@ -147,7 +148,7 @@
   Paint all badges in z-order.
 */
 void HbBadgeIcon::paint(QPainter *painter,
-                        const QRectF& rect,
+                        const QRectF &rect,
                         QIcon::Mode mode,
                         QIcon::State state,
                         bool mirror)
@@ -155,12 +156,12 @@
     int count = mBadgeIcons.count();
 
     for (int i = count - 1; i >= 0; i--) {
-        HbBadgeIconInfo aIcon = mBadgeIcons[i];
-        Qt::Alignment align = aIcon.alignment();
+        HbBadgeIconInfo badge = mBadgeIcons.at(i);
+        // Fix the alignment.
+        Qt::Alignment align = badge.alignment();
         Qt::Alignment absAlign = align;
         if (mirror) {
             absAlign = align & ~(Qt::AlignRight | Qt::AlignLeft);
-
             if (align & Qt::AlignLeft) {
                 absAlign |= Qt::AlignRight;
             }
@@ -168,30 +169,44 @@
                 absAlign |= Qt::AlignLeft;
             }
         }
-        // ... and then draw at the specified location.
-        aIcon.icon().paint(painter,
-                 rect,
-                 Qt::KeepAspectRatio,
-                 absAlign,
-                 mode,
-                 state);
+        // Update the size.
+        QSizeF sizeFactor = badge.sizeFactor();
+        if (!sizeFactor.isNull()) {
+            QSizeF targetSizeF(sizeFactor.width() * rect.width(), sizeFactor.height() * rect.height());
+            QSize targetSize = targetSizeF.toSize();
+            HbIcon icon = badge.icon();
+            if (targetSize != icon.size().toSize()) {
+                icon.setSize(targetSize);
+                badge.setIcon(icon);
+                mBadgeIcons[i] = badge;
+            }
+        }
+        // And finally draw the badge.
+        badge.icon().paint(painter,
+                           rect,
+                           badge.aspectRatio(),
+                           absAlign,
+                           mode,
+                           state);
     }
 }
 
 /*!
   \internal
  */
-void HbBadgeIcon::externalize(QDataStream& stream)
+void HbBadgeIcon::externalize(QDataStream &stream)
 {
-    int size = mBadgeIcons.size();
+    int count = mBadgeIcons.count();
     // Write out how many badges we'll save first
-    stream << size;
+    stream << count;
     // And write each item
-    for (int i = 0; i < size; i++) {
-        HbBadgeIconInfo aIcon = mBadgeIcons[i];
-        stream << aIcon.icon();
-        stream << (qint32)(aIcon.alignment());
-        stream << aIcon.zValue();
+    for (int i = 0; i < count; i++) {
+        const HbBadgeIconInfo &badge(mBadgeIcons.at(i));
+        stream << badge.icon();
+        stream << (qint32) badge.alignment();
+        stream << badge.zValue();
+        stream << badge.sizeFactor();
+        stream << (qint32) badge.aspectRatio();
     }
 }
 
@@ -199,19 +214,24 @@
 /*!
 \Internal
 */
-void HbBadgeIcon::internalize(QDataStream& stream)
+void HbBadgeIcon::internalize(QDataStream &stream)
 {
     int howManyBadges;
     stream >> howManyBadges;
-    for (int i = 0; i<howManyBadges; ++i) {
+    for (int i = 0; i < howManyBadges; ++i) {
         qint32 align;
         qint32 zValue;
         HbIcon icon;
+        QSizeF sizeFactor;
+        qint32 aspectRatio;
         stream >> icon;
         stream >> align;
         stream >> zValue;
+        stream >> sizeFactor;
+        stream >> aspectRatio;
 
-        HbBadgeIconInfo info(icon, (Qt::Alignment)align, zValue);
+        HbBadgeIconInfo info(icon, (Qt::Alignment) align, zValue,
+                             sizeFactor, (Qt::AspectRatioMode) aspectRatio);
         mBadgeIcons.append(info);
-    };
+    }
 }