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 #include "tstasksgriditem.h" |
|
18 |
|
19 #include <hblabel.h> |
|
20 #include <hbpushbutton.h> |
|
21 #include <hbabstractitemview.h> |
|
22 #include <hbanchorlayout.h> |
|
23 #include "tsdataroles.h" |
|
24 |
|
25 /*! |
|
26 \class TsTasksGridItem |
|
27 \ingroup group_tsdevicedialogplugin |
|
28 \brief Item that should be presented in grid. |
|
29 */ |
|
30 |
|
31 |
|
32 TsTasksGridItem::TsTasksGridItem() : HbAbstractViewItem(), mScreenshotLabel(0), mApplicationNameLabel(0), mDeleteButton(0) |
|
33 { |
|
34 } |
|
35 |
|
36 TsTasksGridItem::TsTasksGridItem(const TsTasksGridItem &item) : HbAbstractViewItem(item) |
|
37 { |
|
38 // add screenshot |
|
39 mScreenshotLabel = new HbLabel(); |
|
40 mScreenshotLabel->setAlignment(Qt::AlignHCenter); |
|
41 |
|
42 // add application name label |
|
43 mApplicationNameLabel = new HbLabel(); |
|
44 mApplicationNameLabel->setAlignment(Qt::AlignCenter); |
|
45 |
|
46 // add close app button |
|
47 HbIcon deleteIcon(":/resource/delete.png"); |
|
48 mDeleteButton = new HbPushButton(); |
|
49 mDeleteButton->setIcon(deleteIcon); |
|
50 mDeleteButton->setPreferredSize(48, 48); |
|
51 mDeleteButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
52 mDeleteButton->setEnabled(true); |
|
53 connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(handleDeleteClicked())); |
|
54 mDeleteButton->hide(); |
|
55 |
|
56 setContentsMargins(5, 5, 5, 5); |
|
57 |
|
58 // add all items to layout |
|
59 HbAnchorLayout *anchorLayout = new HbAnchorLayout(); |
|
60 anchorLayout->setAnchor(mApplicationNameLabel, Hb::LeftEdge, anchorLayout, Hb::LeftEdge, 0); |
|
61 anchorLayout->setAnchor(mApplicationNameLabel, Hb::TopEdge, anchorLayout, Hb::TopEdge, 0); |
|
62 anchorLayout->setAnchor(mApplicationNameLabel, Hb::RightEdge, anchorLayout, Hb::RightEdge, 0); |
|
63 |
|
64 anchorLayout->setAnchor(mScreenshotLabel, Hb::TopEdge, mApplicationNameLabel, Hb::BottomEdge, 0); |
|
65 anchorLayout->setAnchor(mScreenshotLabel, Hb::LeftEdge, anchorLayout, Hb::LeftEdge, 0); |
|
66 anchorLayout->setAnchor(mScreenshotLabel, Hb::RightEdge, anchorLayout, Hb::RightEdge, 0); |
|
67 anchorLayout->setAnchor(mScreenshotLabel, Hb::BottomEdge, anchorLayout, Hb::BottomEdge, 0); |
|
68 |
|
69 anchorLayout->setAnchor(mDeleteButton, Hb::RightEdge, mScreenshotLabel, Hb::RightEdge, 0); |
|
70 anchorLayout->setAnchor(mDeleteButton, Hb::TopEdge, mScreenshotLabel, Hb::TopEdge, 0); |
|
71 |
|
72 setLayout(anchorLayout); |
|
73 } |
|
74 |
|
75 TsTasksGridItem::~TsTasksGridItem() |
|
76 { |
|
77 } |
|
78 |
|
79 HbAbstractViewItem *TsTasksGridItem::createItem() |
|
80 { |
|
81 TsTasksGridItem *newItem = new TsTasksGridItem(*this); |
|
82 connect(newItem, SIGNAL(deleteClicked(QModelIndex)), itemView(), SIGNAL(deleteButtonClicked(QModelIndex))); |
|
83 return newItem; |
|
84 } |
|
85 |
|
86 void TsTasksGridItem::handleDeleteClicked() |
|
87 { |
|
88 emit deleteClicked(modelIndex()); |
|
89 } |
|
90 |
|
91 void TsTasksGridItem::updateChildItems() |
|
92 { |
|
93 mScreenshotLabel->setIcon(modelIndex().data(Qt::DecorationRole).value<HbIcon>()); |
|
94 mApplicationNameLabel->setPlainText(modelIndex().data(Qt::DisplayRole).toString()); |
|
95 QVariant status(modelIndex().data(TsDataRoles::Closable)); |
|
96 const bool isRunning(status.isValid() && status.toBool()); |
|
97 if (isRunning) { |
|
98 mDeleteButton->show(); |
|
99 } else { |
|
100 mDeleteButton->hide(); |
|
101 } |
|
102 } |
|