|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:BSD$ |
|
10 ** You may use this file under the terms of the BSD license as follows: |
|
11 ** |
|
12 ** "Redistribution and use in source and binary forms, with or without |
|
13 ** modification, are permitted provided that the following conditions are |
|
14 ** met: |
|
15 ** * Redistributions of source code must retain the above copyright |
|
16 ** notice, this list of conditions and the following disclaimer. |
|
17 ** * Redistributions in binary form must reproduce the above copyright |
|
18 ** notice, this list of conditions and the following disclaimer in |
|
19 ** the documentation and/or other materials provided with the |
|
20 ** distribution. |
|
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
|
22 ** the names of its contributors may be used to endorse or promote |
|
23 ** products derived from this software without specific prior written |
|
24 ** permission. |
|
25 ** |
|
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
|
37 ** $QT_END_LICENSE$ |
|
38 ** |
|
39 ****************************************************************************/ |
|
40 |
|
41 #include "radio.h" |
|
42 |
|
43 #include <QtGui> |
|
44 |
|
45 Radio::Radio() |
|
46 { |
|
47 radio = new QRadioTuner; |
|
48 connect(radio,SIGNAL(frequencyChanged(int)),this,SLOT(freqChanged(int))); |
|
49 connect(radio,SIGNAL(signalStrengthChanged(int)),this,SLOT(signalChanged(int))); |
|
50 |
|
51 if(radio->isBandSupported(QRadioTuner::FM)) |
|
52 radio->setBand(QRadioTuner::FM); |
|
53 |
|
54 QWidget *window = new QWidget; |
|
55 QVBoxLayout* layout = new QVBoxLayout; |
|
56 QHBoxLayout* buttonBar = new QHBoxLayout; |
|
57 #if defined Q_OS_SYMBIAN // this is so that we can see all buttons also in 3.1 devices, where the screens are smaller.. |
|
58 QHBoxLayout* buttonBar2 = new QHBoxLayout; |
|
59 #endif |
|
60 QHBoxLayout* topBar = new QHBoxLayout; |
|
61 |
|
62 layout->addLayout(topBar); |
|
63 |
|
64 freq = new QLabel; |
|
65 freq->setText(QString("%1 kHz").arg(radio->frequency()/1000)); |
|
66 topBar->addWidget(freq); |
|
67 |
|
68 signal = new QLabel; |
|
69 if (radio->isAvailable()) |
|
70 signal->setText(tr("No Signal")); |
|
71 else |
|
72 signal->setText(tr("No radio found")); |
|
73 topBar->addWidget(signal); |
|
74 #if defined Q_WS_MAEMO_5 |
|
75 QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); |
|
76 topBar->addItem(spacer); |
|
77 volumeSlider = new QSlider(Qt::Horizontal,this); |
|
78 #else |
|
79 volumeSlider = new QSlider(Qt::Vertical,this); |
|
80 #endif |
|
81 volumeSlider->setRange(0,100); |
|
82 volumeSlider->setValue(50); |
|
83 connect(volumeSlider,SIGNAL(valueChanged(int)),this,SLOT(updateVolume(int))); |
|
84 topBar->addWidget(volumeSlider); |
|
85 |
|
86 layout->addLayout(buttonBar); |
|
87 #if defined Q_OS_SYMBIAN |
|
88 layout->addLayout(buttonBar2); |
|
89 #endif |
|
90 |
|
91 searchLeft = new QPushButton; |
|
92 searchLeft->setText(tr("scan Down")); |
|
93 connect(searchLeft,SIGNAL(clicked()),SLOT(searchDown())); |
|
94 buttonBar->addWidget(searchLeft); |
|
95 |
|
96 left = new QPushButton; |
|
97 left->setText(tr("Freq Down")); |
|
98 connect(left,SIGNAL(clicked()),SLOT(freqDown())); |
|
99 #if defined Q_OS_SYMBIAN |
|
100 buttonBar2->addWidget(left); |
|
101 #else |
|
102 buttonBar->addWidget(left); |
|
103 #endif |
|
104 |
|
105 right = new QPushButton; |
|
106 connect(right,SIGNAL(clicked()),SLOT(freqUp())); |
|
107 right->setText(tr("Freq Up")); |
|
108 #if defined Q_OS_SYMBIAN |
|
109 buttonBar2->addWidget(right); |
|
110 #else |
|
111 buttonBar->addWidget(right); |
|
112 #endif |
|
113 |
|
114 searchRight = new QPushButton; |
|
115 searchRight->setText(tr("scan Up")); |
|
116 connect(searchRight,SIGNAL(clicked()),SLOT(searchUp())); |
|
117 buttonBar->addWidget(searchRight); |
|
118 |
|
119 window->setLayout(layout); |
|
120 setCentralWidget(window); |
|
121 window->show(); |
|
122 |
|
123 radio->start(); |
|
124 } |
|
125 |
|
126 Radio::~Radio() |
|
127 { |
|
128 } |
|
129 |
|
130 void Radio::freqUp() |
|
131 { |
|
132 int f = radio->frequency(); |
|
133 f = f + radio->frequencyStep(QRadioTuner::FM); |
|
134 radio->setFrequency(f); |
|
135 } |
|
136 |
|
137 void Radio::freqDown() |
|
138 { |
|
139 int f = radio->frequency(); |
|
140 f = f - radio->frequencyStep(QRadioTuner::FM); |
|
141 radio->setFrequency(f); |
|
142 } |
|
143 |
|
144 void Radio::searchUp() |
|
145 { |
|
146 radio->searchForward(); |
|
147 } |
|
148 |
|
149 void Radio::searchDown() |
|
150 { |
|
151 radio->searchBackward(); |
|
152 } |
|
153 |
|
154 void Radio::freqChanged(int) |
|
155 { |
|
156 freq->setText(QString("%1 kHz").arg(radio->frequency()/1000)); |
|
157 } |
|
158 |
|
159 void Radio::signalChanged(int) |
|
160 { |
|
161 if(radio->signalStrength() > 25) |
|
162 signal->setText(tr("Got Signal")); |
|
163 else |
|
164 signal->setText(tr("No Signal")); |
|
165 } |
|
166 |
|
167 void Radio::updateVolume(int v) |
|
168 { |
|
169 radio->setVolume(v); |
|
170 } |
|
171 |