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