Modified FriendListItem::paint.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 27 Apr 2010 12:58:15 +0000 (15:58 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 27 Apr 2010 12:58:15 +0000 (15:58 +0300)
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistview.cpp

index bd49034..ffba8a4 100644 (file)
@@ -66,6 +66,7 @@ const QString COMPASS_PATH = QString(":/res/images/compass.png");
 
 FriendListItem::FriendListItem(QWidget *parent)
     : QWidget(parent)
+    , m_expanded(false)
 {
     QWidget *childWidget = new QWidget(this);
     QPalette palette = childWidget->palette();
@@ -106,8 +107,6 @@ FriendListItem::FriendListItem(QWidget *parent)
 
     childWidget->setGeometry(75, 53, 368-75-5, 141-53-5);
 
-    this->setMinimumSize(368, 141);
-
 //    QStateMachine machine;
 //    QState *state1 = new QState(&machine);
 //    QState *state2 = new QState(&machine);
@@ -143,26 +142,50 @@ void FriendListItem::setData(const User &user)
 
 void FriendListItem::mousePressEvent(QMouseEvent *event)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     emit changeState();
+
+    if (m_expanded)
+        m_expanded = false;
+    else
+        m_expanded = true;
+
+    updateGeometry();
+}
+
+QSize FriendListItem::sizeHint() const
+{
+    qDebug() << __PRETTY_FUNCTION__ << " " << m_expanded;
+
+    if (m_expanded)
+        return QSize(368, 200);
+    else
+        return QSize(368, 141);
 }
 
 void FriendListItem::paintEvent(QPaintEvent *event)
 {
     QPainter painter(this);
-    //QRect itemRect = event->rect();
-    QRect itemRect = QRect(0, 0, 368, 141);
-    qDebug() << event->rect();
+    QRect itemRect = event->rect();
+
+    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,
-                             BACKGROUND_MIDDLE_HEIGHT);
+                             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() + 1, BACKGROUND_BOTTOM_WIDTH,
+        QRect bottomRect = QRect(topRect.left(), middleRect.bottom() - 14, BACKGROUND_BOTTOM_WIDTH,
                                  BACKGROUND_BOTTOM_HEIGHT);
         painter.drawPixmap(bottomRect, QPixmap(BACKGROUND_BOTTOM_PATH));
     }
index b0461be..1943757 100644 (file)
@@ -50,6 +50,7 @@ protected:
 public:
     enum ListRole { Name, Image, Distance, Updated, StatusText, Location };
 
+    QSize sizeHint() const;
 
 signals:
     void changeState();
@@ -64,6 +65,7 @@ private:
     QLabel *m_locationLabel;
     QString m_name;
     QString m_image;
+    bool m_expanded;
 };
 
 #endif // FRIENDLISTITEM_H
index 266d96f..76eed37 100644 (file)
@@ -29,6 +29,7 @@ FriendListView::FriendListView(QWidget *parent)
     m_friendListLayout = new QVBoxLayout(this);
     m_friendListLayout->setMargin(0);
     m_friendListLayout->setSpacing(0);
+    m_friendListLayout->setStretch(0, 0);
 
     this->setLayout(m_friendListLayout);
 }