|
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: Internet Radio home screen widget |
|
15 * |
|
16 */ |
|
17 // System includes |
|
18 #include <QGraphicsLinearLayout> |
|
19 #include <QSettings> |
|
20 #include <QPixmap> |
|
21 #include <HbLabel> |
|
22 #include <HbColorScheme> |
|
23 #include <HbStyleLoader> |
|
24 |
|
25 // User includes |
|
26 #include "irhswidgettitlerow.h" |
|
27 #include "irservicedef.h" |
|
28 #include "irhswidgetuiloader.h" |
|
29 |
|
30 // Constants |
|
31 static const QString KIrHsWidgetTitleRowDocML = ":/resource/irhswidgettitlerow.docml"; |
|
32 static const QString KIrHsWidgetTitleRowContainer = "titlerow_layout"; |
|
33 static const QString KIrHsWidgetStationLogo = "station_logo"; |
|
34 static const QString KNmHsWidgetStationName = "station_name"; |
|
35 |
|
36 static const QString KStationNameColor = "qtc_hs_list_item_title"; |
|
37 static const QString KDefaultStationLogo = "qtg_large_internet_radio"; |
|
38 |
|
39 static const int KIrHsWidgetContentsMargin = 0; |
|
40 static const int KIrHsWidgetLogoSize = 50; // hs widget logo size |
|
41 |
|
42 IrHsWidgetTitleRow::IrHsWidgetTitleRow(QGraphicsItem *aParent, Qt::WindowFlags aFlags) : |
|
43 HbWidget(aParent, aFlags), |
|
44 mStationLogo(NULL), |
|
45 mStationName(NULL) |
|
46 { |
|
47 loadUi(); |
|
48 } |
|
49 |
|
50 IrHsWidgetTitleRow::~IrHsWidgetTitleRow() |
|
51 { |
|
52 } |
|
53 |
|
54 void IrHsWidgetTitleRow::loadUi() |
|
55 { |
|
56 IRHsWidgetUiLoader loader; |
|
57 loader.load(KIrHsWidgetTitleRowDocML); |
|
58 |
|
59 //Create layout |
|
60 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); |
|
61 |
|
62 layout->setContentsMargins(KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin, |
|
63 KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin); |
|
64 layout->setSpacing(KIrHsWidgetContentsMargin); |
|
65 setLayout(layout); |
|
66 |
|
67 QGraphicsWidget *container = loader.findWidget(KIrHsWidgetTitleRowContainer); |
|
68 layout->addItem(container); |
|
69 |
|
70 mStationLogo = static_cast<HbLabel*> (loader.findWidget(KIrHsWidgetStationLogo)); |
|
71 mStationName = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetStationName)); |
|
72 mStationName->setTextColor(HbColorScheme::color(KStationNameColor)); |
|
73 } |
|
74 |
|
75 void IrHsWidgetTitleRow::setDefaultTitle() |
|
76 { |
|
77 #ifdef SUBTITLE_STR_BY_LOCID |
|
78 mStationName->setPlainText(hbTrId("txt_irad_title_internet_radio")); |
|
79 #else |
|
80 mStationName->setPlainText(hbTrId("Internet radio")); |
|
81 #endif |
|
82 } |
|
83 |
|
84 void IrHsWidgetTitleRow::setStationName(const QString& aStationName) |
|
85 { |
|
86 if (mStationName->plainText() != aStationName) |
|
87 { |
|
88 mStationName->setPlainText(aStationName); |
|
89 } |
|
90 } |
|
91 |
|
92 void IrHsWidgetTitleRow::loadStationLogo() |
|
93 { |
|
94 QSettings settings(KIrSettingOrganization, KIrSettingApplication); |
|
95 if (settings.value(KIrSettingStationLogo).canConvert<QPixmap>()) |
|
96 { |
|
97 QPixmap logoPixmap = settings.value(KIrSettingStationLogo).value<QPixmap>(); |
|
98 QPixmap newLogoPixmap = |
|
99 logoPixmap.scaled(QSize(KIrHsWidgetLogoSize,KIrHsWidgetLogoSize),Qt::KeepAspectRatio); |
|
100 QIcon logoQIcon(newLogoPixmap); |
|
101 HbIcon logoHbIcon(logoQIcon); |
|
102 mStationLogo->setIcon(logoHbIcon); |
|
103 } |
|
104 } |
|
105 |
|
106 void IrHsWidgetTitleRow::setDefaultLogo() |
|
107 { |
|
108 mStationLogo->setIcon(KDefaultStationLogo); |
|
109 } |
|
110 |
|
111 |
|
112 void IrHsWidgetTitleRow::mousePressEvent(QGraphicsSceneMouseEvent *aEvent) |
|
113 { |
|
114 Q_UNUSED(aEvent); |
|
115 emit titleRowClicked(); |
|
116 } |