kwave  18.07.70
CompressionWidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  CompressionWidget.cpp - widget for setting ogg or mp3 compression rates
3  -------------------
4  begin : Sat Jun 14 2003
5  copyright : (C) 2002 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include <QCheckBox>
21 #include <QLabel>
22 #include <QList>
23 #include <QObject>
24 #include <QRadioButton>
25 #include <QSlider>
26 #include <QSpinBox>
27 #include <QToolTip>
28 #include <QWhatsThis>
29 
30 #include <KLocalizedString>
31 
33 #include "libkwave/String.h"
34 
35 #include "BitrateWidget.h"
36 #include "CompressionWidget.h"
37 
38 //***************************************************************************
40  :QWidget(parent), Ui::CompressionWidgetBase()
41 {
42  setupUi(this);
43 
44  // use well-known bitrates from MP3
46  abrBitrate->allowRates(rates);
47  abrHighestBitrate->allowRates(rates);
48  abrLowestBitrate->allowRates(rates);
49 
50  connect(rbABR, SIGNAL(toggled(bool)),
51  this, SLOT(selectABR(bool)));
52  connect(chkLowestBitrate, SIGNAL(toggled(bool)),
53  this, SLOT(lowestToggled(bool)));
54  connect(chkHighestBitrate, SIGNAL(toggled(bool)),
55  this, SLOT(highestToggled(bool)));
56  connect(abrBitrate, SIGNAL(valueChanged(int)),
57  this, SLOT(abrChanged(int)));
58  connect(abrLowestBitrate, SIGNAL(valueChanged(int)),
59  this, SLOT(lowestChanged(int)));
60  connect(abrHighestBitrate, SIGNAL(valueChanged(int)),
61  this, SLOT(highestChanged(int)));
62 
63  enableABR(false, false, false);
64  enableVBR(false);
65 }
66 
67 //***************************************************************************
69 {
70 }
71 
72 //***************************************************************************
74 {
75  initInfo(lblCompressionNominalBitrate, abrBitrate,
77  initInfo(Q_NULLPTR, abrHighestBitrate,
79  initInfo(Q_NULLPTR, abrLowestBitrate,
81  initInfo(lblCompressionBaseQuality, sbBaseQuality,
83  initInfo(Q_NULLPTR, slBaseQuality,
85 }
86 
87 //***************************************************************************
89  const QString &name,
90  const QString &description)
91 {
92  if (!widget) return;
93  widget->setToolTip(description);
94  widget->setWhatsThis(_("<b>") + name + _("</b><br>") + description);
95 }
96 
97 //***************************************************************************
98 void Kwave::CompressionWidget::initInfo(QLabel *label, QWidget *widget,
99  Kwave::FileProperty property,
100  Kwave::FileInfo &info)
101 {
102  Q_ASSERT(widget);
103  if (label) label->setText(i18n(info.name(property).toLatin1()) + _(":"));
104  describeWidget(widget, i18n(info.name(property).toLatin1()),
105  i18n(info.description(property).toLatin1()));
106 }
107 
108 //***************************************************************************
109 void Kwave::CompressionWidget::enableABR(bool enable, bool lowest, bool highest)
110 {
111  rbABR->setEnabled(enable);
112  if (!enable) rbABR->setChecked(false);
113 
114  const bool on = (rbABR->isChecked() && enable);
115  lblCompressionNominalBitrate->setEnabled(on);
116  abrBitrate->setEnabled(on);
117  abrHighestBitrate->setEnabled(on);
118  abrLowestBitrate->setEnabled(on);
119  chkHighestBitrate->setEnabled(on);
120  chkLowestBitrate->setEnabled(on);
121 
122  chkLowestBitrate->setChecked(lowest);
123  chkHighestBitrate->setChecked(highest);
124 }
125 
126 //***************************************************************************
128 {
129  rbVBR->setEnabled(enable);
130  if (!enable) rbVBR->setChecked(false);
131 
132  const bool on = (rbVBR->isChecked() && enable);
133  lblCompressionBaseQuality->setEnabled(on);
134  sbBaseQuality->setEnabled(on);
135  slBaseQuality->setEnabled(on);
136 
137 }
138 
139 //***************************************************************************
141 {
142  abrHighestBitrate->setEnabled(checked && chkHighestBitrate->isChecked());
143  abrLowestBitrate->setEnabled( checked && chkLowestBitrate->isChecked());
144 }
145 
146 //***************************************************************************
148 {
149  if (on) {
150  // if previous state was off: transition off->on
151  // make sure that the lowest ABR is below the current ABR
152  int abr = abrBitrate->value();
153  if (abrLowestBitrate->value() > abr)
154  abrLowestBitrate->setValue(abr);
155  }
156  abrLowestBitrate->setEnabled(chkLowestBitrate->isEnabled() && on);
157 }
158 
159 
160 //***************************************************************************
162 {
163  if (on) {
164  // if previous state was off: transition off->on
165  // make sure that the highest ABR is above the current ABR
166  int abr = abrBitrate->value();
167  if (abrHighestBitrate->value() < abr)
168  abrHighestBitrate->setValue(abr);
169  }
170  abrHighestBitrate->setEnabled(chkHighestBitrate->isEnabled() && on);
171 }
172 
173 
174 //***************************************************************************
176 {
177  if (value < abrLowestBitrate->value())
178  abrLowestBitrate->setValue(value);
179  if (value > abrHighestBitrate->value())
180  abrHighestBitrate->setValue(value);
181 }
182 
183 //***************************************************************************
185 {
186  if (value > abrBitrate->value())
187  abrBitrate->setValue(value);
188  if (value > abrHighestBitrate->value())
189  abrHighestBitrate->setValue(value);
190 }
191 
192 //***************************************************************************
194 {
195  if (value < abrLowestBitrate->value())
196  abrLowestBitrate->setValue(value);
197  if (value < abrBitrate->value())
198  abrBitrate->setValue(value);
199 }
200 
201 //***************************************************************************
202 void Kwave::CompressionWidget::setBitrates(int nominal, int lower, int upper)
203 {
204  abrLowestBitrate->setValue(lower);
205  abrHighestBitrate->setValue(upper);
206  abrBitrate->setValue(nominal);
207 }
208 
209 //***************************************************************************
211 {
212  sbBaseQuality->setValue(quality);
213 }
214 
215 //***************************************************************************
217 {
218  return (rbABR->isChecked()) ? ABR_MODE : VBR_MODE;
219 }
220 
221 //***************************************************************************
223 {
224  bool abr = rbABR->isEnabled();
225  bool vbr = rbVBR->isEnabled();
226  switch (mode) {
227  case ABR_MODE:
228  rbVBR->setChecked(false);
229  rbVBR->setChecked(true);
230  rbVBR->setChecked(false);
231 
232  rbABR->setChecked(true);
233  rbABR->setChecked(false);
234  rbABR->setChecked(true);
235  rbABR->setChecked(abr);
236  break;
237  case VBR_MODE:
238  rbABR->setChecked(false);
239  rbABR->setChecked(true);
240  rbABR->setChecked(false);
241 
242  rbVBR->setChecked(true);
243  rbVBR->setChecked(false);
244  rbVBR->setChecked(true);
245  rbVBR->setChecked(vbr);
246  break;
247  }
248 }
249 
250 //***************************************************************************
252 {
253  return chkLowestBitrate->isChecked();
254 }
255 
256 //***************************************************************************
258 {
259  return chkHighestBitrate->isChecked();
260 }
261 
262 //***************************************************************************
264  int &lowest, int &highest)
265 {
266  nominal = abrBitrate->value();
267  lowest = abrLowestBitrate->value();
268  highest = abrHighestBitrate->value();
269 }
270 
271 //***************************************************************************
273 {
274  return sbBaseQuality->value();
275 }
276 
277 //***************************************************************************
278 //***************************************************************************
virtual void lowestChanged(int value)
virtual void highestChanged(int value)
void describeWidget(QWidget *widget, const QString &name, const QString &description)
virtual void enableABR(bool enable, bool lowest, bool highest)
QString name(FileProperty key) const
Definition: FileInfo.h:227
virtual void setMode(Mode mode)
virtual void init(Kwave::FileInfo &info)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
const char name[16]
Definition: memcpy.c:510
QString description(FileProperty key) const
Definition: FileInfo.h:234
virtual void setBitrates(int nominal, int lower, int upper)
virtual void getABRrates(int &nominal, int &lowest, int &highest)
void initInfo(QLabel *label, QWidget *widget, Kwave::FileProperty property, Kwave::FileInfo &info)
virtual void selectABR(bool checked)
virtual void abrChanged(int value)
#define _(m)
Definition: memcpy.c:66
virtual void enableVBR(bool enable)
virtual void highestToggled(bool on)
CompressionWidget(QWidget *parent)
virtual void lowestToggled(bool on)
static const StandardBitrates & instance()
FileProperty
Definition: FileInfo.h:45
virtual void setQuality(int quality)