Audacity 3.2.0
LabelTrackControls.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5LabelTrackControls.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
12#include "LabelTrackControls.h"
13
14#include "LabelTrackView.h"
15#include "../../../HitTestResult.h"
16#include "LabelTrack.h"
17#include "../../../widgets/PopupMenuTable.h"
18#include "Prefs.h"
19#include "../../../RefreshCode.h"
20#include "ShuttleGui.h"
21#include "wxPanelWrapper.h"
22#include <wx/fontenum.h>
23#include <wx/listbox.h>
24#include <wx/spinctrl.h>
25
27{
28}
29
30std::vector<UIHandlePtr> LabelTrackControls::HitTest
31(const TrackPanelMouseState & state,
32 const AudacityProject *pProject)
33{
34 return CommonTrackControls::HitTest(state, pProject);
35}
36
38{
40 : PopupMenuTable{ "LabelTrack" }
41 {}
43
44public:
46
47 void InitUserData(void *pUserData) override
48 {
49 mpData = static_cast<CommonTrackControls::InitMenuData*>(pUserData);
50 }
51
53
54 void OnSetFont(wxCommandEvent &);
55};
56
58{
59 static LabelTrackMenuTable instance;
60 return instance;
61}
62
63enum
64{
65 OnSetFontID = 30000,
66};
67
69 BeginSection( "Basic" );
70 AppendItem( "Font", OnSetFontID, XXO("&Font..."), POPUP_MENU_FN( OnSetFont ) );
73
74void LabelTrackMenuTable::OnSetFont(wxCommandEvent &)
75{
76 // Small helper class to enumerate all fonts in the system
77 // We use this because the default implementation of
78 // wxFontEnumerator::GetFacenames() has changed between wx2.6 and 2.8
79 class FontEnumerator : public wxFontEnumerator
80 {
81 public:
82 explicit FontEnumerator(wxArrayString* fontNames) :
83 mFontNames(fontNames) {}
84
85 bool OnFacename(const wxString& font) override
86 {
87 mFontNames->push_back(font);
88 return true;
89 }
90
91 private:
92 wxArrayString* mFontNames;
93 };
94
95 wxArrayString facenames;
96 FontEnumerator fontEnumerator(&facenames);
97 fontEnumerator.EnumerateFacenames(wxFONTENCODING_SYSTEM, false);
98
99 wxString facename = gPrefs->Read(wxT("/GUI/LabelFontFacename"), wxT(""));
100
101 // Correct for empty facename, or bad preference file:
102 // get the name of a really existing font, to highlight by default
103 // in the list box
104 facename = LabelTrackView::GetFont(facename).GetFaceName();
105
106 long fontsize = gPrefs->Read(wxT("/GUI/LabelFontSize"),
107 static_cast<int>(LabelTrackView::DefaultFontSize));
108
109 /* i18n-hint: (noun) This is the font for the label track.*/
110 wxDialogWrapper dlg(mpData->pParent, wxID_ANY, XO("Label Track Font"));
111 dlg.SetName();
112 ShuttleGui S(&dlg, eIsCreating);
113 wxListBox *lb;
114 wxSpinCtrl *sc;
115
116 S.StartVerticalLay(true);
117 {
118 S.StartMultiColumn(2, wxEXPAND);
119 {
120 S.SetStretchyRow(0);
121 S.SetStretchyCol(1);
122
123 /* i18n-hint: (noun) The name of the typeface*/
124 S.AddPrompt(XXO("Face name"));
125 lb = safenew wxListBox(S.GetParent(), wxID_ANY,
126 wxDefaultPosition,
127 wxDefaultSize,
128 facenames,
129 wxLB_SINGLE);
130
131 lb->SetSelection( make_iterator_range( facenames ).index( facename ));
132 S
133 .Name(XO("Face name"))
134 .Position( wxALIGN_LEFT | wxEXPAND | wxALL )
135 .AddWindow(lb);
136
137 /* i18n-hint: (noun) The size of the typeface*/
138 S.AddPrompt(XXO("Face size"));
139 sc = safenew wxSpinCtrl(S.GetParent(), wxID_ANY,
140 wxString::Format(wxT("%ld"), fontsize),
141 wxDefaultPosition,
142 wxDefaultSize,
143 wxSP_ARROW_KEYS,
144 8, 48, fontsize);
145 S
146 .Name(XO("Face size"))
147 .Position( wxALIGN_LEFT | wxALL )
148 .AddWindow(sc);
149 }
150 S.EndMultiColumn();
151 S.AddStandardButtons();
152 }
153 S.EndVerticalLay();
154
155 dlg.Layout();
156 dlg.Fit();
157 dlg.CenterOnParent();
158 if (dlg.ShowModal() == wxID_CANCEL)
159 return;
160
161 gPrefs->Write(wxT("/GUI/LabelFontFacename"), lb->GetStringSelection());
162 gPrefs->Write(wxT("/GUI/LabelFontSize"), sc->GetValue());
163 gPrefs->Flush();
164
166
167 mpData->result = RefreshCode::RefreshAll;
168}
169
171{
173}
174
177 return [](LabelTrack &track) {
178 return std::make_shared<LabelTrackControls>( track.SharedPointer() );
179 };
180}
181
184 return [](LabelTrack &) {
185 // Label tracks are narrow
186 // Default is to allow two rows so that NEW users get the
187 // idea that labels can 'stack' when they would overlap.
188 return 73;
189 };
190}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: IteratorX.h:210
EndSection()
DEFINE_ATTACHED_VIRTUAL_OVERRIDE(DoGetLabelTrackControls)
AppendItem("Font", OnSetFontID, XXO("&Font..."), POPUP_MENU_FN(OnSetFont))
BeginSection("Basic")
@ OnSetFontID
#define safenew
Definition: MemoryX.h:10
#define END_POPUP_MENU()
#define BEGIN_POPUP_MENU(HandlerClass)
#define POPUP_MENU_FN(memFn)
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
@ eIsCreating
Definition: ShuttleGui.h:37
#define S(N)
Definition: ToChars.cpp:64
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
virtual std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override=0
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
PopupMenuTable * GetMenuExtension(Track *pTrack) override
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:98
DECLARE_POPUP_MENU(LabelTrackMenuTable)
void OnSetFont(wxCommandEvent &)
void InitUserData(void *pUserData) override
Called before the menu items are appended.
static LabelTrackMenuTable & Instance()
CommonTrackControls::InitMenuData * mpData
static wxFont GetFont(const wxString &faceName, int size=DefaultFontSize)
static void ResetFont()
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
virtual bool Read(const wxString &key, bool *value) const =0
void SetName(const TranslatableString &title)
For defining overrides of the method.