1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-19 09:30:52 +02:00

RulerPanel uses TranslatableString for units string...

... also fixing missed translation of "k" in spectrum vertical ruler
This commit is contained in:
Paul Licameli 2019-12-28 20:11:08 -05:00
parent 1887928fe2
commit 6e14d2e56c
9 changed files with 53 additions and 43 deletions

View File

@ -301,7 +301,7 @@ FrequencyPlotDialog::FrequencyPlotDialog(wxWindow * parent, wxWindowID id,
wxSize{ 100, 100 }, // Ruler can't handle small sizes wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ 0.0, -dBRange }, RulerPanel::Range{ 0.0, -dBRange },
Ruler::LinearDBFormat, Ruler::LinearDBFormat,
_("dB"), XO("dB"),
RulerPanel::Options{} RulerPanel::Options{}
.LabelEdges(true) .LabelEdges(true)
.TickColour( theTheme.Colour( clrGraphLabels ) ) .TickColour( theTheme.Colour( clrGraphLabels ) )
@ -384,7 +384,7 @@ FrequencyPlotDialog::FrequencyPlotDialog(wxWindow * parent, wxWindowID id,
wxSize{ 100, 100 }, // Ruler can't handle small sizes wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ 10, 20000 }, RulerPanel::Range{ 10, 20000 },
Ruler::RealFormat, Ruler::RealFormat,
_("Hz"), XO("Hz"),
RulerPanel::Options{} RulerPanel::Options{}
.Log(true) .Log(true)
.Flip(true) .Flip(true)
@ -721,10 +721,10 @@ void FrequencyPlotDialog::DrawPlot()
// Set up y axis ruler // Set up y axis ruler
if (mAlg == SpectrumAnalyst::Spectrum) { if (mAlg == SpectrumAnalyst::Spectrum) {
vRuler->ruler.SetUnits(_("dB")); vRuler->ruler.SetUnits(XO("dB"));
vRuler->ruler.SetFormat(Ruler::LinearDBFormat); vRuler->ruler.SetFormat(Ruler::LinearDBFormat);
} else { } else {
vRuler->ruler.SetUnits(wxT("")); vRuler->ruler.SetUnits({});
vRuler->ruler.SetFormat(Ruler::RealFormat); vRuler->ruler.SetFormat(Ruler::RealFormat);
} }
int w1, w2, h; int w1, w2, h;
@ -767,13 +767,14 @@ void FrequencyPlotDialog::DrawPlot()
xStep = (xMax - xMin) / width; xStep = (xMax - xMin) / width;
hRuler->ruler.SetLog(false); hRuler->ruler.SetLog(false);
} }
hRuler->ruler.SetUnits(_("Hz")); hRuler->ruler.SetUnits(XO("Hz"));
} else { } else {
xMin = 0; xMin = 0;
xMax = mAnalyst->GetProcessedSize() / mRate; xMax = mAnalyst->GetProcessedSize() / mRate;
xStep = (xMax - xMin) / width; xStep = (xMax - xMin) / width;
hRuler->ruler.SetLog(false); hRuler->ruler.SetLog(false);
hRuler->ruler.SetUnits(_("s")); /* i18n-hint: short form of 'seconds'.*/
hRuler->ruler.SetUnits(XO("s"));
} }
hRuler->ruler.SetRange(xMin, xMax-xStep); hRuler->ruler.SetRange(xMin, xMax-xStep);
hRuler->Refresh(false); hRuler->Refresh(false);

View File

@ -716,7 +716,7 @@ void EffectCompressorPanel::OnPaint(wxPaintEvent & WXUNUSED(evt))
vRuler.SetOrientation(wxVERTICAL); vRuler.SetOrientation(wxVERTICAL);
vRuler.SetRange(0, -rangeDB); vRuler.SetRange(0, -rangeDB);
vRuler.SetFormat(Ruler::LinearDBFormat); vRuler.SetFormat(Ruler::LinearDBFormat);
vRuler.SetUnits(_("dB")); vRuler.SetUnits(XO("dB"));
vRuler.GetMaxSize(&w, NULL); vRuler.GetMaxSize(&w, NULL);
Ruler hRuler; Ruler hRuler;
@ -724,7 +724,7 @@ void EffectCompressorPanel::OnPaint(wxPaintEvent & WXUNUSED(evt))
hRuler.SetOrientation(wxHORIZONTAL); hRuler.SetOrientation(wxHORIZONTAL);
hRuler.SetRange(-rangeDB, 0); hRuler.SetRange(-rangeDB, 0);
hRuler.SetFormat(Ruler::LinearDBFormat); hRuler.SetFormat(Ruler::LinearDBFormat);
hRuler.SetUnits(_("dB")); hRuler.SetUnits(XO("dB"));
hRuler.SetFlip(true); hRuler.SetFlip(true);
hRuler.GetMaxSize(NULL, &h); hRuler.GetMaxSize(NULL, &h);

View File

@ -776,7 +776,7 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
wxSize{ 100, 100 }, // Ruler can't handle small sizes wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ 60.0, -120.0 }, RulerPanel::Range{ 60.0, -120.0 },
Ruler::LinearDBFormat, Ruler::LinearDBFormat,
_("dB"), XO("dB"),
RulerPanel::Options{} RulerPanel::Options{}
.LabelEdges(true) .LabelEdges(true)
.TicksAtExtremes(true) .TicksAtExtremes(true)
@ -833,7 +833,7 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
wxSize{ 100, 100 }, // Ruler can't handle small sizes wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ mLoFreq, mHiFreq }, RulerPanel::Range{ mLoFreq, mHiFreq },
Ruler::IntFormat, Ruler::IntFormat,
_("Hz"), XO("Hz"),
RulerPanel::Options{} RulerPanel::Options{}
.Log(true) .Log(true)
.Flip(true) .Flip(true)

View File

@ -380,7 +380,7 @@ void EffectScienFilter::PopulateOrExchange(ShuttleGui & S)
wxSize{ 100, 100 }, // Ruler can't handle small sizes wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ 30.0, -120.0 }, RulerPanel::Range{ 30.0, -120.0 },
Ruler::LinearDBFormat, Ruler::LinearDBFormat,
_("dB"), XO("dB"),
RulerPanel::Options{} RulerPanel::Options{}
.LabelEdges(true) .LabelEdges(true)
); );
@ -438,7 +438,7 @@ void EffectScienFilter::PopulateOrExchange(ShuttleGui & S)
wxSize{ 100, 100 }, // Ruler can't handle small sizes wxSize{ 100, 100 }, // Ruler can't handle small sizes
RulerPanel::Range{ mLoFreq, mNyquist }, RulerPanel::Range{ mLoFreq, mNyquist },
Ruler::IntFormat, Ruler::IntFormat,
wxT(""), {},
RulerPanel::Options{} RulerPanel::Options{}
.Log(true) .Log(true)
.Flip(true) .Flip(true)

View File

@ -162,12 +162,13 @@ void SpectrumVRulerControls::DoUpdateVRuler(
// use kHz in scale, if appropriate // use kHz in scale, if appropriate
if (maxFreq >= 2000) { if (maxFreq >= 2000) {
vruler->SetRange((maxFreq / 1000.), (minFreq / 1000.)); vruler->SetRange((maxFreq / 1000.), (minFreq / 1000.));
vruler->SetUnits(wxT("k")); /* i18n-hint k abbreviating kilo meaning thousands */
vruler->SetUnits(XO("k"));
} }
else { else {
// use Hz // use Hz
vruler->SetRange((int)(maxFreq), (int)(minFreq)); vruler->SetRange((int)(maxFreq), (int)(minFreq));
vruler->SetUnits(wxT("")); vruler->SetUnits({});
} }
vruler->SetLog(false); vruler->SetLog(false);
} }
@ -193,7 +194,7 @@ void SpectrumVRulerControls::DoUpdateVRuler(
vruler->SetFormat(Ruler::IntFormat); vruler->SetFormat(Ruler::IntFormat);
vruler->SetLabelEdges(true); vruler->SetLabelEdges(true);
vruler->SetRange(maxFreq, minFreq); vruler->SetRange(maxFreq, minFreq);
vruler->SetUnits(wxT("")); vruler->SetUnits({});
vruler->SetLog(true); vruler->SetLog(true);
NumberScale scale( NumberScale scale(
wt->GetSpectrogramSettings().GetScale( minFreq, maxFreq ) wt->GetSpectrogramSettings().GetScale( minFreq, maxFreq )

View File

@ -220,7 +220,7 @@ void WaveformVRulerControls::DoUpdateVRuler(
vruler->SetOrientation(wxVERTICAL); vruler->SetOrientation(wxVERTICAL);
vruler->SetRange(max, min); vruler->SetRange(max, min);
vruler->SetFormat(Ruler::RealFormat); vruler->SetFormat(Ruler::RealFormat);
vruler->SetUnits(wxT("")); vruler->SetUnits({});
vruler->SetLabelEdges(false); vruler->SetLabelEdges(false);
vruler->SetLog(false); vruler->SetLog(false);
} }
@ -228,7 +228,7 @@ void WaveformVRulerControls::DoUpdateVRuler(
wxASSERT(scaleType == WaveformSettings::stLogarithmic); wxASSERT(scaleType == WaveformSettings::stLogarithmic);
scaleType = WaveformSettings::stLogarithmic; scaleType = WaveformSettings::stLogarithmic;
vruler->SetUnits(wxT("")); vruler->SetUnits({});
float min, max; float min, max;
wt->GetDisplayBounds(&min, &max); wt->GetDisplayBounds(&min, &max);

View File

@ -90,7 +90,7 @@ void TimeTrackVRulerControls::UpdateRuler( const wxRect &rect )
vruler->SetOrientation(wxVERTICAL); vruler->SetOrientation(wxVERTICAL);
vruler->SetRange(max, min); vruler->SetRange(max, min);
vruler->SetFormat((tt->GetDisplayLog()) ? Ruler::RealLogFormat : Ruler::RealFormat); vruler->SetFormat((tt->GetDisplayLog()) ? Ruler::RealLogFormat : Ruler::RealFormat);
vruler->SetUnits(wxT("")); vruler->SetUnits({});
vruler->SetLabelEdges(false); vruler->SetLabelEdges(false);
vruler->SetLog(tt->GetDisplayLog()); vruler->SetLog(tt->GetDisplayLog());

View File

@ -166,7 +166,7 @@ void Ruler::SetLog(bool log)
} }
} }
void Ruler::SetUnits(const wxString &units) void Ruler::SetUnits(const TranslatableString &units)
{ {
// Specify the name of the units (like "dB") if you // Specify the name of the units (like "dB") if you
// want numbers like "1.6" formatted as "1.6 dB". // want numbers like "1.6" formatted as "1.6 dB".
@ -576,7 +576,7 @@ void Ruler::FindLinearTickSizes(double UPP)
} }
} }
wxString Ruler::LabelString(double d, bool major) TranslatableString Ruler::LabelString(double d, bool major)
{ {
// Given a value, turn it into a string according // Given a value, turn it into a string according
// to the current ruler format. The number of digits of // to the current ruler format. The number of digits of
@ -585,6 +585,9 @@ wxString Ruler::LabelString(double d, bool major)
wxString s; wxString s;
// PRL Todo: are all these cases properly localized? (Decimal points,
// hour-minute-second, etc.?)
// Replace -0 with 0 // Replace -0 with 0
if (d < 0.0 && (d+mMinor > 0.0) && ( mFormat != RealLogFormat )) if (d < 0.0 && (d+mMinor > 0.0) && ( mFormat != RealLogFormat ))
d = 0.0; d = 0.0;
@ -718,15 +721,15 @@ wxString Ruler::LabelString(double d, bool major)
} }
} }
auto result = Verbatim( s );
if (!mUnits.empty()) if (!mUnits.empty())
s = (s + mUnits); result += mUnits;
return s; return result;
} }
void Ruler::Tick(int pos, double d, bool major, bool minor) void Ruler::Tick(int pos, double d, bool major, bool minor)
{ {
wxString l;
wxCoord strW, strH, strD, strL; wxCoord strW, strH, strD, strL;
int strPos, strLen, strLeft, strTop; int strPos, strLen, strLeft, strTop;
@ -751,14 +754,14 @@ void Ruler::Tick(int pos, double d, bool major, bool minor)
label->pos = pos; label->pos = pos;
label->lx = mLeft - 1000; // don't display label->lx = mLeft - 1000; // don't display
label->ly = mTop - 1000; // don't display label->ly = mTop - 1000; // don't display
label->text = wxT(""); label->text = {};
mDC->SetFont(major? *mMajorFont: minor? *mMinorFont : *mMinorMinorFont); mDC->SetFont(major? *mMajorFont: minor? *mMinorFont : *mMinorMinorFont);
// Bug 521. dB view for waveforms needs a 2-sided scale. // Bug 521. dB view for waveforms needs a 2-sided scale.
if(( mDbMirrorValue > 1.0 ) && ( -d > mDbMirrorValue )) if(( mDbMirrorValue > 1.0 ) && ( -d > mDbMirrorValue ))
d = -2*mDbMirrorValue - d; d = -2*mDbMirrorValue - d;
l = LabelString(d, major); auto l = LabelString(d, major);
mDC->GetTextExtent(l, &strW, &strH, &strD, &strL); mDC->GetTextExtent(l.Translation(), &strW, &strH, &strD, &strL);
if (mOrientation == wxHORIZONTAL) { if (mOrientation == wxHORIZONTAL) {
strLen = strW; strLen = strW;
@ -842,7 +845,6 @@ void Ruler::TickCustom(int labelIdx, bool major, bool minor)
// be optimized. // be optimized.
int pos; int pos;
wxString l;
wxCoord strW, strH, strD, strL; wxCoord strW, strH, strD, strL;
int strPos, strLen, strLeft, strTop; int strPos, strLen, strLeft, strTop;
@ -863,13 +865,13 @@ void Ruler::TickCustom(int labelIdx, bool major, bool minor)
label->value = 0.0; label->value = 0.0;
pos = label->pos; // already stored in label class pos = label->pos; // already stored in label class
l = label->text; auto l = label->text;
label->lx = mLeft - 1000; // don't display label->lx = mLeft - 1000; // don't display
label->ly = mTop - 1000; // don't display label->ly = mTop - 1000; // don't display
mDC->SetFont(major? *mMajorFont: minor? *mMinorFont : *mMinorMinorFont); mDC->SetFont(major? *mMajorFont: minor? *mMinorFont : *mMinorMinorFont);
mDC->GetTextExtent(l, &strW, &strH, &strD, &strL); mDC->GetTextExtent(l.Translation(), &strW, &strH, &strD, &strL);
if (mOrientation == wxHORIZONTAL) { if (mOrientation == wxHORIZONTAL) {
strLen = strW; strLen = strW;
@ -1170,7 +1172,7 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
// mNumMinor = 0; // mNumMinor = 0;
// Nowadays we just drop the labels. // Nowadays we just drop the labels.
for(i=0; i<mNumMinor; i++) for(i=0; i<mNumMinor; i++)
mMinorLabels[i].text = ""; mMinorLabels[i].text = {};
} }
// Left and Right Edges // Left and Right Edges
@ -1541,25 +1543,29 @@ void Ruler::GetMaxSize(wxCoord *width, wxCoord *height)
void Ruler::SetCustomMode(bool value) { mCustom = value; } void Ruler::SetCustomMode(bool value) { mCustom = value; }
void Ruler::SetCustomMajorLabels(wxArrayString *label, size_t numLabel, int start, int step) void Ruler::SetCustomMajorLabels(
const TranslatableStrings &labels, int start, int step)
{ {
const auto numLabel = labels.size();
mNumMajor = numLabel; mNumMajor = numLabel;
mMajorLabels.reinit(numLabel); mMajorLabels.reinit(numLabel);
for(size_t i = 0; i<numLabel; i++) { for(size_t i = 0; i<numLabel; i++) {
mMajorLabels[i].text = (*label)[i]; mMajorLabels[i].text = labels[i];
mMajorLabels[i].pos = start + i*step; mMajorLabels[i].pos = start + i*step;
} }
//Remember: DELETE majorlabels.... //Remember: DELETE majorlabels....
} }
void Ruler::SetCustomMinorLabels(wxArrayString *label, size_t numLabel, int start, int step) void Ruler::SetCustomMinorLabels(
const TranslatableStrings &labels, int start, int step)
{ {
const auto numLabel = labels.size();
mNumMinor = numLabel; mNumMinor = numLabel;
mMinorLabels.reinit(numLabel); mMinorLabels.reinit(numLabel);
for(size_t i = 0; i<numLabel; i++) { for(size_t i = 0; i<numLabel; i++) {
mMinorLabels[i].text = (*label)[i]; mMinorLabels[i].text = labels[i];
mMinorLabels[i].pos = start + i*step; mMinorLabels[i].pos = start + i*step;
} }
//Remember: DELETE majorlabels.... //Remember: DELETE majorlabels....
@ -1576,7 +1582,7 @@ void Ruler::Label::Draw(wxDC&dc, bool twoTone, wxColour c) const
dc.SetTextForeground(altColor ? *wxBLUE : *wxBLACK); dc.SetTextForeground(altColor ? *wxBLUE : *wxBLACK);
#endif #endif
dc.DrawText(text, lx, ly); dc.DrawText(text.Translation(), lx, ly);
} }
} }
@ -1603,7 +1609,7 @@ RulerPanel::RulerPanel(wxWindow* parent, wxWindowID id,
const wxSize &bounds, const wxSize &bounds,
const Range &range, const Range &range,
Ruler::RulerFormat format, Ruler::RulerFormat format,
const wxString &units, const TranslatableString &units,
const Options &options, const Options &options,
const wxPoint& pos /*= wxDefaultPosition*/, const wxPoint& pos /*= wxDefaultPosition*/,
const wxSize& size /*= wxDefaultSize*/): const wxSize& size /*= wxDefaultSize*/):

View File

@ -75,7 +75,7 @@ class AUDACITY_DLL_API Ruler {
// Specify the name of the units (like "dB") if you // Specify the name of the units (like "dB") if you
// want numbers like "1.6" formatted as "1.6 dB". // want numbers like "1.6" formatted as "1.6 dB".
void SetUnits(const wxString &units); void SetUnits(const TranslatableString &units);
void SetDbMirrorValue( const double d ){ mDbMirrorValue = d ; }; void SetDbMirrorValue( const double d ){ mDbMirrorValue = d ; };
// Logarithmic // Logarithmic
@ -125,8 +125,10 @@ class AUDACITY_DLL_API Ruler {
// If this is the case, you should provide a wxString array of labels, start // If this is the case, you should provide a wxString array of labels, start
// label position, and labels step. The range eventually specified will be // label position, and labels step. The range eventually specified will be
// ignored. // ignored.
void SetCustomMajorLabels(wxArrayString *label, size_t numLabel, int start, int step); void SetCustomMajorLabels(
void SetCustomMinorLabels(wxArrayString *label, size_t numLabel, int start, int step); const TranslatableStrings &labels, int start, int step);
void SetCustomMinorLabels(
const TranslatableStrings &labels, int start, int step);
void SetUseZoomInfo(int leftOffset, const ZoomInfo *zoomInfo); void SetUseZoomInfo(int leftOffset, const ZoomInfo *zoomInfo);
@ -154,7 +156,7 @@ class AUDACITY_DLL_API Ruler {
void Update(const Envelope* envelope); void Update(const Envelope* envelope);
void FindTickSizes(); void FindTickSizes();
void FindLinearTickSizes(double UPP); void FindLinearTickSizes(double UPP);
wxString LabelString(double d, bool major); TranslatableString LabelString(double d, bool major);
void Tick(int pos, double d, bool major, bool minor); void Tick(int pos, double d, bool major, bool minor);
@ -198,7 +200,7 @@ private:
double value; double value;
int pos; int pos;
int lx, ly; int lx, ly;
wxString text; TranslatableString text;
void Draw(wxDC &dc, bool twoTone, wxColour c) const; void Draw(wxDC &dc, bool twoTone, wxColour c) const;
}; };
@ -230,7 +232,7 @@ private:
bool mMajorGrid; // for grid drawing bool mMajorGrid; // for grid drawing
bool mMinorGrid; // . bool mMinorGrid; // .
int mGridLineLength; // end int mGridLineLength; // end
wxString mUnits; TranslatableString mUnits;
bool mTwoTone; bool mTwoTone;
const ZoomInfo *mUseZoomInfo; const ZoomInfo *mUseZoomInfo;
int mLeftOffset; int mLeftOffset;
@ -275,7 +277,7 @@ class AUDACITY_DLL_API RulerPanel final : public wxPanelWrapper {
const wxSize &bounds, const wxSize &bounds,
const Range &range, const Range &range,
Ruler::RulerFormat format, Ruler::RulerFormat format,
const wxString &units, const TranslatableString &units,
const Options &options = {}, const Options &options = {},
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize); const wxSize& size = wxDefaultSize);