Added ImageButton::setButtonIcon method. Modified FriendListItem to
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 21 May 2010 10:33:46 +0000 (13:33 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 21 May 2010 10:33:46 +0000 (13:33 +0300)
use profile image as button.

src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/imagebutton.cpp
src/ui/imagebutton.h

index ff3255b..0755f19 100644 (file)
@@ -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;
index 8c63eda..31f000a 100644 (file)
@@ -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
index 28e8358..a94ca30 100644 (file)
@@ -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);
index df47c61..0061fe2 100644 (file)
@@ -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