Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
TrackPanelResizeHandle Class Referencefinal

Constructed from one channel, but changes height of all channels in a track. More...

#include <TrackPanelResizeHandle.h>

Inheritance diagram for TrackPanelResizeHandle:
[legend]
Collaboration diagram for TrackPanelResizeHandle:
[legend]

Public Member Functions

 TrackPanelResizeHandle (const std::shared_ptr< Channel > &pChannel, int y)
 
TrackPanelResizeHandleoperator= (const TrackPanelResizeHandle &)=default
 
virtual ~TrackPanelResizeHandle ()
 
std::shared_ptr< const ChannelFindChannel () const override
 
std::shared_ptr< ChannelFindChannel ()
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual void Enter (bool forward, AudacityProject *pProject)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape (AudacityProject *pProject) const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool HandlesRightClick ()
 Whether the handle has any special right-button handling. More...
 
virtual Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject)=0
 
virtual Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
 
virtual Result Cancel (AudacityProject *pProject)=0
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
virtual std::shared_ptr< const ChannelFindChannel () const =0
 
virtual bool IsDragging () const
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 
virtual void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
 
virtual wxRect DrawingArea (TrackPanelDrawingContext &context, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
 

Static Public Member Functions

static HitTestPreview HitPreview (bool bLinked)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
- Static Public Member Functions inherited from TrackPanelDrawable
static wxRect MaximizeWidth (const wxRect &rect, const wxRect &panelRect)
 
static wxRect MaximizeHeight (const wxRect &rect, const wxRect &panelRect)
 

Private Types

enum  Mode { IsResizing , IsResizingBetweenLinkedTracks , IsResizingBelowLinkedTracks }
 

Private Member Functions

 TrackPanelResizeHandle (const TrackPanelResizeHandle &)=delete
 
ChannelPrevChannel (Channel &channel)
 
ChannelNextChannel (Channel &channel)
 

Static Private Member Functions

static TrackGetTrack (Channel &channel)
 

Private Attributes

Mode mMode { IsResizing }
 
std::weak_ptr< ChannelmwChannel
 
bool mInitialMinimized {}
 
int mInitialTrackHeight {}
 
int mInitialExpandedHeight {}
 
int mInitialUpperTrackHeight {}
 
int mInitialUpperExpandedHeight {}
 
int mMouseClickY {}
 

Additional Inherited Members

- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Constructed from one channel, but changes height of all channels in a track.

Definition at line 20 of file TrackPanelResizeHandle.h.

Member Enumeration Documentation

◆ Mode

Enumerator
IsResizing 
IsResizingBetweenLinkedTracks 
IsResizingBelowLinkedTracks 

Definition at line 60 of file TrackPanelResizeHandle.h.

Constructor & Destructor Documentation

◆ TrackPanelResizeHandle() [1/2]

TrackPanelResizeHandle::TrackPanelResizeHandle ( const TrackPanelResizeHandle )
privatedelete

◆ TrackPanelResizeHandle() [2/2]

TrackPanelResizeHandle::TrackPanelResizeHandle ( const std::shared_ptr< Channel > &  pChannel,
int  y 
)
Precondition
pChannel != nullptr

Definition at line 96 of file TrackPanelResizeHandle.cpp.

98 : mwChannel{ pChannel }
99 , mMouseClickY( y )
100{
101 // TODO: more-than-two-channels
102
103 //STM: Determine whether we should rescale one or two tracks
104 auto channels = GetTrack(*pChannel).Channels();
105 auto last = *channels.rbegin();
106 auto &lastView = ChannelView::Get(*last);
107 mInitialTrackHeight = lastView.GetHeight();
108 mInitialExpandedHeight = lastView.GetExpandedHeight();
109 mInitialMinimized = lastView.GetMinimized();
110
111 if (channels.size() > 1) {
112 auto first = *channels.begin();
113 auto &firstView = ChannelView::Get(*first);
114
115 mInitialUpperTrackHeight = firstView.GetHeight();
116 mInitialUpperExpandedHeight = firstView.GetExpandedHeight();
117
118 if (pChannel == *channels.rbegin())
119 // pChannel is lowest among two or more,
120 // so there is a previous channel
122 else
123 // pChannel is not the lowest among two or more,
124 // so there is a next channel
126 }
127 else
128 // Don't assume there is a next or previous channel
130}
IteratorRange< ChannelIterator< ChannelType > > Channels()
Get range of channels with mutative access.
Definition: Channel.h:408
static ChannelView & Get(Channel &channel)
std::weak_ptr< Channel > mwChannel
static Track & GetTrack(Channel &channel)

References ChannelGroup::Channels(), ChannelView::Get(), GetTrack(), IsResizing, IsResizingBelowLinkedTracks, IsResizingBetweenLinkedTracks, mInitialExpandedHeight, mInitialMinimized, mInitialTrackHeight, mInitialUpperExpandedHeight, mInitialUpperTrackHeight, and mMode.

Here is the call graph for this function:

◆ ~TrackPanelResizeHandle()

TrackPanelResizeHandle::~TrackPanelResizeHandle ( )
virtual

Definition at line 52 of file TrackPanelResizeHandle.cpp.

53{
54}

Member Function Documentation

◆ Cancel()

UIHandle::Result TrackPanelResizeHandle::Cancel ( AudacityProject pProject)
overridevirtual

Implements UIHandle.

Definition at line 290 of file TrackPanelResizeHandle.cpp.

291{
292 auto &tracks = TrackList::Get( *pProject );
293 auto theChannel = FindChannel();
294 if (!theChannel)
296
297
298 switch (mMode) {
299 case IsResizing:
300 {
301 auto &view = ChannelView::Get(*theChannel);
302 view.SetExpandedHeight(mInitialExpandedHeight);
303 view.SetMinimized( mInitialMinimized );
304 }
305 break;
307 {
308 // Assume next channel is present, see constructor
309 const auto next = NextChannel(*theChannel);
310 auto &view = ChannelView::Get(*theChannel),
311 &nextView = ChannelView::Get(*next);
312 view.SetExpandedHeight(mInitialUpperExpandedHeight);
313 view.SetMinimized( mInitialMinimized );
314 nextView.SetExpandedHeight(mInitialExpandedHeight);
315 nextView.SetMinimized( mInitialMinimized );
316 }
317 break;
319 {
320 // Assume previous channel is present, see constructor
321 const auto prev = PrevChannel(*theChannel);
322 auto &view = ChannelView::Get(*theChannel),
323 &prevView = ChannelView::Get(*prev);
324 view.SetExpandedHeight(mInitialExpandedHeight);
325 view.SetMinimized( mInitialMinimized );
326 prevView.SetExpandedHeight(mInitialUpperExpandedHeight);
327 prevView.SetMinimized(mInitialMinimized);
328 }
329 break;
330 }
331
333}
const auto tracks
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
Channel * PrevChannel(Channel &channel)
std::shared_ptr< const Channel > FindChannel() const override
Channel * NextChannel(Channel &channel)

References RefreshCode::Cancelled, FindChannel(), TrackList::Get(), ChannelView::Get(), IsResizing, IsResizingBelowLinkedTracks, IsResizingBetweenLinkedTracks, mInitialExpandedHeight, mInitialMinimized, mInitialUpperExpandedHeight, mMode, NextChannel(), PrevChannel(), RefreshCode::RefreshAll, and tracks.

Here is the call graph for this function:

◆ Click()

UIHandle::Result TrackPanelResizeHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 66 of file TrackPanelResizeHandle.cpp.

68{
69 using namespace RefreshCode;
70 if (evt.event.LeftDClick() && mMode == IsResizingBetweenLinkedTracks) {
71 auto &tracks = TrackList::Get(*pProject);
72 auto theChannel = FindChannel();
73 if (!theChannel)
74 return RefreshNone;
75 auto &view = ChannelView::Get(*theChannel);
76 if (!view.GetMinimized()) {
77 auto range = GetTrack(*theChannel).Channels();
78 auto size = range.size();
79 auto height = range.sum( [](auto pChannel){
80 return ChannelView::Get(*pChannel).GetHeight(); } );
81 int ii = 1;
82 int coord = 0;
83 for (const auto pChannel : range) {
84 int newCoord = ((double)ii++ /size) * height;
85 ChannelView::Get(*pChannel).SetExpandedHeight(newCoord - coord);
86 coord = newCoord;
87 }
88 ProjectHistory::Get( *pProject ).ModifyState(false);
89 // Do not start a drag
90 return Cancelled | RefreshAll;
91 }
92 }
93 return RefreshNone;
94}
int GetHeight() const
void SetExpandedHeight(int height)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16

References Cancelled, ChannelGroup::Channels(), TrackPanelMouseEvent::event, FindChannel(), ProjectHistory::Get(), TrackList::Get(), ChannelView::Get(), ChannelView::GetHeight(), GetTrack(), IsResizingBetweenLinkedTracks, mMode, ProjectHistory::ModifyState(), RefreshCode::RefreshAll, RefreshCode::RefreshNone, ChannelView::SetExpandedHeight(), size, and tracks.

Here is the call graph for this function:

◆ Drag()

UIHandle::Result TrackPanelResizeHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 148 of file TrackPanelResizeHandle.cpp.

150{
151 auto &tracks = TrackList::Get( *pProject );
152 auto theChannel = FindChannel();
153 if (!theChannel)
155
156 auto &view = ChannelView::Get(*theChannel);
157
158 const wxMouseEvent &event = evt.event;
159
160 int delta = (event.m_y - mMouseClickY);
161
162 // On first drag, jump out of minimized mode. Initial height
163 // will be height of minimized track.
164 //
165 // This used to be in HandleResizeClick(), but simply clicking
166 // on a resize border would switch the minimized state.
167 if (view.GetMinimized()) {
168 auto channels = GetTrack(*theChannel).Channels();
169 for (auto pChannel : channels) {
170 auto &channelView = ChannelView::Get(*pChannel);
171 channelView.SetExpandedHeight(channelView.GetHeight());
172 channelView.SetMinimized(false);
173 }
174
175 if (channels.size() > 1) {
176 // Initial values must be reset since they weren't based on the
177 // minimized heights.
178 auto &channelView = ChannelView::Get(**channels.begin());
179 mInitialUpperTrackHeight = channelView.GetHeight();
180 mInitialTrackHeight = channelView.GetHeight();
181 }
182 }
183
184 // Common pieces of code for MONO_WAVE_PAN and otherwise.
185 auto doResizeBelow = [&] (Channel *prev) {
186 // TODO: more-than-two-channels
187
188 auto &prevView = ChannelView::Get(*prev);
189
190 double proportion = static_cast < double >(mInitialTrackHeight)
192
193 int newTrackHeight = static_cast < int >
194 (mInitialTrackHeight + delta * proportion);
195
196 int newUpperTrackHeight = static_cast < int >
197 (mInitialUpperTrackHeight + delta * (1.0 - proportion));
198
199 //make sure neither track is smaller than its minimum height
200 if (newTrackHeight < view.GetMinimizedHeight())
201 newTrackHeight = view.GetMinimizedHeight();
202 if (newUpperTrackHeight < prevView.GetMinimizedHeight())
203 newUpperTrackHeight = prevView.GetMinimizedHeight();
204
205 view.SetExpandedHeight(newTrackHeight);
206 prevView.SetExpandedHeight(newUpperTrackHeight);
207 };
208
209 auto doResizeBetween = [&] (Channel *next) {
210 // TODO: more-than-two-channels
211
212 auto &nextView = ChannelView::Get(*next);
213 int newUpperTrackHeight = mInitialUpperTrackHeight + delta;
214 int newTrackHeight = mInitialTrackHeight - delta;
215
216 // make sure neither track is smaller than its minimum height
217 if (newTrackHeight < nextView.GetMinimizedHeight()) {
218 newTrackHeight = nextView.GetMinimizedHeight();
219 newUpperTrackHeight =
220 mInitialUpperTrackHeight + mInitialTrackHeight - nextView.GetMinimizedHeight();
221 }
222 if (newUpperTrackHeight < view.GetMinimizedHeight()) {
223 newUpperTrackHeight = view.GetMinimizedHeight();
224 newTrackHeight =
225 mInitialUpperTrackHeight + mInitialTrackHeight - view.GetMinimizedHeight();
226 }
227
228 view.SetExpandedHeight(newUpperTrackHeight);
229 nextView.SetExpandedHeight(newTrackHeight);
230 };
231
232 auto doResize = [&] {
233 int newTrackHeight = mInitialTrackHeight + delta;
234 if (newTrackHeight < view.GetMinimizedHeight())
235 newTrackHeight = view.GetMinimizedHeight();
236 view.SetExpandedHeight(newTrackHeight);
237 };
238
239 //STM: We may be dragging one or two (stereo) tracks.
240 // If two, resize proportionally if we are dragging the lower track, and
241 // adjust compensatively if we are dragging the upper track.
242
243 switch( mMode )
244 {
246 {
247 // Assume previous channel is present, see constructor
248 doResizeBelow(PrevChannel(*theChannel));
249 break;
250 }
252 {
253 // Assume next channel is present, see constructor
254 doResizeBetween(NextChannel(*theChannel));
255 break;
256 }
257 case IsResizing:
258 {
259 doResize();
260 break;
261 }
262 default:
263 // don't refresh in this case.
265 }
266
268}

References RefreshCode::Cancelled, ChannelGroup::Channels(), TrackPanelMouseEvent::event, FindChannel(), TrackList::Get(), ChannelView::Get(), GetTrack(), IsResizing, IsResizingBelowLinkedTracks, IsResizingBetweenLinkedTracks, mInitialTrackHeight, mInitialUpperTrackHeight, mMode, mMouseClickY, NextChannel(), PrevChannel(), RefreshCode::RefreshAll, RefreshCode::RefreshNone, and tracks.

Here is the call graph for this function:

◆ FindChannel() [1/2]

std::shared_ptr< Channel > TrackPanelResizeHandle::FindChannel ( )

Definition at line 61 of file TrackPanelResizeHandle.cpp.

62{
63 return mwChannel.lock();
64}

References mwChannel.

◆ FindChannel() [2/2]

std::shared_ptr< const Channel > TrackPanelResizeHandle::FindChannel ( ) const
overridevirtual
Returns
pointer to associated channel, if any

Implements UIHandle.

Definition at line 56 of file TrackPanelResizeHandle.cpp.

57{
58 return mwChannel.lock();
59}

References mwChannel.

Referenced by Cancel(), Click(), and Drag().

Here is the caller graph for this function:

◆ GetTrack()

Track & TrackPanelResizeHandle::GetTrack ( Channel channel)
staticprivate

Definition at line 335 of file TrackPanelResizeHandle.cpp.

336{
337 // TODO wide wave tracks -- just return channel.GetTrack()
338 // But until then, Track::Channels() will not iterate all channels when
339 // given a right hand track
340 // So be sure to substitute the leader
341 const auto pTrack = static_cast<Track*>(&channel.GetChannelGroup());
342 return **TrackList::Channels(pTrack).begin();
343}
ChannelGroup & GetChannelGroup()
Channel object's lifetime is assumed to be nested in its Track's.
Definition: Channel.cpp:71
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1164

References TrackList::Channels(), and Channel::GetChannelGroup().

Referenced by Click(), Drag(), NextChannel(), PrevChannel(), and TrackPanelResizeHandle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HitPreview()

HitTestPreview TrackPanelResizeHandle::HitPreview ( bool  bLinked)
static

When in the resize area we can adjust size or relative size.

Definition at line 25 of file TrackPanelResizeHandle.cpp.

26{
27 // TODO: more-than-two-channels-message
28
29 static wxCursor resizeCursor{ wxCURSOR_SIZENS };
30
32 // Check to see whether it is the first channel of a stereo track
33 if (bLinked) {
34 // If we are in the label we got here 'by mistake' and we're
35 // not actually in the resize area at all. (The resize area
36 // is shorter when it is between stereo tracks).
37
38 return {
39 XO(
40"Click and drag to adjust relative size of stereo tracks, double-click to make heights equal"),
41 &resizeCursor
42 };
43 }
44 else {
45 return {
46 XO("Click and drag to resize the track."),
47 &resizeCursor
48 };
49 }
50}
XO("Cut/Copy/Paste")

References XO().

Referenced by Preview().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextChannel()

Channel * TrackPanelResizeHandle::NextChannel ( Channel channel)
private

Definition at line 140 of file TrackPanelResizeHandle.cpp.

141{
142 // Assume channel is first of two
143 // TODO: more-than-two-channels
144 auto channels = GetTrack(channel).Channels();
145 return &**channels.rbegin();
146}

References ChannelGroup::Channels(), and GetTrack().

Referenced by Cancel(), and Drag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

TrackPanelResizeHandle & TrackPanelResizeHandle::operator= ( const TrackPanelResizeHandle )
default

◆ PrevChannel()

Channel * TrackPanelResizeHandle::PrevChannel ( Channel channel)
private

Definition at line 132 of file TrackPanelResizeHandle.cpp.

133{
134 // Assume channel is last of two
135 // TODO: more-than-two-channels
136 auto channels = GetTrack(channel).Channels();
137 return &**channels.begin();
138}

References ChannelGroup::Channels(), and GetTrack().

Referenced by Cancel(), and Drag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Preview()

HitTestPreview TrackPanelResizeHandle::Preview ( const TrackPanelMouseState state,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 270 of file TrackPanelResizeHandle.cpp.

272{
274}
static HitTestPreview HitPreview(bool bLinked)

References HitPreview(), IsResizingBetweenLinkedTracks, and mMode.

Here is the call graph for this function:

◆ Release()

UIHandle::Result TrackPanelResizeHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

This happens when the button is released from a drag. Since we actually took care of resizing the track when we got drag events, all we have to do here is clean up. We also modify the undo state (the action doesn't become undo-able, but it gets merged with the previous undo-able event).

Implements UIHandle.

Definition at line 276 of file TrackPanelResizeHandle.cpp.

279{
286 ProjectHistory::Get( *pProject ).ModifyState(false);
288}

References RefreshCode::FixScrollbars, ProjectHistory::Get(), and ProjectHistory::ModifyState().

Here is the call graph for this function:

Member Data Documentation

◆ mInitialExpandedHeight

int TrackPanelResizeHandle::mInitialExpandedHeight {}
private

Definition at line 71 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), and TrackPanelResizeHandle().

◆ mInitialMinimized

bool TrackPanelResizeHandle::mInitialMinimized {}
private

Definition at line 69 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), and TrackPanelResizeHandle().

◆ mInitialTrackHeight

int TrackPanelResizeHandle::mInitialTrackHeight {}
private

Definition at line 70 of file TrackPanelResizeHandle.h.

Referenced by Drag(), and TrackPanelResizeHandle().

◆ mInitialUpperExpandedHeight

int TrackPanelResizeHandle::mInitialUpperExpandedHeight {}
private

Definition at line 73 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), and TrackPanelResizeHandle().

◆ mInitialUpperTrackHeight

int TrackPanelResizeHandle::mInitialUpperTrackHeight {}
private

Definition at line 72 of file TrackPanelResizeHandle.h.

Referenced by Drag(), and TrackPanelResizeHandle().

◆ mMode

Mode TrackPanelResizeHandle::mMode { IsResizing }
private

Definition at line 65 of file TrackPanelResizeHandle.h.

Referenced by Cancel(), Click(), Drag(), Preview(), and TrackPanelResizeHandle().

◆ mMouseClickY

int TrackPanelResizeHandle::mMouseClickY {}
private

Definition at line 75 of file TrackPanelResizeHandle.h.

Referenced by Drag().

◆ mwChannel

std::weak_ptr<Channel> TrackPanelResizeHandle::mwChannel
private

Definition at line 67 of file TrackPanelResizeHandle.h.

Referenced by FindChannel().


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