|
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: This widget is used to display audio content in univiewer. |
|
15 * |
|
16 */ |
|
17 #include "msgunieditoraudiowidget.h" |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <QFileInfo> |
|
21 #include <QTimer> |
|
22 #include <HbMenu> |
|
23 |
|
24 // USER INCLUDES |
|
25 #include "msgmediautil.h" |
|
26 #include "msgunieditorutils.h" |
|
27 |
|
28 // LOCAL CONSTANTS |
|
29 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
30 #define LOC_REMOVE hbTrId("txt_common_menu_remove") |
|
31 |
|
32 const QString AUDIO_ICON("qtg_mono_audio"); |
|
33 const QString AUDIO_MIMETYPE("audio"); |
|
34 |
|
35 //---------------------------------------------------------------------------- |
|
36 // MsgUniFiedEditorAudioWidget::MsgUniFiedEditorAudioWidget |
|
37 // @see header file |
|
38 //---------------------------------------------------------------------------- |
|
39 MsgUniFiedEditorAudioWidget::MsgUniFiedEditorAudioWidget(QGraphicsItem *parent) : |
|
40 HbPushButton(parent), mEditorUtils(0), mValidMediaDuration(true) |
|
41 { |
|
42 connect(this, SIGNAL(clicked()), this, SLOT(handleShortTap())); |
|
43 connect(this, SIGNAL(longPress(QPointF)), this, SLOT(handleLongTap(QPointF))); |
|
44 } |
|
45 |
|
46 //---------------------------------------------------------------------------- |
|
47 // MsgUniFiedEditorAudioWidget::~MsgUniFiedEditorAudioWidget |
|
48 // @see header file |
|
49 //---------------------------------------------------------------------------- |
|
50 MsgUniFiedEditorAudioWidget::~MsgUniFiedEditorAudioWidget() |
|
51 { |
|
52 } |
|
53 |
|
54 //---------------------------------------------------------------------------- |
|
55 // MsgUniFiedEditorAudioWidget::~MsgUniFiedEditorAudioWidget |
|
56 // @see header file |
|
57 //---------------------------------------------------------------------------- |
|
58 void MsgUniFiedEditorAudioWidget::populate(const QString &filePath) |
|
59 { |
|
60 mMediaPath = filePath; |
|
61 |
|
62 this->setIcon(HbIcon(AUDIO_ICON)); |
|
63 QFileInfo fileInfo(mMediaPath); |
|
64 this->setText(fileInfo.baseName()); |
|
65 MsgMediaUtil mediaUtil; |
|
66 QString mediaDuration(mediaUtil.mediaDuration(mMediaPath)); |
|
67 if (mediaDuration.isEmpty()) { |
|
68 mValidMediaDuration = false; |
|
69 } |
|
70 else { |
|
71 mValidMediaDuration = true; |
|
72 this->setAdditionalText(mediaDuration); |
|
73 } |
|
74 this->setTextAlignment(Qt::AlignVCenter | Qt::AlignLeft); |
|
75 } |
|
76 |
|
77 //---------------------------------------------------------------------------- |
|
78 // MsgUniFiedEditorAudioWidget::setStretched |
|
79 // @see header file |
|
80 //---------------------------------------------------------------------------- |
|
81 void MsgUniFiedEditorAudioWidget::setStretched(bool stretched) |
|
82 { |
|
83 if (mValidMediaDuration) { |
|
84 HbPushButton::setStretched(stretched); |
|
85 } |
|
86 else { |
|
87 HbPushButton::setStretched(true); |
|
88 } |
|
89 } |
|
90 |
|
91 //---------------------------------------------------------------------------- |
|
92 // MsgUniFiedEditorAudioWidget::handleShortTap |
|
93 // @see header file |
|
94 //---------------------------------------------------------------------------- |
|
95 void MsgUniFiedEditorAudioWidget::handleShortTap() |
|
96 { |
|
97 emit shortTap(mMediaPath); |
|
98 |
|
99 // Open the media. |
|
100 handleOpen(); |
|
101 } |
|
102 |
|
103 //---------------------------------------------------------------------------- |
|
104 // MsgUniFiedEditorAudioWidget::handleLongTap |
|
105 // @see header file |
|
106 //---------------------------------------------------------------------------- |
|
107 void MsgUniFiedEditorAudioWidget::handleLongTap(const QPointF &position) |
|
108 { |
|
109 emit longTap(position); |
|
110 |
|
111 // Display context sensitive menu. |
|
112 HbMenu* menu = new HbMenu; |
|
113 menu->setAttribute(Qt::WA_DeleteOnClose); |
|
114 menu->setDismissPolicy(HbPopup::TapAnywhere); |
|
115 |
|
116 menu->addAction(LOC_OPEN, this, SLOT(handleOpen())); |
|
117 menu->addAction(LOC_REMOVE, this, SLOT(handleRemove())); |
|
118 menu->setPreferredPos(position); |
|
119 menu->show(); |
|
120 } |
|
121 |
|
122 //---------------------------------------------------------------------------- |
|
123 // MsgUniFiedEditorAudioWidget::handleOpen |
|
124 // @see header file |
|
125 //---------------------------------------------------------------------------- |
|
126 void MsgUniFiedEditorAudioWidget::handleOpen() |
|
127 { |
|
128 this->ungrabGesture(Qt::TapGesture); |
|
129 |
|
130 if (!mEditorUtils) |
|
131 { |
|
132 mEditorUtils = new MsgUnifiedEditorUtils(this); |
|
133 } |
|
134 mEditorUtils->launchContentViewer(AUDIO_MIMETYPE, mMediaPath); |
|
135 |
|
136 //fire timer to regrab gesture after some delay. |
|
137 QTimer::singleShot(300,this,SLOT(regrabGesture())); |
|
138 } |
|
139 |
|
140 //---------------------------------------------------------------------------- |
|
141 // MsgUniFiedEditorAudioWidget::handleRemove |
|
142 // @see header file |
|
143 //---------------------------------------------------------------------------- |
|
144 void MsgUniFiedEditorAudioWidget::handleRemove() |
|
145 { |
|
146 emit remove(); |
|
147 } |
|
148 |
|
149 //--------------------------------------------------------------- |
|
150 // MsgUniFiedEditorAudioWidget::regrabGesture |
|
151 // @see header file |
|
152 //--------------------------------------------------------------- |
|
153 void MsgUniFiedEditorAudioWidget::regrabGesture() |
|
154 { |
|
155 this->grabGesture(Qt::TapGesture); |
|
156 } |
|
157 // EOF |