kwave  18.07.70
Kwave::BitrateSpinBox Class Reference

#include <BitrateSpinBox.h>

Inheritance diagram for Kwave::BitrateSpinBox:
Inheritance graph
Collaboration diagram for Kwave::BitrateSpinBox:
Collaboration graph

Public Slots

virtual void snapIn (int value)
 

Signals

void snappedIn (int bitrate)
 

Public Member Functions

 BitrateSpinBox (QWidget *parent)
 
virtual ~BitrateSpinBox ()
 
virtual void allowRates (const QList< int > &list)
 

Protected Member Functions

int nearestIndex (int rate)
 

Private Attributes

QList< int > m_rates
 

Detailed Description

Definition at line 30 of file BitrateSpinBox.h.

Constructor & Destructor Documentation

◆ BitrateSpinBox()

Kwave::BitrateSpinBox::BitrateSpinBox ( QWidget *  parent)
explicit

Constructor

Definition at line 27 of file BitrateSpinBox.cpp.

References Kwave::connect(), m_rates, and snapIn().

28  :QSpinBox(parent), m_rates()
29 {
30  m_rates.append(0); // don't let it stay empty, that makes life easier
31 
32  connect(this, SIGNAL(valueChanged(int)),
33  this, SLOT(snapIn(int)));
34 }
virtual void snapIn(int value)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
Here is the call graph for this function:

◆ ~BitrateSpinBox()

Kwave::BitrateSpinBox::~BitrateSpinBox ( )
virtual

Destructor

Definition at line 37 of file BitrateSpinBox.cpp.

38 {
39 }

Member Function Documentation

◆ allowRates()

void Kwave::BitrateSpinBox::allowRates ( const QList< int > &  list)
virtual

sets a list of allowed bitrates

Definition at line 64 of file BitrateSpinBox.cpp.

References m_rates.

65 {
66  int old_value = value();
67 
68  m_rates = list;
69  if (m_rates.isEmpty()) m_rates.append(0);
70 
71  // set new ranges
72  setMinimum(m_rates.first());
73  setMaximum(m_rates.last());
74 
75  setValue(old_value);
76 }

◆ nearestIndex()

int Kwave::BitrateSpinBox::nearestIndex ( int  rate)
protected

find the nearest bitrate index of a current position

Definition at line 79 of file BitrateSpinBox.cpp.

References m_rates, and Kwave::toInt().

Referenced by snapIn().

80 {
81  // find the nearest value
82  int nearest = 0;
83  foreach(int i, m_rates)
84  if (qAbs(i - rate) < qAbs(nearest - rate)) nearest = i;
85 
86  // find the index
87  int index = m_rates.contains(nearest) ? m_rates.indexOf(nearest) : 0;
88 
89  // limit the index into a reasonable range
90  if (index < 0)
91  index = 0;
92  if (index >= Kwave::toInt(m_rates.size()))
93  index = m_rates.size()-1;
94 
95  return index;
96 }
int toInt(T x)
Definition: Utils.h:127
Here is the call graph for this function:
Here is the caller graph for this function:

◆ snapIn

void Kwave::BitrateSpinBox::snapIn ( int  value)
virtualslot

snaps in to a new value

Definition at line 42 of file BitrateSpinBox.cpp.

References m_rates, nearestIndex(), snappedIn(), and Kwave::toInt().

Referenced by BitrateSpinBox().

43 {
44  int index = nearestIndex(value);
45  int old_index = index;
46  int old_value = m_rates[index];
47 
48  if (value == old_value) return;
49 
50  if ((value > old_value) && (index < Kwave::toInt(m_rates.size()) - 1))
51  index++;
52 
53  if ((value < old_value) && (index > 0))
54  index--;
55 
56  if (index != old_index) {
57  int v = m_rates[index];
58  setValue(v);
59  emit snappedIn(v);
60  }
61 }
void snappedIn(int bitrate)
int nearestIndex(int rate)
int toInt(T x)
Definition: Utils.h:127
Here is the call graph for this function:
Here is the caller graph for this function:

◆ snappedIn

void Kwave::BitrateSpinBox::snappedIn ( int  bitrate)
signal

emitted when the value changed and snapped in to a bitrate

Referenced by snapIn().

Here is the caller graph for this function:

Member Data Documentation

◆ m_rates

QList<int> Kwave::BitrateSpinBox::m_rates
private

list of allowed bitrates, sorted ascending

Definition at line 61 of file BitrateSpinBox.h.

Referenced by allowRates(), BitrateSpinBox(), nearestIndex(), and snapIn().


The documentation for this class was generated from the following files: