From: Jussi Laitinen Date: Fri, 21 May 2010 10:33:46 +0000 (+0300) Subject: Added ImageButton::setButtonIcon method. Modified FriendListItem to X-Git-Tag: v0.5~39 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=f729053b0640510940fd0625fd34c71c5b0bfe7e;p=situare Added ImageButton::setButtonIcon method. Modified FriendListItem to use profile image as button. --- diff --git a/src/ui/friendlistitem.cpp b/src/ui/friendlistitem.cpp index ff3255b..0755f19 100644 --- a/src/ui/friendlistitem.cpp +++ b/src/ui/friendlistitem.cpp @@ -108,9 +108,6 @@ FriendListItem::FriendListItem(QWidget *parent) compassLabel->setContentsMargins(0, 0, MARGIN, 0); compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT); - m_imageLabel = new QLabel(); - m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT); - m_nameLabel = new QLabel(); m_nameLabel->setFixedHeight(IMAGE_HEIGHT); @@ -120,8 +117,7 @@ FriendListItem::FriendListItem(QWidget *parent) m_distanceImageLabel = new QLabel(); m_distanceImageLabel->setFixedSize(ICON_WIDTH, ICON_HEIGHT); - m_findButton = new ImageButton(this, ":/res/images/show_position.png", - ":/res/images/show_position_s.png"); + m_findButton = new ImageButton(this); m_updatedLabel = new QLabel(); m_updatedLabel->setWordWrap(true); @@ -137,11 +133,11 @@ FriendListItem::FriendListItem(QWidget *parent) infoLayout->addRow(compassLabel, m_locationLabel); infoLayout->addRow(clockLabel, m_updatedLabel); - topLayout->addWidget(m_imageLabel); + topLayout->addWidget(m_findButton); topLayout->addWidget(m_nameLabel, 1); topLayout->addLayout(distanceLayout); - bottomLayout->addWidget(m_findButton, 0, Qt::AlignTop); + bottomLayout->addSpacing(IMAGE_WIDTH); bottomLayout->addLayout(infoLayout); layout->addLayout(topLayout, 0); @@ -173,7 +169,7 @@ void FriendListItem::setData(User *user) m_user = user; - m_imageLabel->setPixmap(m_user->profileImage()); + m_findButton->setButtonIcon(m_user->profileImage()); QString unit; double value; diff --git a/src/ui/friendlistitem.h b/src/ui/friendlistitem.h index 8c63eda..31f000a 100644 --- a/src/ui/friendlistitem.h +++ b/src/ui/friendlistitem.h @@ -139,7 +139,6 @@ private: QLabel *m_distanceImageLabel; ///< Distance image for friend label QLabel *m_distanceTextLabel; ///< Distance text for friend label ImageButton *m_findButton; ///< Friend find button - QLabel *m_imageLabel; ///< Image label QLabel *m_locationLabel; ///< Location label QPoint m_mousePosition; ///< Current mouse press position QLabel *m_nameLabel; ///< Name label diff --git a/src/ui/imagebutton.cpp b/src/ui/imagebutton.cpp index 28e8358..a94ca30 100644 --- a/src/ui/imagebutton.cpp +++ b/src/ui/imagebutton.cpp @@ -33,13 +33,25 @@ ImageButton::ImageButton(QWidget *parent, QString normalIconPictureFileName, { qDebug() << __PRETTY_FUNCTION__; - QPixmap iconPixmap(normalIconPictureFileName); - m_buttonSize = iconPixmap.size(); // Get the button size from the normal state icon picture - QIcon icon(iconPixmap); + if (normalIconPictureFileName != "") { + QPixmap iconPixmap(normalIconPictureFileName); + m_buttonSize = iconPixmap.size(); // Get the button size from the normal state icon picture + QIcon icon(iconPixmap); + + // If there is a picture for selected state, use it instead of a simple highlight change + if(selectedIconPictureFileName != "") + icon.addFile(selectedIconPictureFileName, m_buttonSize, QIcon::Selected); + + setIcon(icon); + setIconSize(m_buttonSize); + setFixedSize(m_buttonSize); + } +} - // If there is a picture for selected state, use it instead of a simple highlight change - if(selectedIconPictureFileName != "") - icon.addFile(selectedIconPictureFileName, m_buttonSize, QIcon::Selected); +void ImageButton::setButtonIcon(const QPixmap &image) +{ + m_buttonSize = image.size(); // Get the button size from the normal state icon picture + QIcon icon(image); setIcon(icon); setIconSize(m_buttonSize); diff --git a/src/ui/imagebutton.h b/src/ui/imagebutton.h index df47c61..0061fe2 100644 --- a/src/ui/imagebutton.h +++ b/src/ui/imagebutton.h @@ -80,6 +80,13 @@ protected: ******************************************************************************/ public: /** + * @brief Set button icon. + * + * @param image image pixmap + */ + void setButtonIcon(const QPixmap &image); + + /** * @brief Sets the button icon mode * * @param mode Button icon mode