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

#include <TrackSelectHandle.h>

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

Public Member Functions

 TrackSelectHandle (const std::shared_ptr< Track > &pTrack)
 
TrackSelectHandleoperator= (const TrackSelectHandle &)=default
 
virtual ~TrackSelectHandle ()
 
std::shared_ptr< const TrackFindTrack () const override
 
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 *) override
 
bool StopsOnKeystroke () 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 TrackFindTrack () 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 UIHandlePtr HitAnywhere (std::weak_ptr< TrackSelectHandle > &holder, const std::shared_ptr< Track > &pTrack)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
static std::shared_ptr< const TrackTrackFromChannel (const std::shared_ptr< const Channel > &pChannel)
 A frequent convenience in the definition of UIHandles. More...
 
- 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 Member Functions

 TrackSelectHandle (const TrackSelectHandle &)=delete
 
void CalculateRearrangingThresholds (const wxMouseEvent &event, AudacityProject *project)
 

Private Attributes

std::shared_ptr< TrackmpTrack
 
bool mClicked {}
 
int mMoveUpThreshold {}
 
int mMoveDownThreshold {}
 
int mRearrangeCount {}
 

Additional Inherited Members

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

Detailed Description

Definition at line 19 of file TrackSelectHandle.h.

Constructor & Destructor Documentation

◆ TrackSelectHandle() [1/2]

TrackSelectHandle::TrackSelectHandle ( const TrackSelectHandle )
privatedelete

◆ TrackSelectHandle() [2/2]

TrackSelectHandle::TrackSelectHandle ( const std::shared_ptr< Track > &  pTrack)
explicit

Definition at line 51 of file TrackSelectHandle.cpp.

52 : mpTrack( pTrack )
53{}
std::shared_ptr< Track > mpTrack

◆ ~TrackSelectHandle()

TrackSelectHandle::~TrackSelectHandle ( )
virtual

Definition at line 64 of file TrackSelectHandle.cpp.

65{
66}

Member Function Documentation

◆ CalculateRearrangingThresholds()

void TrackSelectHandle::CalculateRearrangingThresholds ( const wxMouseEvent &  event,
AudacityProject project 
)
private

Figure out how far the user must drag the mouse up or down before the track will swap with the one above or below

Definition at line 224 of file TrackSelectHandle.cpp.

226{
227 // JH: this will probably need to be tweaked a bit, I'm just
228 // not sure what formula will have the best feel for the
229 // user.
230
231 auto &tracks = TrackList::Get( *project );
232
233 if (mpTrack && tracks.CanMoveUp(*mpTrack))
235 event.m_y -
237 * -- tracks.Find(mpTrack.get()));
238 else
239 mMoveUpThreshold = INT_MIN;
240
241 if (mpTrack && tracks.CanMoveDown(*mpTrack))
243 event.m_y +
245 * ++ tracks.Find(mpTrack.get()));
246 else
247 mMoveDownThreshold = INT_MAX;
248}
const auto tracks
const auto project
static int GetChannelGroupHeight(const Track *pTrack)
Definition: ChannelView.cpp:39
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314

References TrackList::Get(), ChannelView::GetChannelGroupHeight(), mMoveDownThreshold, mMoveUpThreshold, mpTrack, project, and tracks.

Referenced by Click(), and Drag().

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

◆ Cancel()

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

Implements UIHandle.

Definition at line 214 of file TrackSelectHandle.cpp.

215{
216 ProjectHistory::Get( *pProject ).RollbackState();
217 // Bug 1677
218 mpTrack.reset();
220}
static ProjectHistory & Get(AudacityProject &project)

References ProjectHistory::Get(), mpTrack, RefreshCode::RefreshAll, and ProjectHistory::RollbackState().

Here is the call graph for this function:

◆ Click()

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

Implements UIHandle.

Definition at line 73 of file TrackSelectHandle.cpp.

75{
76 // If unsafe to drag, still, it does harmlessly change the selected track
77 // set on button down.
78
79 using namespace RefreshCode;
80 Result result = RefreshNone;
81
82 const wxMouseEvent &event = evt.event;
83
84 // AS: If not a click, ignore the mouse event.
85 if (!event.ButtonDown() && !event.ButtonDClick())
86 return Cancelled;
87 if (!event.Button(wxMOUSE_BTN_LEFT))
88 return Cancelled;
89
90 const auto pTrack = mpTrack;
91 if (!pTrack)
92 return Cancelled;
93 const bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
94
95 // DM: If they weren't clicking on a particular part of a track label,
96 // deselect other tracks and select this one.
97
98 // JH: also, capture the current track for rearranging, so the user
99 // can drag the track up or down to swap it with others
100 if (unsafe)
101 result |= Cancelled;
102 else {
103 mRearrangeCount = 0;
104 CalculateRearrangingThresholds(event, pProject);
105 }
106
108 *pTrack, event.ShiftDown(), event.ControlDown(), !unsafe);
109
110 mClicked = true;
111 return result;
112}
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
void CalculateRearrangingThresholds(const wxMouseEvent &event, AudacityProject *project)
unsigned Result
Definition: UIHandle.h:40
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
void DoListSelection(AudacityProject &project, Track &t, bool shift, bool ctrl, bool modifyState)

References CalculateRearrangingThresholds(), Cancelled, SelectUtilities::DoListSelection(), TrackPanelMouseEvent::event, ProjectAudioIO::Get(), ProjectAudioIO::IsAudioActive(), mClicked, mpTrack, mRearrangeCount, and RefreshCode::RefreshNone.

Here is the call graph for this function:

◆ Drag()

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

Implements UIHandle.

Definition at line 114 of file TrackSelectHandle.cpp.

116{
117 using namespace RefreshCode;
118 Result result = RefreshNone;
119 if (!mpTrack)
120 return result;
121
122 const wxMouseEvent &event = evt.event;
123
124 auto &tracks = TrackList::Get( *pProject );
125
126 // probably harmless during play? However, we do disallow the click, so check this too.
127 bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
128 if (unsafe)
129 return result;
130
131 if (event.m_y < mMoveUpThreshold || event.m_y < 0) {
132 tracks.MoveUp(*mpTrack);
134 }
135 else if ( event.m_y > mMoveDownThreshold
136 || event.m_y > evt.whole.GetHeight() ) {
137 tracks.MoveDown(*mpTrack);
139 }
140 else
141 return result;
142
143 // JH: if we moved up or down, recalculate the thresholds and make sure the
144 // track is fully on-screen.
145 CalculateRearrangingThresholds(event, pProject);
146
147 result |= EnsureVisible | RefreshAll;
148 return result;
149}

References CalculateRearrangingThresholds(), RefreshCode::EnsureVisible, TrackPanelMouseEvent::event, ProjectAudioIO::Get(), TrackList::Get(), ProjectAudioIO::IsAudioActive(), mMoveDownThreshold, mMoveUpThreshold, mpTrack, mRearrangeCount, RefreshCode::RefreshAll, RefreshCode::RefreshNone, tracks, and TrackPanelMouseEvent::whole.

Here is the call graph for this function:

◆ FindTrack()

std::shared_ptr< const Track > TrackSelectHandle::FindTrack ( ) const
overridevirtual
Returns
pointer to associated track, if any

Implements UIHandle.

Definition at line 68 of file TrackSelectHandle.cpp.

69{
70 return mpTrack;
71}

References mpTrack.

◆ HitAnywhere()

UIHandlePtr TrackSelectHandle::HitAnywhere ( std::weak_ptr< TrackSelectHandle > &  holder,
const std::shared_ptr< Track > &  pTrack 
)
static

Definition at line 55 of file TrackSelectHandle.cpp.

58{
59 auto result = std::make_shared<TrackSelectHandle>(pTrack);
60 result = AssignUIHandlePtr(holder, result);
61 return result;
62}
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164

References AssignUIHandlePtr().

Referenced by CommonTrackControls::HitTest().

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

◆ operator=()

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

◆ Preview()

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

Implements UIHandle.

Definition at line 151 of file TrackSelectHandle.cpp.

153{
154 static auto disabledCursor =
155 ::MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
156 //static wxCursor rearrangeCursor{ wxCURSOR_HAND };
157 static auto rearrangingCursor =
158 ::MakeCursor(wxCURSOR_HAND, RearrangingCursorXpm, 16, 16);
159 static wxCursor arrowCursor{ wxCURSOR_ARROW };
160
161 //static auto hoverCursor =
162 // ::MakeCursor(wxCURSOR_HAND, RearrangeCursorXpm, 16, 16);
163 //static auto clickedCursor =
164 // ::MakeCursor(wxCURSOR_HAND, RearrangingCursorXpm, 16, 16);
165
166 const auto trackCount = TrackList::Get( *project ).Any().size();
167 auto message = Message(trackCount);
168 if (mClicked) {
169 const bool unsafe =
171 const bool canMove = TrackList::Get( *project ).Any().size() > 1;
172 return {
173 message,
174 (unsafe
175 ? &*disabledCursor
176 : canMove
177 ? &*rearrangingCursor
178 : &arrowCursor)
179 // , message // Stop showing the tooltip after the click
180 };
181 }
182 else {
183 // Only mouse-over
184 // Don't test safety, because the click to change selection is allowed
185 return {
186 message,
187 &arrowCursor,
188 message
189 };
190 }
191}
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:189
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:950
TranslatableString Message(unsigned trackCount)

References TrackList::Any(), ProjectAudioIO::Get(), TrackList::Get(), ProjectAudioIO::IsAudioActive(), MakeCursor(), mClicked, and anonymous_namespace{TrackSelectHandle.cpp}::Message().

Here is the call graph for this function:

◆ Release()

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

Implements UIHandle.

Definition at line 193 of file TrackSelectHandle.cpp.

195{
196 // If we're releasing, surely we are dragging a track?
197 wxASSERT( mpTrack );
198 if (mRearrangeCount != 0) {
199 ProjectHistory::Get( *project ).PushState(
200 /* i18n-hint: will substitute name of track for %s */
201 ( mRearrangeCount < 0 ? XO("Moved '%s' up") : XO("Moved '%s' down") )
202 .Format( mpTrack->GetName() ),
203 XO("Move Track"));
204 }
205 // Bug 1677
206 // Holding on to the reference to the track was causing it to be released far later
207 // than necessary, on shutdown, and so causing a crash as a dialog about cleaning
208 // out files could not show at that time.
209 mpTrack.reset();
210 // No need to redraw, that was done when drag moved the track
212}
XO("Cut/Copy/Paste")
Abstract base class used in importing a file.
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)

References ProjectHistory::Get(), mpTrack, mRearrangeCount, ProjectHistory::PushState(), RefreshCode::RefreshNone, and XO().

Here is the call graph for this function:

◆ StopsOnKeystroke()

bool TrackSelectHandle::StopsOnKeystroke ( )
inlineoverridevirtual

Reimplemented from UIHandle.

Definition at line 52 of file TrackSelectHandle.h.

52{ return true; }

Member Data Documentation

◆ mClicked

bool TrackSelectHandle::mClicked {}
private

Definition at line 56 of file TrackSelectHandle.h.

Referenced by Click(), and Preview().

◆ mMoveDownThreshold

int TrackSelectHandle::mMoveDownThreshold {}
private

Definition at line 61 of file TrackSelectHandle.h.

Referenced by CalculateRearrangingThresholds(), and Drag().

◆ mMoveUpThreshold

int TrackSelectHandle::mMoveUpThreshold {}
private

Definition at line 60 of file TrackSelectHandle.h.

Referenced by CalculateRearrangingThresholds(), and Drag().

◆ mpTrack

std::shared_ptr<Track> TrackSelectHandle::mpTrack
private

◆ mRearrangeCount

int TrackSelectHandle::mRearrangeCount {}
private

Definition at line 62 of file TrackSelectHandle.h.

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


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