[e8cdcd]: plugins / gui-standard-display / radioview_frequencyseeker.cpp  Maximize  Restore  History

Download this file

257 lines (203 with data), 7.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/***************************************************************************
radioview_frequencyseeker.cpp - description
-------------------
begin : Fre Jun 20 2003
copyright : (C) 2003 by Martin Witte
email : emw-kradio@nocabal.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <math.h>
#include <QtGui/QLayout>
#include <QtGui/QSlider>
#include <QtGui/QToolButton>
// #include <QtGui/QAccel>
#include <kiconloader.h>
#include <klocale.h>
#include <kicon.h>
#include "radioview_frequencyseeker.h"
RadioViewFrequencySeeker::RadioViewFrequencySeeker(QWidget *parent, const QString &name)
: RadioViewElement(parent, name, clsRadioSeek),
m_btnSearchLeft(NULL),
m_btnStepLeft(NULL),
m_btnStepRight(NULL),
m_btnSearchRight(NULL),
m_sldFrequency(NULL),
m_ignoreChanges(false),
m_accelLeft(parent),
m_accelRight(parent)
{
QHBoxLayout *l = new QHBoxLayout(this);
l->setSpacing(1);
l->setMargin(0);
m_sldFrequency = new QSlider(Qt::Horizontal, this);
m_btnSearchLeft = new QToolButton(this);
m_btnSearchRight = new QToolButton(this);
m_btnStepLeft = new QToolButton(this);
m_btnStepRight = new QToolButton(this);
m_btnSearchLeft ->setCheckable(true);
m_btnSearchRight->setCheckable(true);
m_sldFrequency ->setPageStep(1);
m_btnSearchLeft ->setIcon(KIcon("media-skip-backward"));
m_btnSearchRight->setIcon(KIcon("media-skip-forward"));
m_btnStepLeft ->setIcon(KIcon("media-seek-backward"));
m_btnStepRight ->setIcon(KIcon("media-seek-forward"));
l->addWidget (m_btnSearchLeft);
l->addWidget (m_btnStepLeft);
l->addWidget (m_sldFrequency);
l->addWidget (m_btnStepRight);
l->addWidget (m_btnSearchRight);
QObject::connect(m_sldFrequency, SIGNAL(valueChanged(int)),
this, SLOT(slotSliderChanged(int)));
QObject::connect(m_btnSearchLeft, SIGNAL(toggled(bool)),
this, SLOT(slotSearchLeft(bool)));
QObject::connect(m_btnSearchRight, SIGNAL(toggled(bool)),
this, SLOT(slotSearchRight(bool)));
QObject::connect(m_btnStepLeft, SIGNAL(clicked()),
this, SLOT(slotStepDown()));
QObject::connect(m_btnStepRight, SIGNAL(clicked()),
this, SLOT(slotStepUp()));
// Tooltips
m_btnSearchLeft ->setToolTip(i18n("Search for previous radio station"));
m_btnSearchRight->setToolTip(i18n("Search for next radio station"));
m_btnStepLeft ->setToolTip(i18n("Decrement frequency"));
m_btnStepRight ->setToolTip(i18n("Increment frequency"));
m_sldFrequency ->setToolTip(i18n("Change frequency"));
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
}
RadioViewFrequencySeeker::~RadioViewFrequencySeeker()
{
}
float RadioViewFrequencySeeker::getUsability (Interface *i) const
{
if (dynamic_cast<IFrequencyRadio*>(i))
return 0.9;
else
return 0.0;
}
// Interface
bool RadioViewFrequencySeeker::connectI (Interface *i)
{
if (IFrequencyRadioClient::connectI(i)) {
ISeekRadioClient::connectI(i);
return true;
} else {
return false;
}
}
bool RadioViewFrequencySeeker::disconnectI(Interface *i)
{
bool a = IFrequencyRadioClient::disconnectI(i);
bool b = ISeekRadioClient::disconnectI(i);
return a || b;
}
// ISeekRadioClient
bool RadioViewFrequencySeeker::noticeSeekStarted (bool up)
{
m_ignoreChanges = true;
m_btnSearchLeft->setChecked(!up);
m_btnSearchRight->setChecked(up);
m_ignoreChanges = false;
return true;
}
bool RadioViewFrequencySeeker::noticeSeekStopped ()
{
m_ignoreChanges = true;
m_btnSearchLeft->setChecked(false);
m_btnSearchRight->setChecked(false);
m_ignoreChanges = false;
return true;
}
bool RadioViewFrequencySeeker::noticeSeekFinished (const RadioStation &/*s*/, bool /*goodQuality*/)
{
m_ignoreChanges = true;
m_btnSearchLeft->setChecked(false);
m_btnSearchRight->setChecked(false);
m_ignoreChanges = false;
return true;
}
// IFrequencyRadioClient
bool RadioViewFrequencySeeker::noticeFrequencyChanged(float f, const FrequencyRadioStation */*s*/)
{
float step = queryScanStep();
if (step == 0) step = 0.000001;
m_ignoreChanges = true;
m_sldFrequency->setValue((int)rint(f / step));
m_ignoreChanges = false;
return true;
}
bool RadioViewFrequencySeeker::noticeMinMaxFrequencyChanged(float min, float max)
{
float step = queryScanStep();
if (step == 0) step = 0.000001;
m_ignoreChanges = true;
m_sldFrequency->setMinimum((int)rint(min / step));
m_sldFrequency->setMaximum((int)rint(max / step));
m_sldFrequency->setValue ((int)rint(queryFrequency() / step));
m_ignoreChanges = false;
return true;
}
bool RadioViewFrequencySeeker::noticeDeviceMinMaxFrequencyChanged(float /*min*/, float /*max*/)
{
return false; // we don't care
}
bool RadioViewFrequencySeeker::noticeScanStepChanged(float s)
{
if (s == 0) s = 0.000001;
m_ignoreChanges = true;
m_sldFrequency->setMinimum((int)rint(queryMinFrequency() / s));
m_sldFrequency->setMaximum((int)rint(queryMaxFrequency() / s));
m_sldFrequency->setValue ((int)rint(queryFrequency() / s));
m_ignoreChanges = false;
return true;
}
void RadioViewFrequencySeeker::slotSearchLeft(bool on)
{
if (m_ignoreChanges) return;
if (on) {
if (queryIsSeekUpRunning())
sendStopSeek();
if (!queryIsSeekRunning())
sendStartSeekDown();
} else {
if (queryIsSeekDownRunning())
sendStopSeek();
}
if (!queryIsSeekDownRunning())
m_btnSearchLeft->setChecked(false);
}
void RadioViewFrequencySeeker::slotSearchRight(bool on)
{
if (m_ignoreChanges) return;
if (on) {
if (queryIsSeekDownRunning())
sendStopSeek();
if (!queryIsSeekRunning())
sendStartSeekUp();
} else {
if (queryIsSeekUpRunning())
sendStopSeek();
}
if (!queryIsSeekUpRunning())
m_btnSearchRight->setChecked(false);
}
void RadioViewFrequencySeeker::slotSliderChanged(int val)
{
if (m_ignoreChanges) return;
sendFrequency(val * queryScanStep());
}
void RadioViewFrequencySeeker::slotStepUp()
{
m_sldFrequency->triggerAction(QAbstractSlider::SliderSingleStepAdd);
}
void RadioViewFrequencySeeker::slotStepDown()
{
m_sldFrequency->triggerAction(QAbstractSlider::SliderSingleStepSub);
}
#include "radioview_frequencyseeker.moc"