Revision: 201036 default tip
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 04 Oct 2010 00:17:19 +0300
changeset 1 67589f86e56b
parent 0 dc71378f4890
Revision: 201036 Kit: 201039
inc/profileswidget.h
inc/profileswidgetconsts.h
src/profileswidget.cpp
--- a/inc/profileswidget.h	Fri Sep 17 09:20:42 2010 +0300
+++ b/inc/profileswidget.h	Mon Oct 04 00:17:19 2010 +0300
@@ -37,6 +37,7 @@
     QRectF boundingRect() const;
     QPainterPath shape() const;
     void changeIcon();
+    void adjustButtonWidth(const QString &text);
 
 public slots:
     void onShow();
--- a/inc/profileswidgetconsts.h	Fri Sep 17 09:20:42 2010 +0300
+++ b/inc/profileswidgetconsts.h	Mon Oct 04 00:17:19 2010 +0300
@@ -22,4 +22,7 @@
 const int ProfilesWidgetSilentProfileId = 1;
 const int ProfilesWidgetMeetingProfileId = 2;
 
+const int ProfilesWidgetDefaultNameLength = 7;
+const int ProfielsWidgetMinimumWidthInPx = 80;
+const int ProfilesWidgetWidthSpaceInPx = 20;
 #endif //PROFILESWIDGETCONSTS_H
--- a/src/profileswidget.cpp	Fri Sep 17 09:20:42 2010 +0300
+++ b/src/profileswidget.cpp	Mon Oct 04 00:17:19 2010 +0300
@@ -21,6 +21,7 @@
 #include <HbStyle>
 #include <HbDocumentLoader>
 #include <HbFrameDrawer>
+#include <QFontMetrics>
 
 // User includes
 #include "profileswidget.h"
@@ -60,7 +61,9 @@
         return;
     }
     
-    mButton->setText(mModel->activeProfileName());
+    QString text = mModel->activeProfileName();
+    mButton->setText(text);   
+    adjustButtonWidth(text);
     HbFrameDrawer *background = new HbFrameDrawer("qtg_fr_hsshortcut_normal", 
             HbFrameDrawer::NinePieces);
     mButton->setFrameBackground(background);
@@ -71,6 +74,29 @@
 }
 
 /*!
+    Adjust button width according to text length
+*/
+void ProfilesWidget::adjustButtonWidth(const QString &text)
+{ 
+    HbFontSpec *sysFontSpec = new HbFontSpec(HbFontSpec::Secondary);
+    QFont sysFont = sysFontSpec->font();
+    QFontMetrics metrics( sysFont );
+
+    int textWidth = 0;
+    for (int i = 0; i < text.length(); i++) {
+        textWidth += metrics.width(text.at(i));
+    }
+    mButton->setMaximumWidth((textWidth > ProfielsWidgetMinimumWidthInPx 
+        ? textWidth : ProfielsWidgetMinimumWidthInPx) + 
+                ProfilesWidgetWidthSpaceInPx);
+    mButton->setMinimumWidth((textWidth > ProfielsWidgetMinimumWidthInPx 
+        ? textWidth : ProfielsWidgetMinimumWidthInPx) + 
+                ProfilesWidgetWidthSpaceInPx);
+        
+    delete sysFontSpec;
+}
+
+/*!
     Handle toggled event of button
 */
 void ProfilesWidget::onButtonPressed()
@@ -81,7 +107,10 @@
     } else {
         mModel->activateProfile(ProfilesWidgetMeetingProfileId);
     }
-    mButton->setText(mModel->activeProfileName());
+
+    QString text = mModel->activeProfileName();
+    mButton->setText(text);
+    adjustButtonWidth(text);
 }
 
 /*!
@@ -89,7 +118,9 @@
 */
 void ProfilesWidget::changeIcon()
 {
-    mButton->setText(mModel->activeProfileName());
+    QString text = mModel->activeProfileName();
+    mButton->setText(text);
+    adjustButtonWidth(text);
 }
 
 /*!