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

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

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

208{
209 ProjectHistory::Get( *pProject ).RollbackState();
210 // Bug 1677
211 mpTrack.reset();
213}
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 68 of file TrackSelectHandle.cpp.

70{
71 // If unsafe to drag, still, it does harmlessly change the selected track
72 // set on button down.
73
74 using namespace RefreshCode;
75 Result result = RefreshNone;
76
77 const wxMouseEvent &event = evt.event;
78
79 // AS: If not a click, ignore the mouse event.
80 if (!event.ButtonDown() && !event.ButtonDClick())
81 return Cancelled;
82 if (!event.Button(wxMOUSE_BTN_LEFT))
83 return Cancelled;
84
85 const auto pTrack = mpTrack;
86 if (!pTrack)
87 return Cancelled;
88 const bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
89
90 // DM: If they weren't clicking on a particular part of a track label,
91 // deselect other tracks and select this one.
92
93 // JH: also, capture the current track for rearranging, so the user
94 // can drag the track up or down to swap it with others
95 if (unsafe)
96 result |= Cancelled;
97 else {
99 CalculateRearrangingThresholds(event, pProject);
100 }
101
103 *pTrack, event.ShiftDown(), event.ControlDown(), !unsafe);
104
105 mClicked = true;
106 return result;
107}
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
void CalculateRearrangingThresholds(const wxMouseEvent &event, AudacityProject *project)
unsigned Result
Definition: UIHandle.h:38
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 109 of file TrackSelectHandle.cpp.

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

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:

◆ 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:151

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

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

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

50{ return true; }

Member Data Documentation

◆ mClicked

bool TrackSelectHandle::mClicked {}
private

Definition at line 54 of file TrackSelectHandle.h.

Referenced by Click(), and Preview().

◆ mMoveDownThreshold

int TrackSelectHandle::mMoveDownThreshold {}
private

Definition at line 59 of file TrackSelectHandle.h.

Referenced by CalculateRearrangingThresholds(), and Drag().

◆ mMoveUpThreshold

int TrackSelectHandle::mMoveUpThreshold {}
private

Definition at line 58 of file TrackSelectHandle.h.

Referenced by CalculateRearrangingThresholds(), and Drag().

◆ mpTrack

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

Definition at line 53 of file TrackSelectHandle.h.

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

◆ mRearrangeCount

int TrackSelectHandle::mRearrangeCount {}
private

Definition at line 60 of file TrackSelectHandle.h.

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


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