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); } /*!