|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QStandardItemModel> |
|
19 #include <QGraphicsLinearLayout> |
|
20 |
|
21 #include <HbGridView> |
|
22 #include <HbAction> |
|
23 #include <HbInstance> |
|
24 |
|
25 #include "hsimagegridwidget.h" |
|
26 |
|
27 #ifdef COVERAGE_MEASUREMENT |
|
28 #pragma CTC SKIP |
|
29 #endif //COVERAGE_MEASUREMENT |
|
30 |
|
31 namespace |
|
32 { |
|
33 const int FILENAMEROLE = Qt::UserRole + 1; |
|
34 } |
|
35 |
|
36 /*! |
|
37 \class HsImageGridWidget |
|
38 \ingroup group_hsutils |
|
39 \brief Widget which shows images in a grid. |
|
40 */ |
|
41 |
|
42 /*! |
|
43 Constructor. |
|
44 \a imageFiles List of absolut paths to image files. |
|
45 \a parent Parent item. |
|
46 */ |
|
47 HsImageGridWidget::HsImageGridWidget(const QStringList &imageFiles, |
|
48 QGraphicsItem *parent) |
|
49 : HbView(parent), |
|
50 mGridModel(new QStandardItemModel(this)) |
|
51 { |
|
52 mGridView = new HbGridView(); |
|
53 mGridView->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide); |
|
54 mGridView->setSelectionMode(HbAbstractItemView::NoSelection); |
|
55 mGridView->setModel(mGridModel); |
|
56 |
|
57 connect(mGridView, |
|
58 SIGNAL(activated(QModelIndex)), |
|
59 SLOT(gridItemActivated(QModelIndex))); |
|
60 |
|
61 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; |
|
62 layout->addItem(mGridView); |
|
63 setLayout(layout); |
|
64 |
|
65 setContent(imageFiles); |
|
66 } |
|
67 |
|
68 /*! |
|
69 Destructor |
|
70 */ |
|
71 HsImageGridWidget::~HsImageGridWidget() |
|
72 { |
|
73 } |
|
74 |
|
75 /*! |
|
76 Sets content image files to widget. |
|
77 \a images List of absolut paths to image files. |
|
78 */ |
|
79 void HsImageGridWidget::setContent(const QStringList &images) |
|
80 { |
|
81 mGridModel->clear(); |
|
82 QSize targetSize(150, 150); |
|
83 QList<QStandardItem *> items; |
|
84 QStandardItem *standardItem = 0; |
|
85 for (int i = 0; i < images.count(); ++i) { |
|
86 QPixmap original(images[i]); |
|
87 QIcon scaledIcon(original.scaled(targetSize, Qt::KeepAspectRatio)); |
|
88 standardItem = new QStandardItem(); |
|
89 standardItem->setData(HbIcon(scaledIcon), Qt::DecorationRole); |
|
90 standardItem->setData(images[i], FILENAMEROLE); |
|
91 items << standardItem; |
|
92 } |
|
93 mGridModel->appendColumn(items); |
|
94 } |
|
95 |
|
96 /*! |
|
97 \fn void HsImageGridWidget::imageSelected(const QString& aSelectedImage) |
|
98 Emitted when image is selected from a grid |
|
99 \a aImageFiles List of absolut paths to image files. |
|
100 */ |
|
101 |
|
102 /*! |
|
103 Finds item from model and emits imageSelected |
|
104 \a index is the index of selected image |
|
105 */ |
|
106 void HsImageGridWidget::gridItemActivated(const QModelIndex &index) |
|
107 { |
|
108 QVariant data = mGridModel->data(index, FILENAMEROLE); |
|
109 emit imageSelected( data.toString() ); |
|
110 } |
|
111 |
|
112 #ifdef COVERAGE_MEASUREMENT |
|
113 #pragma CTC ENDSKIP |
|
114 #endif //COVERAGE_MEASUREMENT |