1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Another view for test application. |
|
15 * |
|
16 */ |
|
17 #include "hgcoverflowwidget.h" |
|
18 #include "trace.h" |
|
19 |
|
20 #include <qgraphicslinearlayout.h> |
|
21 #include <qgraphicssceneresizeevent> |
|
22 |
|
23 |
|
24 |
|
25 HgCoverflowWidget::HgCoverflowWidget(QGraphicsItem *parent) : HgMediawall(parent), |
|
26 mTextPositionsDirty(false) |
|
27 { |
|
28 mTitleLabel = new HbLabel("Title", this); |
|
29 mTitleLabel->setAlignment(Qt::AlignCenter); |
|
30 mDescLabel = new HbLabel("Description", this); |
|
31 mDescLabel->setAlignment(Qt::AlignCenter); |
|
32 } |
|
33 |
|
34 HgCoverflowWidget::~HgCoverflowWidget() |
|
35 { |
|
36 |
|
37 } |
|
38 |
|
39 void HgCoverflowWidget::frontItemChanged ( const QModelIndex & current, const QModelIndex & previous ) |
|
40 { |
|
41 if (!this->model()) |
|
42 return; |
|
43 |
|
44 QVariant variant = this->model()->data(current, Qt::DisplayRole); |
|
45 QStringList texts = variant.toStringList(); |
|
46 HbLabel* labels[2]; |
|
47 labels[0] = mTitleLabel; |
|
48 labels[1] = mDescLabel; |
|
49 int n = texts.size() > 2 ? 2 : texts.size(); |
|
50 for (int i = 0; i < n; i++) |
|
51 labels[i]->setPlainText(texts[i]); |
|
52 |
|
53 mTextPositionsDirty = true; |
|
54 } |
|
55 |
|
56 void HgCoverflowWidget::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
57 { |
|
58 HgMediawall::resizeEvent(event); |
|
59 |
|
60 mTextPositionsDirty = true; |
|
61 |
|
62 QObject::connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), |
|
63 this, SLOT(frontItemChanged(const QModelIndex&, const QModelIndex&))); |
|
64 } |
|
65 |
|
66 void HgCoverflowWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
67 { |
|
68 HgMediawall::paint(painter, option, widget); |
|
69 |
|
70 if (mTextPositionsDirty) |
|
71 { |
|
72 QModelIndex index = this->currentIndex(); |
|
73 |
|
74 if (index.isValid()) |
|
75 { |
|
76 QRectF bounds; |
|
77 |
|
78 QPointF halfSize = QPointF(itemSize().width()/2, itemSize().height()/2); |
|
79 bounds.setTopLeft(rect().center() + frontItemPositionDelta() - halfSize); |
|
80 bounds.setBottomRight(rect().center() + frontItemPositionDelta() + halfSize); |
|
81 |
|
82 mTitleLabel->resize(QSizeF(size().width(), mTitleLabel->minimumSize().height())); |
|
83 mTitleLabel->setPos(QPointF(bounds.center().x() - size().width()/2, |
|
84 bounds.top() - 40)); |
|
85 mDescLabel->resize(QSizeF(size().width(), mDescLabel->minimumSize().height())); |
|
86 mDescLabel->setPos(QPointF(bounds.center().x() - size().width()/2, |
|
87 bounds.bottom() + 40 - mDescLabel->minimumSize().height())); |
|
88 |
|
89 frontItemChanged(index, index); |
|
90 |
|
91 mTextPositionsDirty = false; |
|
92 } |
|
93 |
|
94 } |
|
95 |
|
96 } |
|
97 |
|
98 void HgCoverflowWidget::updateTextPositions() |
|
99 { |
|
100 mTextPositionsDirty = true; |
|
101 } |
|
102 |
|
103 |
|
104 |
|