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 ChannelFindChannel () 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 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 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 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 222 of file TrackSelectHandle.cpp.

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

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 212 of file TrackSelectHandle.cpp.

213{
214 ProjectHistory::Get( *pProject ).RollbackState();
215 // Bug 1677
216 mpTrack.reset();
218}
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:39
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
120 const wxMouseEvent &event = evt.event;
121
122 auto &tracks = TrackList::Get( *pProject );
123
124 // probably harmless during play? However, we do disallow the click, so check this too.
125 bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
126 if (unsafe)
127 return result;
128
129 if (event.m_y < mMoveUpThreshold || event.m_y < 0) {
130 tracks.MoveUp(mpTrack.get());
132 }
133 else if ( event.m_y > mMoveDownThreshold
134 || event.m_y > evt.whole.GetHeight() ) {
135 tracks.MoveDown(mpTrack.get());
137 }
138 else
139 return result;
140
141 // JH: if we moved up or down, recalculate the thresholds and make sure the
142 // track is fully on-screen.
143 CalculateRearrangingThresholds(event, pProject);
144
145 result |= EnsureVisible | RefreshAll;
146 return result;
147}

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:

◆ FindChannel()

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

Implements UIHandle.

Definition at line 68 of file TrackSelectHandle.cpp.

69{
70 return std::dynamic_pointer_cast<const Channel>(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:159

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 149 of file TrackSelectHandle.cpp.

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

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