Audacity 3.2.0
ShareAudioToolbar.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 ShareAudioToolbar.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#include "ShareAudioToolbar.h"
12
13#include <wx/sizer.h>
14#include <wx/stattext.h>
15
16#include <algorithm>
17
18#if wxUSE_TOOLTIPS
19#include <wx/tooltip.h>
20#endif
21
22#include "AColor.h"
23#include "AllThemeResources.h"
24#include "AudioIOBase.h"
25#include "ExportUtils.h"
26#include "PlayableTrack.h"
27#include "Prefs.h"
28#include "ProjectWindow.h"
29#include "Theme.h"
30
33#include "widgets/AButton.h"
34
36
37namespace audacity::cloud
38{
40{
41 return wxT("Share Audio");
42}
43
45 : ToolBar(project, XO("Share Audio"), ID())
46{
47}
48
50{
51}
52
54{
55 auto& toolManager = ToolManager::Get(project);
56 return *static_cast<ShareAudioToolbar*>(
57 toolManager.GetToolBar(ID()));
58}
59
61{
62 return Get(const_cast<AudacityProject&>(project));
63}
64
65void ShareAudioToolbar::Create(wxWindow* parent)
66{
67 ToolBar::Create(parent);
68
69 // Simulate a size event to set initial meter placement/size
70 wxSizeEvent event(GetSize(), GetId());
71 event.SetEventObject(this);
72 GetEventHandler()->ProcessEvent(event);
73}
74
76{
77#if wxUSE_TOOLTIPS
78 for (long iWinID = ID_SHARE_AUDIO_BUTTON; iWinID < BUTTON_COUNT; iWinID++)
79 {
80 auto pCtrl = static_cast<AButton*>(this->FindWindow(iWinID));
82 switch (iWinID)
83 {
85 name = ID();
86 break;
87 }
88
89 std::vector<ComponentInterfaceSymbol> commands(
90 1u, { name, Verbatim(pCtrl->GetLabel()) });
91
93 mProject, *pCtrl, commands.data(), commands.size());
94 }
95#endif
96}
97
99{
101 SetBackgroundColour(theTheme.Colour(clrMedium));
103
104#if wxUSE_TOOLTIPS
106 wxToolTip::Enable(true);
107 wxToolTip::SetDelay(1000);
108#endif
109
110 // Set default order and mode
112}
113
115{
116 // this was used to add a bevel and can be removed
117}
118
120{
121 auto gAudioIO = AudioIOBase::Get();
122
123 const bool audioStreamActive = gAudioIO &&
124 gAudioIO->IsStreamActive() && !gAudioIO->IsMonitoring();
125
126 bool hasAudio = false;
127
128 for (const auto& track : TrackList::Get(mProject).Any<PlayableTrack>())
129 {
130 if (track->GetStartTime() != track->GetEndTime())
131 {
132 hasAudio = true;
133 break;
134 }
135 }
136
137 mShareAudioButton->SetEnabled(hasAudio && !audioStreamActive);
138}
139
141{
143
145
147}
148
150{
151 const auto height = (toolbarSingle - toolbarMargin) * 2;
152
154 //i18n-hint: Share audio button text, keep as short as possible
155 mShareAudioButton->SetLabel(XO("Share Audio"));
158 theTheme.Image(bmpRecoloredUpSmall),
159 theTheme.Image(bmpRecoloredUpHiliteSmall),
160 theTheme.Image(bmpRecoloredDownSmall),
161 theTheme.Image(bmpRecoloredHiliteSmall),
162 theTheme.Image(bmpRecoloredUpSmall));
163 mShareAudioButton->SetIcon(theTheme.Image(bmpShareAudio));
164 mShareAudioButton->SetForegroundColour(theTheme.Colour(clrTrackPanelText));
165
166 mShareAudioButton->Bind(wxEVT_BUTTON, [this](auto) {
170 dlg.ShowModal();
171
173 });
174 mShareAudioButton->SetMinSize(wxSize{-1, height});
175 mShareAudioButton->SetMaxSize(wxSize{-1, height});
176}
177
179{
180 Add(mShareAudioButton, 0, wxALIGN_CENTRE | wxALL, toolbarSpacing);
181
182 SetMinSize({ std::max(76, GetSizer()->GetMinSize().GetWidth()), -1 });
183 SetMaxSize({ -1, -1 });
184
185 // Layout the toolbar
186 Layout();
187}
188
192};
193
194namespace
195{
197 /* i18n-hint: Clicking this menu item shows the toolbar
198 that opens Share Audio dialog */
199 ShareAudioToolbar::ID(), wxT("ShareAudioTB"), XXO("&Share Audio Toolbar")
200};
201}
202
203} // namespace audacity::cloud
wxT("CloseDown"))
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
Extends Track with notions of mute and solo setting.
IMPLEMENT_CLASS(audacity::cloud::ShareAudioToolbar, ToolBar)
wxString name
Definition: TagsEditor.cpp:166
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
static constexpr auto toolbarSpacing
Preferred spacing between inner toolbar elements.
Definition: ToolBar.h:57
static constexpr auto toolbarSingle
Height of a single line toolbar.
Definition: ToolBar.h:53
static constexpr auto toolbarMargin
Preferred inner toolbar margin.
Definition: ToolBar.h:55
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
void SetButtonType(Type type)
Definition: AButton.cpp:148
void SetImages(const wxImage &up, const wxImage &over, const wxImage &down, const wxImage &overDown, const wxImage &dis)
Definition: AButton.cpp:221
void PopUp()
Definition: AButton.cpp:672
@ FrameTextVButton
Definition: AButton.h:115
void SetEnabled(bool state)
Definition: AButton.h:201
void SetIcon(const wxImage &icon)
Definition: AButton.cpp:242
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:205
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:94
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:260
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
static ProjectWindow & Get(AudacityProject &project)
wxColour & Colour(int iIndex)
wxImage & Image(int iIndex)
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:73
AudacityProject & mProject
Definition: ToolBar.h:247
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:709
virtual void ReCreateButtons()
Definition: ToolBar.cpp:533
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:819
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:701
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:77
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:934
static ToolManager & Get(AudacityProject &project)
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
ShareAudioToolbar(AudacityProject &project)
void Create(wxWindow *parent) override
static ShareAudioToolbar & Get(AudacityProject &project)
static RegisteredToolbarFactory factory