Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SubViewRearrangeHandle Class Reference
Inheritance diagram for SubViewRearrangeHandle:
[legend]
Collaboration diagram for SubViewRearrangeHandle:
[legend]

Public Types

enum  { HotZoneWidth = 3 * kTrackInfoBtnSize / 2 }
 
enum  DragChoice_t { Upward , Downward , Neutral }
 
- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 

Public Member Functions

 SubViewRearrangeHandle (SubViewAdjuster &&adjuster, size_t subViewIndex, wxCoord viewHeight)
 
std::shared_ptr< const TrackFindTrack () const override
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
bool Clicked () const
 
DragChoice_t DragChoice (const TrackPanelMouseEvent &event) const
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *) 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 HitTest (std::weak_ptr< SubViewRearrangeHandle > &holder, WaveChannelView &view, WaveChannelSubView &subView, const TrackPanelMouseState &state)
 
- 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 Attributes

SubViewAdjuster mAdjuster
 
std::vector< wxCoord > mHeights
 
wxCoord mTopY
 
size_t mMySubView {}
 
wxCoord mViewHeight {}
 

Additional Inherited Members

- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 486 of file WaveChannelView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
HotZoneWidth 

Definition at line 490 of file WaveChannelView.cpp.

490{ HotZoneWidth = 3 * kTrackInfoBtnSize / 2 };
@ kTrackInfoBtnSize
Definition: ViewInfo.h:98

◆ DragChoice_t

Enumerator
Upward 
Downward 
Neutral 

Definition at line 573 of file WaveChannelView.cpp.

Constructor & Destructor Documentation

◆ SubViewRearrangeHandle()

SubViewRearrangeHandle::SubViewRearrangeHandle ( SubViewAdjuster &&  adjuster,
size_t  subViewIndex,
wxCoord  viewHeight 
)
inline

Definition at line 533 of file WaveChannelView.cpp.

536 : mAdjuster{ std::move( adjuster ) }
537 , mMySubView{ subViewIndex }
538 , mViewHeight{ viewHeight }
539 {
540 }

Member Function Documentation

◆ Cancel()

Result SubViewRearrangeHandle::Cancel ( AudacityProject )
inlineoverridevirtual

Implements UIHandle.

Definition at line 665 of file WaveChannelView.cpp.

666 {
667 mAdjuster.UpdateViews( true );
669 }
void UpdateViews(bool rollback)

References mAdjuster, RefreshCode::RefreshAll, and SubViewAdjuster::UpdateViews().

Here is the call graph for this function:

◆ Click()

Result SubViewRearrangeHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 550 of file WaveChannelView.cpp.

552 {
553 using namespace RefreshCode;
554 const auto &permutation = mAdjuster.mPermutation;
555 const auto size = permutation.size();
556 if ( mMySubView >= size )
557 return Cancelled;
558
560
561 // Find y coordinate of first sub-view
562 wxCoord heightAbove = 0;
563 for (auto index = mAdjuster.mFirstSubView;
564 index != mMySubView; ++index)
565 heightAbove += mHeights[ index ];
566 mTopY = event.rect.GetTop() - heightAbove;
567
568 return RefreshNone;
569 }
std::vector< wxCoord > mHeights
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
std::vector< wxCoord > ComputeHeights(wxCoord totalHeight)
std::vector< size_t > mPermutation

References Cancelled, SubViewAdjuster::ComputeHeights(), mAdjuster, SubViewAdjuster::mFirstSubView, mHeights, mMySubView, SubViewAdjuster::mPermutation, mTopY, mViewHeight, RefreshCode::RefreshNone, and size.

Here is the call graph for this function:

◆ Clicked()

bool SubViewRearrangeHandle::Clicked ( ) const
inline

Definition at line 571 of file WaveChannelView.cpp.

571{ return !mHeights.empty(); }

References mHeights.

Referenced by Preview().

Here is the caller graph for this function:

◆ Drag()

Result SubViewRearrangeHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject  
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 606 of file WaveChannelView.cpp.

607 {
608 using namespace RefreshCode;
609 auto pView = mAdjuster.mwView.lock();
610 if ( !pView )
611 return Cancelled;
612
613 switch( DragChoice( event ) ) {
614 case Upward:
615 {
617 std::swap(
620 );
621 --mMySubView;
622 break;
623 }
624 case Downward:
625 {
627 std::swap(
630 );
631 ++mMySubView;
632 break;
633 }
634 default:
635 return RefreshNone;
636 }
637
638 // Save adjustment to the track and request a redraw
639 mAdjuster.UpdateViews( false );
640 return RefreshAll;
641 }
DragChoice_t DragChoice(const TrackPanelMouseEvent &event) const
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634
WaveChannelSubViewPlacements mNewPlacements
std::weak_ptr< WaveChannelView > mwView

References Cancelled, Downward, DragChoice(), mAdjuster, mHeights, mMySubView, SubViewAdjuster::mNewPlacements, SubViewAdjuster::mwView, RefreshCode::RefreshAll, RefreshCode::RefreshNone, anonymous_namespace{NoteTrack.cpp}::swap(), SubViewAdjuster::UpdateViews(), and Upward.

Here is the call graph for this function:

◆ DragChoice()

DragChoice_t SubViewRearrangeHandle::DragChoice ( const TrackPanelMouseEvent event) const
inline

Definition at line 575 of file WaveChannelView.cpp.

576 {
577 // Disregard x coordinate -- so the mouse need not be in any sub-view,
578 // just in the correct range of y coordinates
579 auto yy = event.event.GetY();
580 auto coord = mTopY;
581 size_t ii = mAdjuster.mFirstSubView;
582 if ( yy < mTopY )
583 return ( mMySubView == ii ) ? Neutral : Upward;
584
585 for ( auto nn = mHeights.size(); ii < nn; ++ii ) {
586 const auto height = mHeights[ ii ];
587 coord += height;
588 if ( yy < coord )
589 break;
590 }
591
592 if ( ii < mMySubView ) {
593 if ( yy < coord - mHeights[ ii ] + mHeights[ mMySubView ] )
594 return Upward;
595 }
596
597 if ( ii > mMySubView ) {
598 if( mMySubView < mHeights.size() - 1 &&
599 yy >= coord - mHeights[ mMySubView ] )
600 return Downward;
601 }
602
603 return Neutral;
604 }

References Downward, mAdjuster, SubViewAdjuster::mFirstSubView, mHeights, mMySubView, mTopY, Neutral, and Upward.

Referenced by Drag().

Here is the caller graph for this function:

◆ FindTrack()

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

Implements UIHandle.

Definition at line 542 of file WaveChannelView.cpp.

543 {
544 auto pView = mAdjuster.mwView.lock();
545 if (pView)
546 return TrackFromChannel(pView->FindChannel());
547 return nullptr;
548 }
static std::shared_ptr< const Track > TrackFromChannel(const std::shared_ptr< const Channel > &pChannel)
A frequent convenience in the definition of UIHandles.
Definition: UIHandle.cpp:63

References mAdjuster, SubViewAdjuster::mwView, and UIHandle::TrackFromChannel().

Here is the call graph for this function:

◆ HitTest()

static UIHandlePtr SubViewRearrangeHandle::HitTest ( std::weak_ptr< SubViewRearrangeHandle > &  holder,
WaveChannelView view,
WaveChannelSubView subView,
const TrackPanelMouseState state 
)
inlinestatic

Definition at line 492 of file WaveChannelView.cpp.

495 {
496 if ( !view.GetMultiView() )
497 return {};
498
499 SubViewAdjuster adjuster{ view };
500 if ( adjuster.NVisible() < 2 )
501 return {};
502
503 auto relX = state.state.GetX() - state.rect.GetLeft();
504 if ( relX >= HotZoneWidth )
505 return {};
506
507 auto index = adjuster.FindIndex( subView );
508
509 // Hit on the rearrange cursor only in the top and bottom thirds of
510 // sub-view height, leaving the rest free to hit the selection cursor
511 // first.
512 // And also exclude the top third of the topmost sub-view and bottom
513 // third of bottommost.
514 auto relY = state.state.GetY() - state.rect.GetTop();
515 auto height = state.rect.GetHeight();
516 bool hit =
517 ( ( 3 * relY < height ) && index > 0 ) // top hit
518 ||
519 ( ( 3 * relY > 2 * height ) &&
520 index < adjuster.mPermutation.size() - 1 ) // bottom
521 ;
522 if ( ! hit )
523 return {};
524
525 auto result = std::make_shared< SubViewRearrangeHandle >(
526 std::move( adjuster ),
527 index, view.GetLastHeight()
528 );
529 result = AssignUIHandlePtr( holder, result );
530 return result;
531 }
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
bool GetMultiView() const
wxCoord GetLastHeight() const

References AssignUIHandlePtr(), WaveChannelView::GetLastHeight(), WaveChannelView::GetMultiView(), HotZoneWidth, TrackPanelMouseState::rect, and TrackPanelMouseState::state.

Referenced by WaveChannelSubView::DoDetailedHitTest().

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

◆ Preview()

HitTestPreview SubViewRearrangeHandle::Preview ( const TrackPanelMouseState state,
AudacityProject  
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 643 of file WaveChannelView.cpp.

645 {
646 static auto hoverCursor =
647 ::MakeCursor(wxCURSOR_HAND, RearrangeCursorXpm, 16, 16);
648 static auto clickedCursor =
649 ::MakeCursor(wxCURSOR_HAND, RearrangingCursorXpm, 16, 16);
650 return {
651 XO("Click and drag to rearrange sub-views"),
652 Clicked() ? &*clickedCursor : &*hoverCursor,
653 XO("Rearrange sub-views")
654 };
655 }
XO("Cut/Copy/Paste")
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:189

References Clicked(), MakeCursor(), and XO().

Here is the call graph for this function:

◆ Release()

Result SubViewRearrangeHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
inlineoverridevirtual

Implements UIHandle.

Definition at line 657 of file WaveChannelView.cpp.

660 {
661 ProjectHistory::Get( *pProject ).ModifyState( false );
663 }
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)

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

Here is the call graph for this function:

Member Data Documentation

◆ mAdjuster

SubViewAdjuster SubViewRearrangeHandle::mAdjuster
private

Definition at line 673 of file WaveChannelView.cpp.

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

◆ mHeights

std::vector<wxCoord> SubViewRearrangeHandle::mHeights
private

Definition at line 674 of file WaveChannelView.cpp.

Referenced by Click(), Clicked(), Drag(), and DragChoice().

◆ mMySubView

size_t SubViewRearrangeHandle::mMySubView {}
private

Definition at line 678 of file WaveChannelView.cpp.

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

◆ mTopY

wxCoord SubViewRearrangeHandle::mTopY
private

Definition at line 675 of file WaveChannelView.cpp.

Referenced by Click(), and DragChoice().

◆ mViewHeight

wxCoord SubViewRearrangeHandle::mViewHeight {}
private

Definition at line 680 of file WaveChannelView.cpp.

Referenced by Click().


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