File: CompressionWidget.cpp

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (282 lines) | stat: -rw-r--r-- 9,986 bytes parent folder | download
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/***************************************************************************
  CompressionWidget.cpp  -  widget for setting ogg or mp3 compression rates
                             -------------------
    begin                : Sat Jun 14 2003
    copyright            : (C) 2002 by Thomas Eschenbacher
    email                : Thomas.Eschenbacher@gmx.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 "config.h"

#include <QCheckBox>
#include <QLabel>
#include <QList>
#include <QObject>
#include <QRadioButton>
#include <QSlider>
#include <QSpinBox>
#include <QToolTip>
#include <QWhatsThis>

#include <KLocalizedString>

#include "libkwave/StandardBitrates.h"
#include "libkwave/String.h"
#include "libkwave/Utils.h"

#include "BitrateWidget.h"
#include "CompressionWidget.h"

//***************************************************************************
Kwave::CompressionWidget::CompressionWidget(QWidget *parent)
    :QWidget(parent), Ui::CompressionWidgetBase()
{
    setupUi(this);

    // use well-known bitrates from MP3
    const Kwave::StandardBitrates &rates = Kwave::StandardBitrates::instance();
    abrBitrate->allowRates(rates);
    abrHighestBitrate->allowRates(rates);
    abrLowestBitrate->allowRates(rates);

    connect(rbABR, SIGNAL(toggled(bool)),
            this,  SLOT(selectABR(bool)));
    connect(chkLowestBitrate, SIGNAL(toggled(bool)),
            this,  SLOT(lowestToggled(bool)));
    connect(chkHighestBitrate, SIGNAL(toggled(bool)),
            this,  SLOT(highestToggled(bool)));
    connect(abrBitrate, SIGNAL(valueChanged(int)),
            this, SLOT(abrChanged(int)));
    connect(abrLowestBitrate, SIGNAL(valueChanged(int)),
            this, SLOT(lowestChanged(int)));
    connect(abrHighestBitrate, SIGNAL(valueChanged(int)),
            this, SLOT(highestChanged(int)));

    enableABR(false, false, false);
    enableVBR(false);
}

//***************************************************************************
Kwave::CompressionWidget::~CompressionWidget()
{
}

//***************************************************************************
void Kwave::CompressionWidget::init(Kwave::FileInfo &info)
{
    initInfo(lblCompressionNominalBitrate, abrBitrate,
             Kwave::INF_BITRATE_NOMINAL, info);
    initInfo(nullptr, abrHighestBitrate,
             Kwave::INF_BITRATE_UPPER, info);
    initInfo(nullptr, abrLowestBitrate,
             Kwave::INF_BITRATE_LOWER, info);
    initInfo(lblCompressionBaseQuality, sbBaseQuality,
             Kwave::INF_VBR_QUALITY, info);
    initInfo(nullptr, slBaseQuality,
             Kwave::INF_VBR_QUALITY, info);
}

//***************************************************************************
void Kwave::CompressionWidget::describeWidget(QWidget *widget,
                                              const QString &name,
                                              const QString &description)
{
    if (!widget) return;
    widget->setToolTip(description);
    widget->setWhatsThis(_("<b>") + name + _("</b><br>") + description);
}

//***************************************************************************
void Kwave::CompressionWidget::initInfo(QLabel *label, QWidget *widget,
                                        Kwave::FileProperty property,
                                        Kwave::FileInfo &info)
{
    Q_ASSERT(widget);
    if (label) label->setText(i18n(info.name(property).toLatin1().constData()) + _(":"));
    describeWidget(widget, i18n(info.name(property).toLatin1().constData()),
                   i18n(info.description(property).toLatin1().constData()));
}

//***************************************************************************
void Kwave::CompressionWidget::enableABR(bool enable, bool lowest, bool highest)
{
    rbABR->setEnabled(enable);
    if (!enable) rbABR->setChecked(false);

    const bool on = (rbABR->isChecked() && enable);
    lblCompressionNominalBitrate->setEnabled(on);
    abrBitrate->setEnabled(on);
    abrHighestBitrate->setEnabled(on);
    abrLowestBitrate->setEnabled(on);
    chkHighestBitrate->setEnabled(on);
    chkLowestBitrate->setEnabled(on);

    chkLowestBitrate->setChecked(lowest);
    chkHighestBitrate->setChecked(highest);
}

//***************************************************************************
void Kwave::CompressionWidget::enableVBR(bool enable)
{
    rbVBR->setEnabled(enable);
    if (!enable) rbVBR->setChecked(false);

    const bool on = (rbVBR->isChecked() && enable);
    lblCompressionBaseQuality->setEnabled(on);
    sbBaseQuality->setEnabled(on);
    slBaseQuality->setEnabled(on);

}

//***************************************************************************
void Kwave::CompressionWidget::selectABR(bool checked)
{
    abrHighestBitrate->setEnabled(checked && chkHighestBitrate->isChecked());
    abrLowestBitrate->setEnabled( checked && chkLowestBitrate->isChecked());
}

//***************************************************************************
void Kwave::CompressionWidget::lowestToggled(bool on)
{
    if (on) {
        // if previous state was off: transition off->on
        // make sure that the lowest ABR is below the current ABR
        int abr = abrBitrate->value();
        if (abrLowestBitrate->value() > abr)
            abrLowestBitrate->setValue(abr);
    }
    abrLowestBitrate->setEnabled(chkLowestBitrate->isEnabled() && on);
}


//***************************************************************************
void Kwave::CompressionWidget::highestToggled(bool on)
{
    if (on) {
        // if previous state was off: transition off->on
        // make sure that the highest ABR is above the current ABR
        int abr = abrBitrate->value();
        if (abrHighestBitrate->value() < abr)
            abrHighestBitrate->setValue(abr);
    }
    abrHighestBitrate->setEnabled(chkHighestBitrate->isEnabled() && on);
}


//***************************************************************************
void Kwave::CompressionWidget::abrChanged(int value)
{
    if (value < abrLowestBitrate->value())
        abrLowestBitrate->setValue(value);
    if (value > abrHighestBitrate->value())
        abrHighestBitrate->setValue(value);
}

//***************************************************************************
void Kwave::CompressionWidget::lowestChanged(int value)
{
    if (value > abrBitrate->value())
        abrBitrate->setValue(value);
    if (value > abrHighestBitrate->value())
        abrHighestBitrate->setValue(value);
}

//***************************************************************************
void Kwave::CompressionWidget::highestChanged(int value)
{
    if (value < abrLowestBitrate->value())
        abrLowestBitrate->setValue(value);
    if (value < abrBitrate->value())
        abrBitrate->setValue(value);
}

//***************************************************************************
void Kwave::CompressionWidget::setBitrates(int nominal, int lower, int upper)
{
    abrLowestBitrate->setValue(lower);
    abrHighestBitrate->setValue(upper);
    abrBitrate->setValue(nominal);
}

//***************************************************************************
void Kwave::CompressionWidget::setQuality(int quality)
{
    sbBaseQuality->setValue(quality);
}

//***************************************************************************
Kwave::CompressionWidget::Mode Kwave::CompressionWidget::mode()
{
    return (rbABR->isChecked()) ? ABR_MODE : VBR_MODE;
}

//***************************************************************************
void Kwave::CompressionWidget::setMode(Kwave::CompressionWidget::Mode mode)
{
    bool abr = rbABR->isEnabled();
    bool vbr = rbVBR->isEnabled();
    switch (mode) {
        case ABR_MODE:
            rbVBR->setChecked(false);
            rbVBR->setChecked(true);
            rbVBR->setChecked(false);

            rbABR->setChecked(true);
            rbABR->setChecked(false);
            rbABR->setChecked(true);
            rbABR->setChecked(abr);
            break;
        case VBR_MODE:
            rbABR->setChecked(false);
            rbABR->setChecked(true);
            rbABR->setChecked(false);

            rbVBR->setChecked(true);
            rbVBR->setChecked(false);
            rbVBR->setChecked(true);
            rbVBR->setChecked(vbr);
            break;
        DEFAULT_IMPOSSIBLE;
    }
}

//***************************************************************************
bool Kwave::CompressionWidget::lowestEnabled()
{
    return chkLowestBitrate->isChecked();
}

//***************************************************************************
bool Kwave::CompressionWidget::highestEnabled()
{
    return chkHighestBitrate->isChecked();
}

//***************************************************************************
void Kwave::CompressionWidget::getABRrates(int &nominal,
                                           int &lowest, int &highest)
{
    nominal = abrBitrate->value();
    lowest  = abrLowestBitrate->value();
    highest = abrHighestBitrate->value();
}

//***************************************************************************
int Kwave::CompressionWidget::baseQuality()
{
    return sbBaseQuality->value();
}

//***************************************************************************
//***************************************************************************

#include "moc_CompressionWidget.cpp"