1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-17 17:17:40 +02:00

TrackVRulerControl is directly owned by TrackView not Track...

... in anticipation of making views to tracks many-to-one, but then the rulers
should be one-to-one with the views.  So go through the view to get the ruler.
The ruler is really a left-hand extension for each view.
This commit is contained in:
Paul Licameli 2019-06-17 08:52:28 -04:00
parent e90943cfe1
commit 18b4c01c51
22 changed files with 82 additions and 41 deletions

View File

@ -321,7 +321,6 @@ private:
protected: protected:
std::shared_ptr<TrackView> DoGetView() override; std::shared_ptr<TrackView> DoGetView() override;
std::shared_ptr<TrackControls> DoGetControls() override; std::shared_ptr<TrackControls> DoGetControls() override;
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
friend class GetInfoCommand; // to get labels. friend class GetInfoCommand; // to get labels.
friend class SetLabelCommand; // to set labels. friend class SetLabelCommand; // to set labels.

View File

@ -228,7 +228,6 @@ class AUDACITY_DLL_API NoteTrack final
protected: protected:
std::shared_ptr<TrackView> DoGetView() override; std::shared_ptr<TrackView> DoGetView() override;
std::shared_ptr<TrackControls> DoGetControls() override; std::shared_ptr<TrackControls> DoGetControls() override;
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
}; };
/// Data used to display a note track /// Data used to display a note track

View File

@ -125,7 +125,6 @@ class TimeTrack final : public Track {
protected: protected:
std::shared_ptr<TrackView> DoGetView() override; std::shared_ptr<TrackView> DoGetView() override;
std::shared_ptr<TrackControls> DoGetControls() override; std::shared_ptr<TrackControls> DoGetControls() override;
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
}; };

View File

@ -38,7 +38,6 @@ class LabelTrack;
class TimeTrack; class TimeTrack;
class TrackControls; class TrackControls;
class TrackView; class TrackView;
class TrackVRulerControls;
class TrackPanelResizerCell; class TrackPanelResizerCell;
class WaveTrack; class WaveTrack;
class NoteTrack; class NoteTrack;
@ -297,11 +296,7 @@ class AUDACITY_DLL_API Track /* not final */
std::shared_ptr<const TrackPanelCell> GetTrackControls() const; std::shared_ptr<const TrackPanelCell> GetTrackControls() const;
// Return another, associated TrackPanelCell object that implements the // Return another, associated TrackPanelCell object that implements the
// mouse actions for the vertical ruler
std::shared_ptr<TrackVRulerControls> GetVRulerControls();
std::shared_ptr<const TrackVRulerControls> GetVRulerControls() const;
// Return another, associated TrackPanelCell object that implements the
// click and drag to resize // click and drag to resize
std::shared_ptr<TrackPanelCell> GetResizer(); std::shared_ptr<TrackPanelCell> GetResizer();
@ -760,12 +755,10 @@ protected:
// These are called to create controls on demand: // These are called to create controls on demand:
virtual std::shared_ptr<TrackView> DoGetView() = 0; virtual std::shared_ptr<TrackView> DoGetView() = 0;
virtual std::shared_ptr<TrackControls> DoGetControls() = 0; virtual std::shared_ptr<TrackControls> DoGetControls() = 0;
virtual std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() = 0;
// These hold the controls: // These hold the controls:
std::shared_ptr<TrackView> mpView; std::shared_ptr<TrackView> mpView;
std::shared_ptr<TrackControls> mpControls; std::shared_ptr<TrackControls> mpControls;
std::shared_ptr<TrackVRulerControls> mpVRulerContols;
std::shared_ptr<TrackPanelResizerCell> mpResizer; std::shared_ptr<TrackPanelResizerCell> mpResizer;
std::weak_ptr<SelectHandle> mSelectHandle; std::weak_ptr<SelectHandle> mSelectHandle;

View File

@ -101,7 +101,7 @@ is time to refresh some aspect of the screen.
#include "toolbars/ControlToolBar.h" #include "toolbars/ControlToolBar.h"
#include "tracks/ui/TrackControls.h" #include "tracks/ui/TrackControls.h"
#include "tracks/ui/TrackVRulerControls.h" // for inheritance relation #include "tracks/ui/TrackVRulerControls.h"
//This loads the appropriate set of cursors, depending on platform. //This loads the appropriate set of cursors, depending on platform.
#include "../images/Cursors.h" #include "../images/Cursors.h"

View File

@ -701,7 +701,6 @@ private:
protected: protected:
std::shared_ptr<TrackView> DoGetView() override; std::shared_ptr<TrackView> DoGetView() override;
std::shared_ptr<TrackControls> DoGetControls() override; std::shared_ptr<TrackControls> DoGetControls() override;
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
}; };
// This is meant to be a short-lived object, during whose lifetime, // This is meant to be a short-lived object, during whose lifetime,

View File

@ -23,8 +23,8 @@ class LabelTrackVRulerControls final : public TrackVRulerControls
public: public:
explicit explicit
LabelTrackVRulerControls( std::shared_ptr<Track> pTrack ) LabelTrackVRulerControls( const std::shared_ptr<TrackView> &pTrackView )
: TrackVRulerControls( pTrack ) {} : TrackVRulerControls( pTrackView ) {}
~LabelTrackVRulerControls(); ~LabelTrackVRulerControls();
}; };

View File

@ -15,6 +15,7 @@ Paul Licameli split from TrackPanel.cpp
#include "LabelTrackVRulerControls.h" #include "LabelTrackVRulerControls.h"
#include "LabelGlyphHandle.h" #include "LabelGlyphHandle.h"
#include "LabelTextHandle.h" #include "LabelTextHandle.h"
#include "LabelTrackVRulerControls.h"
#include "../../../HitTestResult.h" #include "../../../HitTestResult.h"
#include "../../../TrackPanelMouseEvent.h" #include "../../../TrackPanelMouseEvent.h"
@ -54,7 +55,8 @@ std::shared_ptr<TrackControls> LabelTrack::DoGetControls()
return std::make_shared<LabelTrackControls>( SharedPointer() ); return std::make_shared<LabelTrackControls>( SharedPointer() );
} }
std::shared_ptr<TrackVRulerControls> LabelTrack::DoGetVRulerControls() std::shared_ptr<TrackVRulerControls> LabelTrackView::DoGetVRulerControls()
{ {
return std::make_shared<LabelTrackVRulerControls>( SharedPointer() ); return
std::make_shared<LabelTrackVRulerControls>( shared_from_this() );
} }

View File

@ -23,6 +23,9 @@ public:
LabelTrackView( const std::shared_ptr<Track> &pTrack ) LabelTrackView( const std::shared_ptr<Track> &pTrack )
: CommonTrackView{ pTrack } {} : CommonTrackView{ pTrack } {}
~LabelTrackView() override; ~LabelTrackView() override;
private:
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
}; };
#endif #endif

View File

@ -22,8 +22,8 @@ class NoteTrackVRulerControls final : public TrackVRulerControls
public: public:
explicit explicit
NoteTrackVRulerControls( std::shared_ptr<Track> pTrack ) NoteTrackVRulerControls( const std::shared_ptr<TrackView> &pTrackView )
: TrackVRulerControls( pTrack ) {} : TrackVRulerControls( pTrackView ) {}
~NoteTrackVRulerControls(); ~NoteTrackVRulerControls();
std::vector<UIHandlePtr> HitTest std::vector<UIHandlePtr> HitTest

View File

@ -57,8 +57,10 @@ std::shared_ptr<TrackControls> NoteTrack::DoGetControls()
return std::make_shared<NoteTrackControls>( SharedPointer() ); return std::make_shared<NoteTrackControls>( SharedPointer() );
} }
std::shared_ptr<TrackVRulerControls> NoteTrack::DoGetVRulerControls() std::shared_ptr<TrackVRulerControls> NoteTrackView::DoGetVRulerControls()
{ {
return std::make_shared<NoteTrackVRulerControls>( SharedPointer() ); return
std::make_shared<NoteTrackVRulerControls>( shared_from_this() );
} }
#endif #endif

View File

@ -23,6 +23,8 @@ public:
NoteTrackView( const std::shared_ptr<Track> &pTrack ) NoteTrackView( const std::shared_ptr<Track> &pTrack )
: CommonTrackView{ pTrack } {} : CommonTrackView{ pTrack } {}
~NoteTrackView() override; ~NoteTrackView() override;
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
}; };
#endif #endif

View File

@ -22,8 +22,8 @@ class WaveTrackVRulerControls final : public TrackVRulerControls
public: public:
explicit explicit
WaveTrackVRulerControls( std::shared_ptr<Track> pTrack ) WaveTrackVRulerControls( const std::shared_ptr<TrackView> &pTrackView )
: TrackVRulerControls( pTrack ) {} : TrackVRulerControls( pTrackView ) {}
~WaveTrackVRulerControls(); ~WaveTrackVRulerControls();
std::vector<UIHandlePtr> HitTest std::vector<UIHandlePtr> HitTest

View File

@ -14,6 +14,7 @@ Paul Licameli split from TrackPanel.cpp
#include "WaveTrackControls.h" #include "WaveTrackControls.h"
#include "WaveTrackVRulerControls.h" #include "WaveTrackVRulerControls.h"
#include "WaveTrackVRulerControls.h"
#include "../../../../HitTestResult.h" #include "../../../../HitTestResult.h"
#include "../../../../TrackPanelMouseEvent.h" #include "../../../../TrackPanelMouseEvent.h"
@ -116,7 +117,8 @@ std::shared_ptr<TrackControls> WaveTrack::DoGetControls()
return std::make_shared<WaveTrackControls>( SharedPointer() ); return std::make_shared<WaveTrackControls>( SharedPointer() );
} }
std::shared_ptr<TrackVRulerControls> WaveTrack::DoGetVRulerControls() std::shared_ptr<TrackVRulerControls> WaveTrackView::DoGetVRulerControls()
{ {
return std::make_shared<WaveTrackVRulerControls>( SharedPointer() ); return
std::make_shared<WaveTrackVRulerControls>( shared_from_this() );
} }

View File

@ -23,6 +23,8 @@ public:
WaveTrackView( const std::shared_ptr<Track> &pTrack ) WaveTrackView( const std::shared_ptr<Track> &pTrack )
: CommonTrackView{ pTrack } {} : CommonTrackView{ pTrack } {}
~WaveTrackView() override; ~WaveTrackView() override;
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
}; };
#endif #endif

View File

@ -22,8 +22,8 @@ class TimeTrackVRulerControls final : public TrackVRulerControls
public: public:
explicit explicit
TimeTrackVRulerControls( std::shared_ptr<Track> pTrack ) TimeTrackVRulerControls( const std::shared_ptr<TrackView> &pTrackView )
: TrackVRulerControls( pTrack ) {} : TrackVRulerControls( pTrackView ) {}
~TimeTrackVRulerControls(); ~TimeTrackVRulerControls();
}; };

View File

@ -14,6 +14,7 @@ Paul Licameli split from TrackPanel.cpp
#include "TimeTrackControls.h" #include "TimeTrackControls.h"
#include "TimeTrackVRulerControls.h" #include "TimeTrackVRulerControls.h"
#include "TimeTrackVRulerControls.h"
#include "../../../HitTestResult.h" #include "../../../HitTestResult.h"
#include "../../../TrackPanelMouseEvent.h" #include "../../../TrackPanelMouseEvent.h"
@ -45,7 +46,8 @@ std::shared_ptr<TrackControls> TimeTrack::DoGetControls()
return std::make_shared<TimeTrackControls>( SharedPointer() ); return std::make_shared<TimeTrackControls>( SharedPointer() );
} }
std::shared_ptr<TrackVRulerControls> TimeTrack::DoGetVRulerControls() std::shared_ptr<TrackVRulerControls> TimeTrackView::DoGetVRulerControls()
{ {
return std::make_shared<TimeTrackVRulerControls>( SharedPointer() ); return
std::make_shared<TimeTrackVRulerControls>( shared_from_this() );
} }

View File

@ -23,6 +23,9 @@ public:
TimeTrackView( const std::shared_ptr<Track> &pTrack ) TimeTrackView( const std::shared_ptr<Track> &pTrack )
: CommonTrackView{ pTrack } {} : CommonTrackView{ pTrack } {}
~TimeTrackView() override; ~TimeTrackView() override;
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
}; };
#endif #endif

View File

@ -11,6 +11,8 @@ Paul Licameli split from TrackPanel.cpp
#include "../../Audacity.h" #include "../../Audacity.h"
#include "TrackVRulerControls.h" #include "TrackVRulerControls.h"
#include "TrackView.h"
#include "../../Track.h" #include "../../Track.h"
#include "../../ViewInfo.h" #include "../../ViewInfo.h"
@ -18,8 +20,9 @@ Paul Licameli split from TrackPanel.cpp
#include <wx/dc.h> #include <wx/dc.h>
#include <wx/translation.h> #include <wx/translation.h>
TrackVRulerControls::TrackVRulerControls( std::shared_ptr<Track> pTrack ) TrackVRulerControls::TrackVRulerControls(
: mwTrack{ pTrack } const std::shared_ptr<TrackView> &pTrackView )
: mwTrackView{ pTrackView }
{ {
} }
@ -29,17 +32,30 @@ TrackVRulerControls::~TrackVRulerControls()
TrackVRulerControls &TrackVRulerControls::Get( Track &track ) TrackVRulerControls &TrackVRulerControls::Get( Track &track )
{ {
return *track.GetVRulerControls(); return *TrackView::Get( track ).GetVRulerControls();
} }
const TrackVRulerControls &TrackVRulerControls::Get( const Track &track ) const TrackVRulerControls &TrackVRulerControls::Get( const Track &track )
{ {
return *track.GetVRulerControls(); return *TrackView::Get( track ).GetVRulerControls();
}
TrackVRulerControls &TrackVRulerControls::Get( TrackView &trackView )
{
return *trackView.GetVRulerControls();
}
const TrackVRulerControls &TrackVRulerControls::Get( const TrackView &trackView )
{
return *trackView.GetVRulerControls();
} }
std::shared_ptr<Track> TrackVRulerControls::DoFindTrack() std::shared_ptr<Track> TrackVRulerControls::DoFindTrack()
{ {
return mwTrack.lock(); const auto pView = mwTrackView.lock();
if ( pView )
return pView->FindTrack();
return {};
} }
std::vector<UIHandlePtr> TrackVRulerControls::HitTest std::vector<UIHandlePtr> TrackVRulerControls::HitTest

View File

@ -14,6 +14,7 @@ Paul Licameli split from TrackPanel.cpp
#include "CommonTrackPanelCell.h" #include "CommonTrackPanelCell.h"
class Track; class Track;
class TrackView;
class wxDC; class wxDC;
const int kGuard = 5; // 5 pixels to reduce risk of VZooming accidentally const int kGuard = 5; // 5 pixels to reduce risk of VZooming accidentally
@ -23,13 +24,16 @@ class TrackVRulerControls /* not final */ : public CommonTrackPanelCell
{ {
public: public:
explicit explicit
TrackVRulerControls( std::shared_ptr<Track> pTrack ); TrackVRulerControls( const std::shared_ptr<TrackView> &pTrackView );
virtual ~TrackVRulerControls() = 0; virtual ~TrackVRulerControls() = 0;
static TrackVRulerControls &Get( Track& ); static TrackVRulerControls &Get( Track& );
static const TrackVRulerControls &Get( const Track& ); static const TrackVRulerControls &Get( const Track& );
static TrackVRulerControls &Get( TrackView& );
static const TrackVRulerControls &Get( const TrackView& );
// Define a default hit test method, just for message and cursor // Define a default hit test method, just for message and cursor
std::vector<UIHandlePtr> HitTest std::vector<UIHandlePtr> HitTest
(const TrackPanelMouseState &state, (const TrackPanelMouseState &state,
@ -44,7 +48,7 @@ protected:
Track *GetTrack() const; Track *GetTrack() const;
std::weak_ptr<Track> mwTrack; std::weak_ptr<TrackView> mwTrackView;
}; };
#endif #endif

View File

@ -119,17 +119,17 @@ std::shared_ptr<const TrackPanelCell> Track::GetTrackControls() const
return const_cast< Track* >( this )->GetTrackControls(); return const_cast< Track* >( this )->GetTrackControls();
} }
std::shared_ptr<TrackVRulerControls> Track::GetVRulerControls() std::shared_ptr<TrackVRulerControls> TrackView::GetVRulerControls()
{ {
if (!mpVRulerContols) if (!mpVRulerControls)
// create on demand // create on demand
mpVRulerContols = DoGetVRulerControls(); mpVRulerControls = DoGetVRulerControls();
return mpVRulerContols; return mpVRulerControls;
} }
std::shared_ptr<const TrackVRulerControls> Track::GetVRulerControls() const std::shared_ptr<const TrackVRulerControls> TrackView::GetVRulerControls() const
{ {
return const_cast< Track* >( this )->GetVRulerControls(); return const_cast< TrackView* >( this )->GetVRulerControls();
} }
#include "../../TrackPanelResizeHandle.h" #include "../../TrackPanelResizeHandle.h"

View File

@ -15,8 +15,10 @@ Paul Licameli split from class Track
#include "CommonTrackPanelCell.h" // to inherit #include "CommonTrackPanelCell.h" // to inherit
class Track; class Track;
class TrackVRulerControls;
class TrackView /* not final */ : public CommonTrackCell class TrackView /* not final */ : public CommonTrackCell
, public std::enable_shared_from_this<TrackView>
{ {
TrackView( const TrackView& ) = delete; TrackView( const TrackView& ) = delete;
TrackView &operator=( const TrackView& ) = delete; TrackView &operator=( const TrackView& ) = delete;
@ -29,6 +31,18 @@ public:
static TrackView &Get( Track & ); static TrackView &Get( Track & );
static const TrackView &Get( const Track & ); static const TrackView &Get( const Track & );
// Return another, associated TrackPanelCell object that implements the
// mouse actions for the vertical ruler
std::shared_ptr<TrackVRulerControls> GetVRulerControls();
std::shared_ptr<const TrackVRulerControls> GetVRulerControls() const;
protected:
// Private factory to make appropriate object; class TrackView handles
// memory management thereafter
virtual std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() = 0;
std::shared_ptr<TrackVRulerControls> mpVRulerControls;
}; };
#endif #endif