started feature to show bigger profile images
[situare] / src / ui / userinfo.cpp
index 4afdaf3..e85921f 100644 (file)
 #include "../user/user.h"
 #include "userinfo.h"
 
-const int BACKGROUND_TOP_HEIGHT = 20;
-const int BACKGROUND_BOTTOM_HEIGHT = 15;
-const QColor COLOR_GRAY = QColor(152, 152, 152);    ///< Gray color
-const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal);    ///< Normal font
-const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);     ///< Small font
-const int ICON_HEIGHT = 24;     ///< Icon height
-const int ICON_WIDTH = 24;       ///< Icon width
-const int IMAGE_HEIGHT = 60; ///< Friend image height
-const int IMAGE_WIDTH = 60;  ///< Friend image width
-const int ITEM_MIN_WIDTH = 245;  ///< Minimum width for item
-const int MARGIN = 5;   ///< Icon margin
+const int BACKGROUND_WIDTH = 240; ///< Width for item
+const int BACKGROUND_TOP_HEIGHT = 16; ///< Height for item top
+const int BACKGROUND_BOTTOM_HEIGHT = 15; ///< Height for item bottom
+const QColor COLOR_GRAY = QColor(152, 152, 152); ///< Gray color
+const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal); ///< Normal font
+const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);  ///< Small font
+const int ICON_HEIGHT = 24; ///< Icon height
+const int ICON_WIDTH = 24;  ///< Icon width
+const int IMAGE_HEIGHT = 60;    ///< Profile image height
+const int IMAGE_WIDTH = 60;     ///< Profile image width
+const int MARGIN = 5; ///< Icon margin
 const int MOUSE_PRESS_AREA_WIDTH = 20;  ///< Area width for item height toggling
 const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
 
@@ -45,60 +45,50 @@ const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height togglin
 *
 * @brief All label's maximum width
 */
-const int LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - ICON_WIDTH;
-
-/**
-* @brief Name label's maximum width
-*
-* @var NAME_LABEL_MAX_WIDTH
-*/
-const int NAME_LABEL_MAX_WIDTH = LABEL_MAX_WIDTH + 70;
+const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - ICON_WIDTH + 130;
 
 UserInfo::UserInfo(QWidget *parent)
     : QWidget(parent),
       m_expanded(false)
-{    
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
     QVBoxLayout *verticalLayout = new QVBoxLayout(this);
     verticalLayout->setContentsMargins(MARGIN * 2, 0, MARGIN * 2, MARGIN * 2);
-//    verticalLayout->setSizeConstraint(QLayout::SetFixedSize);
     verticalLayout->setSpacing(0);
-    this->setLayout(verticalLayout);
+    setLayout(verticalLayout);
 
-    QVBoxLayout *topLayout = new QVBoxLayout(this);
-    topLayout->setMargin(0);
-    topLayout->setSpacing(0);
-
-    QFormLayout *infoLayout = new QFormLayout(this);
+    QFormLayout *infoLayout = new QFormLayout();
     infoLayout->setMargin(0);
     infoLayout->setSpacing(0);
 
-    QHBoxLayout *buttonLayout = new QHBoxLayout(this);
+    QHBoxLayout *buttonLayout = new QHBoxLayout();
     buttonLayout->setMargin(0);
     buttonLayout->setSpacing(0);
 
-    QLabel *envelopeLabel = new QLabel(this);
+    QLabel *envelopeLabel = new QLabel();
     envelopeLabel->setPixmap(QPixmap(":/res/images/envelope.png"));
     envelopeLabel->setContentsMargins(0, 0, MARGIN, 0);
     envelopeLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
-    QLabel *compassLabel = new QLabel(this);
+    QLabel *compassLabel = new QLabel();
     compassLabel->setPixmap(QPixmap(":/res/images/compass.png"));
     compassLabel->setContentsMargins(0, 0, MARGIN, 0);
     compassLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
-    QLabel *clockLabel = new QLabel(this);
+    QLabel *clockLabel = new QLabel();
     clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
     clockLabel->setContentsMargins(0, 0, MARGIN, 0);
     clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
 
-    m_imageLabel = new QLabel(this);
-    m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
+    m_findButton = new ImageButton();
 
-    m_nameLabel = new QLabel(this);
+    m_nameLabel = new QLabel();
+    m_nameLabel->setWordWrap(true);
 
-    m_statusTextLabel = new QLabel(this);
+    m_statusTextLabel = new QLabel();
     m_statusTextLabel->setWordWrap(true);
-    m_locationLabel = new QLabel(this);
+    m_locationLabel = new QLabel();
     m_locationLabel->setWordWrap(true);
-    m_updatedLabel = new QLabel(this);
+    m_updatedLabel = new QLabel();
     m_updatedLabel->setWordWrap(true);
 
     ImageButton *updateFriendsButton = new ImageButton(this, ":/res/images/refresh.png",
@@ -113,20 +103,20 @@ UserInfo::UserInfo(QWidget *parent)
     infoLayout->addRow(compassLabel, m_locationLabel);
     infoLayout->addRow(clockLabel, m_updatedLabel);
 
-//    verticalLayout->addWidget(m_imageLabel, 0, Qt::AlignHCenter);
-//    verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
-    topLayout->addWidget(m_imageLabel, 0, Qt::AlignHCenter);
-    topLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
-    verticalLayout->addLayout(topLayout);
-    verticalLayout->addLayout(infoLayout, 1);
+    verticalLayout->addWidget(m_findButton, 0, Qt::AlignHCenter);
+    verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
+    verticalLayout->addLayout(infoLayout);
     verticalLayout->addLayout(buttonLayout);
 
     connect(updateStatusMessageButton,SIGNAL(clicked()),
             this,SLOT(messageUpdate()));
     connect(updateFriendsButton,SIGNAL(clicked()),
             this, SIGNAL(refreshUserData()));
+    connect(m_findButton, SIGNAL(clicked()),
+        this, SLOT(findButtonClicked()));
 
-    setFixedWidth(235);
+    setFixedWidth(BACKGROUND_WIDTH);
+    //setFixedWidth(500);
 
     this->setFont(NOKIA_FONT_SMALL);
     m_nameLabel->setFont(NOKIA_FONT_NORMAL);
@@ -137,27 +127,23 @@ UserInfo::UserInfo(QWidget *parent)
     namePalette.setColor(QPalette::Foreground, Qt::white);
     m_nameLabel->setPalette(namePalette);
 
-    m_backgroundTopImage.load(":/res/images/list_item_top.png");
-    m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
-    m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
-
-    qWarning() << "Widget width:" << size().width();
-    qWarning() << "VLay width:" << verticalLayout->sizeHint().width();
+    m_backgroundTopImage.load(":/res/images/user_info_item_top.png");
+    m_backgroundMiddleImage.load(":/res/images/user_info_item_middle.png");
+    m_backgroundBottomImage.load(":/res/images/user_info_item_bottom.png");
 }
 
-void UserInfo::setUserName(const QString &name)
+void UserInfo::setAddress(const QString &address)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_userName = name;
-    setText(false);
+    m_locationLabel->setText(address);
 }
 
-void UserInfo::setAvatar(const QPixmap &image)
+void UserInfo::setCoordinates(const QPointF &coordinates)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_imageLabel->setPixmap(image);
+    m_coordinates = coordinates;
 }
 
 void UserInfo::setMessageText(const QString &text)
@@ -168,18 +154,26 @@ void UserInfo::setMessageText(const QString &text)
     setText(false);
 }
 
-void UserInfo::setAddress(const QString &addr)
+void UserInfo::setProfileImage(const QPixmap &image)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_findButton->setButtonIcon(image);
+}
+
+void UserInfo::setTime(const QString &time)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_locationLabel->setText(addr);
+    m_updatedLabel->setText(time);
 }
 
-void UserInfo::setTime(const QString &tim)
+void UserInfo::setUserName(const QString &name)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_updatedLabel->setText(tim);
+    m_userName = name;
+    setText(false);
 }
 
 QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
@@ -208,7 +202,7 @@ void UserInfo::setText(bool expanded)
         m_statusTextLabel->setText(m_messageText);
     }
     else {
-        m_nameLabel->setText(shortenText(m_nameLabel, m_userName, NAME_LABEL_MAX_WIDTH));
+        m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
         m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText,
                                                LABEL_MAX_WIDTH));
     }
@@ -236,18 +230,15 @@ void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
 
     QPainter painter(this);
 
-    QRect topRect = QRect(0, 0, ITEM_MIN_WIDTH, BACKGROUND_TOP_HEIGHT);
-    QRect middleRect = QRect(0, topRect.bottom(), ITEM_MIN_WIDTH,
+    QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
+    QRect middleRect = QRect(0, topRect.bottom(), BACKGROUND_WIDTH,
                              height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
-    QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), ITEM_MIN_WIDTH,
+    QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
                              BACKGROUND_BOTTOM_HEIGHT);
 
     painter.drawPixmap(topRect, m_backgroundTopImage);
     painter.drawPixmap(middleRect, m_backgroundMiddleImage);
     painter.drawPixmap(bottomRect, m_backgroundBottomImage);
-
-//    painter.setPen(Qt::white);
-//    painter.drawRect(rect().x(), rect().y(), rect().width() - 1, rect().height() - 1);
 }
 
 void UserInfo::mousePressEvent(QMouseEvent *event)
@@ -257,6 +248,13 @@ void UserInfo::mousePressEvent(QMouseEvent *event)
     m_mousePosition = event->pos();
 }
 
+void UserInfo::findButtonClicked()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    emit findUser(m_coordinates);
+}
+
 void UserInfo::messageUpdate()
 {
     qDebug() << __PRETTY_FUNCTION__;