Audacity  2.2.2
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:
UIHandle

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, const 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)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape () const
 
virtual bool Escape ()
 
virtual void DrawExtras (DrawingPass pass, wxDC *dc, const wxRegion &updateRegion, const wxRect &panelRect)
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 

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 &)
 

Private Member Functions

 TrackSelectHandle (const TrackSelectHandle &)=delete
 
void CalculateRearrangingThresholds (const wxMouseEvent &event)
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from UIHandle
enum  DrawingPass { Cells, Panel }
 
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 20 of file TrackSelectHandle.h.

Constructor & Destructor Documentation

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

Definition at line 52 of file TrackSelectHandle.cpp.

53  : mpTrack( pTrack )
54 {}
std::shared_ptr< Track > mpTrack
TrackSelectHandle::~TrackSelectHandle ( )
virtual

Definition at line 65 of file TrackSelectHandle.cpp.

66 {
67 }

Member Function Documentation

void TrackSelectHandle::CalculateRearrangingThresholds ( const wxMouseEvent &  event)
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.

References TrackList::CanMoveDown(), TrackList::CanMoveUp(), GetActiveProject(), TrackList::GetGroupHeight(), TrackList::GetNext(), TrackList::GetPrev(), AudacityProject::GetTracks(), mMoveDownThreshold, mMoveUpThreshold, and mpTrack.

218 {
219  // JH: this will probably need to be tweaked a bit, I'm just
220  // not sure what formula will have the best feel for the
221  // user.
222 
223  AudacityProject *const project = ::GetActiveProject();
224  TrackList *const tracks = project->GetTracks();
225 
226  if (tracks->CanMoveUp(mpTrack.get()))
228  event.m_y - tracks->GetGroupHeight(tracks->GetPrev(mpTrack.get(), true));
229  else
230  mMoveUpThreshold = INT_MIN;
231 
232  if (tracks->CanMoveDown(mpTrack.get()))
234  event.m_y + tracks->GetGroupHeight(tracks->GetNext(mpTrack.get(), true));
235  else
236  mMoveDownThreshold = INT_MAX;
237 }
A list of TrackListNode items.
Definition: Track.h:619
bool CanMoveDown(Track *t) const
Definition: Track.cpp:1121
std::shared_ptr< Track > mpTrack
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
bool CanMoveUp(Track *t) const
Definition: Track.cpp:1116
Track * GetNext(Track *t, bool linked=false) const
Return a track in the list that comes after Track t.
Definition: Track.cpp:1048
int GetGroupHeight(Track *t) const
Definition: Track.cpp:1105
Track * GetPrev(Track *t, bool linked=false) const
Definition: Track.cpp:1067
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
TrackList * GetTracks()
Definition: Project.h:192
UIHandle::Result TrackSelectHandle::Cancel ( AudacityProject pProject)
overridevirtual

Implements UIHandle.

Definition at line 207 of file TrackSelectHandle.cpp.

References mpTrack, RefreshCode::RefreshAll, and AudacityProject::RollbackState().

208 {
209  pProject->RollbackState();
210  // Bug 1677
211  mpTrack.reset();
213 }
std::shared_ptr< Track > mpTrack
void RollbackState()
Definition: Project.cpp:4742
UIHandle::Result TrackSelectHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 70 of file TrackSelectHandle.cpp.

References RefreshCode::Cancelled, TrackPanelMouseEvent::event, AudacityProject::HandleListSelection(), AudacityProject::IsAudioActive(), and RefreshCode::RefreshNone.

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

Implements UIHandle.

Definition at line 111 of file TrackSelectHandle.cpp.

References RefreshCode::EnsureVisible, TrackPanelMouseEvent::event, AudacityProject::GetMixerBoard(), AudacityProject::GetTracks(), AudacityProject::IsAudioActive(), MixerBoard::MoveTrackCluster(), RefreshCode::RefreshAll, RefreshCode::RefreshNone, and TrackPanelMouseEvent::whole.

112 {
113  using namespace RefreshCode;
114  Result result = RefreshNone;
115 
116  const wxMouseEvent &event = evt.event;
117 
118  TrackList *const tracks = pProject->GetTracks();
119 
120  // probably harmless during play? However, we do disallow the click, so check this too.
121  bool unsafe = pProject->IsAudioActive();
122  if (unsafe)
123  return result;
124 
125  MixerBoard* pMixerBoard = pProject->GetMixerBoard(); // Update mixer board, too.
126  if (event.m_y < mMoveUpThreshold || event.m_y < 0) {
127  tracks->MoveUp(mpTrack.get());
128  --mRearrangeCount;
129  if (pMixerBoard)
130  if(auto pPlayable = dynamic_cast< const PlayableTrack* >( mpTrack.get() ))
131  pMixerBoard->MoveTrackCluster(pPlayable, true /* up */);
132  }
133  else if ( event.m_y > mMoveDownThreshold
134  || event.m_y > evt.whole.GetHeight() ) {
135  tracks->MoveDown(mpTrack.get());
136  ++mRearrangeCount;
137  if (pMixerBoard)
138  if(auto pPlayable = dynamic_cast< const PlayableTrack* >( mpTrack.get() ))
139  pMixerBoard->MoveTrackCluster(pPlayable, false /* down */);
140  }
141  else
142  return result;
143 
144  // JH: if we moved up or down, recalculate the thresholds and make sure the
145  // track is fully on-screen.
147 
148  result |= EnsureVisible | RefreshAll;
149  return result;
150 }
A list of TrackListNode items.
Definition: Track.h:619
std::shared_ptr< Track > mpTrack
MixerBoard * GetMixerBoard()
Definition: Project.h:516
unsigned Result
Definition: UIHandle.h:37
void CalculateRearrangingThresholds(const wxMouseEvent &event)
bool IsAudioActive() const
Definition: Project.cpp:1454
TrackList * GetTracks()
Definition: Project.h:192
UIHandlePtr TrackSelectHandle::HitAnywhere ( std::weak_ptr< TrackSelectHandle > &  holder,
const std::shared_ptr< Track > &  pTrack 
)
static

Definition at line 57 of file TrackSelectHandle.cpp.

References AssignUIHandlePtr().

Referenced by TrackControls::HitTest().

59 {
60  auto result = std::make_shared<TrackSelectHandle>(pTrack);
61  result = AssignUIHandlePtr(holder, result);
62  return result;
63 }
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162
TrackSelectHandle& TrackSelectHandle::operator= ( const TrackSelectHandle )
default
HitTestPreview TrackSelectHandle::Preview ( const TrackPanelMouseState state,
const AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 153 of file TrackSelectHandle.cpp.

References GetActiveProject(), TrackPanel::GetTrackCount(), AudacityProject::GetTrackPanel(), AudacityProject::IsAudioActive(), MakeCursor(), and Release().

154 {
155  const auto trackCount = project->GetTrackPanel()->GetTrackCount();
156  auto message = Message(trackCount);
157  if (mClicked) {
158  static auto disabledCursor =
159  ::MakeCursor(wxCURSOR_NO_ENTRY, DisabledCursorXpm, 16, 16);
160  static wxCursor rearrangeCursor{ wxCURSOR_HAND };
161 
162  const bool unsafe = GetActiveProject()->IsAudioActive();
163  return {
164  message,
165  (unsafe
166  ? &*disabledCursor
167  : &rearrangeCursor)
168  // , message // Stop showing the tooltip after the click
169  };
170  }
171  else {
172  // Only mouse-over
173  // Don't test safety, because the click to change selection is allowed
174  static wxCursor arrowCursor{ wxCURSOR_ARROW };
175  return {
176  message,
177  &arrowCursor,
178  message
179  };
180  }
181 }
bool IsAudioActive() const
Definition: Project.cpp:1454
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:274
UIHandle::Result TrackSelectHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

Implements UIHandle.

Definition at line 184 of file TrackSelectHandle.cpp.

References _(), GetActiveProject(), AudacityProject::PushState(), and RefreshCode::RefreshNone.

Referenced by Preview().

185 {
186  // If we're releasing, surely we are dragging a track?
187  wxASSERT( mpTrack );
188  if (mRearrangeCount != 0) {
189  AudacityProject *const project = ::GetActiveProject();
190  project->PushState(
191  wxString::Format(
192  /* i18n-hint: will substitute name of track for %s */
193  ( mRearrangeCount < 0 ? _("Moved '%s' up") : _("Moved '%s' down") ),
194  mpTrack->GetName()
195  ),
196  _("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 }
std::shared_ptr< Track > mpTrack
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4702
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
bool TrackSelectHandle::StopsOnKeystroke ( )
inlineoverridevirtual

Reimplemented from UIHandle.

Definition at line 51 of file TrackSelectHandle.h.

51 { return true; }

Member Data Documentation

bool TrackSelectHandle::mClicked {}
private

Definition at line 55 of file TrackSelectHandle.h.

int TrackSelectHandle::mMoveDownThreshold {}
private

Definition at line 60 of file TrackSelectHandle.h.

Referenced by CalculateRearrangingThresholds().

int TrackSelectHandle::mMoveUpThreshold {}
private

Definition at line 59 of file TrackSelectHandle.h.

Referenced by CalculateRearrangingThresholds().

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

Definition at line 54 of file TrackSelectHandle.h.

Referenced by CalculateRearrangingThresholds(), and Cancel().

int TrackSelectHandle::mRearrangeCount {}
private

Definition at line 61 of file TrackSelectHandle.h.


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