Modified FriendListItem content.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 28 Apr 2010 12:47:52 +0000 (15:47 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 28 Apr 2010 12:47:52 +0000 (15:47 +0300)
images.qrc
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistview.cpp
src/ui/listviewscreen.cpp

index f105ef9..25da8f4 100644 (file)
@@ -15,5 +15,6 @@
         <file>res/images/list_item_bottom.png</file>
         <file>res/images/list_item_middle.png</file>
         <file>res/images/list_item_top.png</file>
+        <file>res/images/list_item.png</file>
     </qresource>
 </RCC>
index ffba8a4..359683b 100644 (file)
@@ -30,6 +30,9 @@
 #include <QAbstractTransition>
 #include <QPropertyAnimation>
 #include <QSignalTransition>
+#include <QFontMetrics>
+#include <QFormLayout>
+#include <QSpacerItem>
 
 #include "friendlistitem.h"
 #include "user/user.h"
@@ -68,90 +71,111 @@ FriendListItem::FriendListItem(QWidget *parent)
     : QWidget(parent)
     , m_expanded(false)
 {
-    QWidget *childWidget = new QWidget(this);
-    QPalette palette = childWidget->palette();
+    QGridLayout *layout = new QGridLayout(this);
+    this->setLayout(layout);
+
+    m_childWidget = new QWidget(this);
+    QPalette palette = m_childWidget->palette();
     palette.setColor(QPalette::Foreground, QColor::fromRgb(152, 152, 152));
-    childWidget->setPalette(palette);
+    m_childWidget->setPalette(palette);
     QFont font = QFont("Nokia Sans", 13, QFont::Normal);
-    childWidget->setFont(font);
+    m_childWidget->setFont(font);
 
-    QGridLayout *infoLayout = new QGridLayout(this);
-    infoLayout->setSpacing(0);
-    infoLayout->setMargin(0);
-    childWidget->setLayout(infoLayout);
+    QFormLayout *infoLayout = new QFormLayout(this);
+    m_childWidget->setLayout(infoLayout);
 
     QLabel *clockLabel = new QLabel(this);
     clockLabel->setPixmap(QPixmap(CLOCK_PATH));
+    clockLabel->setMinimumSize(ICON_WIDTH, ICON_HEIGHT);
     QLabel *envelopeLabel = new QLabel(this);
     envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
+    envelopeLabel->setMinimumSize(ICON_WIDTH, ICON_HEIGHT);
     QLabel *compassLabel = new QLabel(this);
     compassLabel->setPixmap(QPixmap(COMPASS_PATH));
+    compassLabel->setMinimumSize(ICON_WIDTH, ICON_HEIGHT);
 
+    m_imageLabel = new QLabel(this);
+    m_nameLabel = new QLabel("", this);
     m_updatedLabel = new QLabel("", this);
     m_updatedLabel->setWordWrap(true);
+    m_updatedLabel->setMinimumWidth(ICON_WIDTH);
     m_statusTextLabel = new QLabel("", this);
     m_statusTextLabel->setWordWrap(true);
+    m_statusTextLabel->setMinimumWidth(ICON_WIDTH);
     m_locationLabel = new QLabel("", this);
     m_locationLabel->setWordWrap(true);
+    m_locationLabel->setMinimumWidth(ICON_WIDTH);
 
-    infoLayout->setColumnStretch(1, 1);
-    infoLayout->setColumnMinimumWidth(0, 28);
-    infoLayout->setRowMinimumHeight(0, 28);
+    infoLayout->addRow(clockLabel, m_updatedLabel);
+    infoLayout->addRow(envelopeLabel, m_statusTextLabel);
+    infoLayout->addRow(compassLabel, m_locationLabel);
 
-    infoLayout->addWidget(clockLabel, 0, 0, 1, 1, Qt::AlignTop);
-    infoLayout->addWidget(m_updatedLabel, 0, 1);
-    infoLayout->addWidget(envelopeLabel, 1, 0, 1, 1, Qt::AlignTop);
-    infoLayout->addWidget(m_statusTextLabel, 1, 1);
-    infoLayout->addWidget(compassLabel, 2, 0, 1, 1, Qt::AlignTop);
-    infoLayout->addWidget(m_locationLabel, 2, 1);
+    infoLayout->setLabelAlignment(Qt::AlignTop);
+    infoLayout->setFormAlignment(Qt::AlignCenter);
 
-    childWidget->setGeometry(75, 53, 368-75-5, 141-53-5);
+    QPalette childPal = m_childWidget->palette();
+    childPal.setColor(QPalette::Background, Qt::red);
+    m_childWidget->setPalette(childPal);
 
-//    QStateMachine machine;
-//    QState *state1 = new QState(&machine);
-//    QState *state2 = new QState(&machine);
-//    machine.setInitialState(state1);
+    //m_childWidget->setGeometry(75, 53, 368-75-5, 141-53-5);
 
-//    QPushButton *btn = new QPushButton(this);
+    layout->addWidget(m_imageLabel, 0, 0);
+    layout->addWidget(m_nameLabel, 0, 1);
+    layout->addWidget(m_childWidget, 1, 1);
 
-//    //state1->assignProperty(childWidget, "geometry", QRect(0, 0, 150, 50));
-//    state1->assignProperty(childWidget, "pos", QPointF(0, 0));
-//    //state2->assignProperty(childWidget, "geometry", QRect(0, 0, 150, 100));
-//    state2->assignProperty(childWidget, "pos", QPointF(100, 100));
-//
-//
-//    QAbstractTransition *t1 = state1->addTransition(btn, SIGNAL(clicked()), state2);
-//    //t1->addAnimation(new QPropertyAnimation(childWidget, "geometry"));
-//    t1->addAnimation(new QPropertyAnimation(childWidget, "pos"));
-//
-//    QAbstractTransition *t2 = state2->addTransition(btn, SIGNAL(clicked()), state1);
-//    //t2->addAnimation(new QPropertyAnimation(childWidget, "geometry"));
-//    t2->addAnimation(new QPropertyAnimation(childWidget, "pos"));
-//
-//    machine.start();
+    this->setObjectName("listItem");
+    this->setStyleSheet("#listItem { border-image: url(:/res/images/list_item.png) 20%; " \
+                        "border-width: 20px 14px 16px 14px; }");
+
+    this->setMinimumSize(368, 141);
+
+//    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 }
 
 void FriendListItem::setData(const User &user)
 {
-    m_name = user.name();
+    m_imageLabel->setPixmap(QPixmap(":/res/images/dummy_Avatar.png"));
+    m_nameLabel->setText(user.name());
     m_updatedLabel->setText(user.timestamp());
     m_statusTextLabel->setText(user.note());
     m_locationLabel->setText(user.address());
     m_image = user.profileImageUrl().toString();
+
+    QFontMetrics fontMetrics = QFontMetrics(QFont("Nokia Sans", 13, QFont::Normal));
+
+    qDebug() << "Status text metrics: " << fontMetrics.boundingRect(user.note());
 }
 
 void FriendListItem::mousePressEvent(QMouseEvent *event)
 {
+    m_mousePosition = event->pos();
+}
+
+void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
+{
     qDebug() << __PRETTY_FUNCTION__;
 
-    emit changeState();
+    if (event->pos() == m_mousePosition) {
 
-    if (m_expanded)
-        m_expanded = false;
-    else
-        m_expanded = true;
+        emit changeState();
 
-    updateGeometry();
+        if (m_expanded) {
+            m_expanded = false;
+            this->setGeometry(0, 0, this->width(), 141);
+            m_childWidget->setGeometry(75, 53, 368-75-5, 141-53-5);
+            m_childWidget->updateGeometry();
+
+        }
+        else {
+            m_expanded = true;
+            this->setGeometry(0, 0, this->width(), 200);
+            m_childWidget->setGeometry(75, 53, 368-75-5, 250-53-5);
+            m_childWidget->updateGeometry();
+        }
+
+        updateGeometry();
+        emit changeState();
+    }
 }
 
 QSize FriendListItem::sizeHint() const
@@ -159,48 +183,66 @@ QSize FriendListItem::sizeHint() const
     qDebug() << __PRETTY_FUNCTION__ << " " << m_expanded;
 
     if (m_expanded)
-        return QSize(368, 200);
+        return QSize(this->width(), 250);
     else
-        return QSize(368, 141);
+        return QSize(this->width(), 141);
 }
 
 void FriendListItem::paintEvent(QPaintEvent *event)
 {
+    QStyleOption opt;
+    opt.init(this);
     QPainter painter(this);
-    QRect itemRect = event->rect();
+    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
 
-    if (m_expanded)
-        itemRect = QRect(0, 0, 368, 200);
-    else
-        itemRect = QRect(0, 0, 368, 141);
-
-    //Draw background
-    QRect topRect = QRect(itemRect.left(), itemRect.top(), BACKGROUND_TOP_WIDTH,
-                          BACKGROUND_TOP_HEIGHT);
-    painter.drawPixmap(topRect, QPixmap(BACKGROUND_TOP_PATH));
-
-    QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_MIDDLE_WIDTH,
-                             itemRect.height());
-    painter.drawPixmap(middleRect, QPixmap(BACKGROUND_MIDDLE_PATH));
-    qDebug() << "Middle rect: " << middleRect;
-
-    if (itemRect.height() >= (141 - 15)) {
-        QRect bottomRect = QRect(topRect.left(), middleRect.bottom() - 14, BACKGROUND_BOTTOM_WIDTH,
-                                 BACKGROUND_BOTTOM_HEIGHT);
-        painter.drawPixmap(bottomRect, QPixmap(BACKGROUND_BOTTOM_PATH));
-    }
+    QRect itemRect = event->rect();
 
-    //Draw image
-    QString image = QString(":/res/images/dummy_Avatar.png");
-    QRect imageRect = QRect(itemRect.left() + IMAGE_X, itemRect.top() + IMAGE_Y,
-                                IMAGE_WIDTH, IMAGE_HEIGHT);
-    painter.drawPixmap(imageRect, QPixmap(image));
-
-    //Draw name
-    QRect nameRect = QRect(itemRect.left() + IMAGE_WIDTH + 11, itemRect.top() + 15, itemRect.width(),
-                           itemRect.height());
-    QPen whitePen(QColor(Qt::white), 1, Qt::SolidLine);
-    painter.setPen(whitePen);
-    painter.setFont(QFont( "Nokia Sans", 18, QFont::Normal));
-    painter.drawText(nameRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, m_name, &nameRect);
+//    if (m_expanded)
+//        itemRect = QRect(0, 0, 568, 200);
+//    else
+//        itemRect = QRect(0, 0, 568, 141);
+//
+//    //Draw background
+//    QRect topRect = QRect(itemRect.left(), itemRect.top(), BACKGROUND_TOP_WIDTH,
+//                          BACKGROUND_TOP_HEIGHT);
+//    painter.drawPixmap(topRect, QPixmap(BACKGROUND_TOP_PATH));
+//    qDebug() << "Top rect   : " << topRect;
+//
+//    QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_MIDDLE_WIDTH,
+//                             itemRect.height() - BACKGROUND_BOTTOM_HEIGHT - BACKGROUND_TOP_HEIGHT);
+//    painter.drawPixmap(middleRect, QPixmap(BACKGROUND_MIDDLE_PATH));
+//    qDebug() << "Middle rect: " << middleRect;
+//
+//    QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, BACKGROUND_BOTTOM_WIDTH,
+//                             BACKGROUND_BOTTOM_HEIGHT);
+//    painter.drawPixmap(bottomRect, QPixmap(BACKGROUND_BOTTOM_PATH));
+//    qDebug() << "Bottom rect: " << bottomRect;
+//
+//    //Draw image
+//    QString image = QString(":/res/images/dummy_Avatar.png");
+//    QRect imageRect = QRect(itemRect.left() + IMAGE_X, itemRect.top() + IMAGE_Y,
+//                                IMAGE_WIDTH, IMAGE_HEIGHT);
+//    painter.drawPixmap(imageRect, QPixmap(image));
+//
+//    //Draw name
+//    QRect nameRect = QRect(itemRect.left() + IMAGE_WIDTH + 11, itemRect.top() + 15, itemRect.width(),
+//                           itemRect.height());
+//    QPen whitePen(QColor(Qt::white), 1, Qt::SolidLine);
+//    painter.setPen(whitePen);
+//    painter.setFont(QFont( "Nokia Sans", 18, QFont::Normal));
+//    painter.drawText(nameRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, m_name, &nameRect);
+
+//    //Draw image
+//    QString image = QString(":/res/images/dummy_Avatar.png");
+//    QRect imageRect = QRect(IMAGE_X, IMAGE_Y,
+//                                IMAGE_WIDTH, IMAGE_HEIGHT);
+//    painter.drawPixmap(imageRect, QPixmap(image));
+//
+//    //Draw name
+//    QRect nameRect = QRect(IMAGE_WIDTH + 11, 15, itemRect.width(),
+//                           50);
+//    QPen whitePen(QColor(Qt::white), 1, Qt::SolidLine);
+//    painter.setPen(whitePen);
+//    painter.setFont(QFont( "Nokia Sans", 18, QFont::Normal));
+//    painter.drawText(nameRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, m_name, &nameRect);
 }
index 1943757..b356dc5 100644 (file)
@@ -44,6 +44,8 @@ protected:
 
     void mousePressEvent(QMouseEvent *);
 
+    void mouseReleaseEvent(QMouseEvent *);
+
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
@@ -63,9 +65,13 @@ private:
     QLabel *m_updatedLabel;
     QLabel *m_statusTextLabel;
     QLabel *m_locationLabel;
+    QLabel *m_imageLabel;
+    QLabel *m_nameLabel;
     QString m_name;
     QString m_image;
     bool m_expanded;
+    QPoint m_mousePosition;
+    QWidget *m_childWidget;
 };
 
 #endif // FRIENDLISTITEM_H
index 76eed37..8300234 100644 (file)
@@ -30,6 +30,11 @@ FriendListView::FriendListView(QWidget *parent)
     m_friendListLayout->setMargin(0);
     m_friendListLayout->setSpacing(0);
     m_friendListLayout->setStretch(0, 0);
+    m_friendListLayout->setSizeConstraint(QLayout::SetFixedSize);
+
+    QPalette pal = this->palette();
+    pal.setColor(QPalette::Background, Qt::green);
+    this->setPalette(pal);
 
     this->setLayout(m_friendListLayout);
 }
index 872244b..6a946de 100644 (file)
@@ -120,9 +120,11 @@ ListViewScreen::ListViewScreen(QWidget *parent)
     friendListView->addWidget(item4);
     friendListView->addWidget(item5);
     friendListView->addWidget(item6);
+//    friendListView->addWidget(new QPushButton("Hep", this));
 
     QScrollArea *friendListScroll = new QScrollArea();
     friendListScroll->setWidget(friendListView);
+    friendListScroll->setWidgetResizable(true);
     //DEBUG