# HG changeset patch # User Dremov Kirill (Nokia-D-MSW/Tampere) # Date 1286140639 -10800 # Node ID 67589f86e56bccb78632dff2ebdddd8b25fe6fba # Parent dc71378f48908cc1a85fc945c48694ca6df53ba8 Revision: 201036 Kit: 201039 diff -r dc71378f4890 -r 67589f86e56b inc/profileswidget.h --- 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(); diff -r dc71378f4890 -r 67589f86e56b inc/profileswidgetconsts.h --- 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 diff -r dc71378f4890 -r 67589f86e56b src/profileswidget.cpp --- 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 #include #include +#include // 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); } /*!