Bug 2654 - Enh: Time tracks have no context menu for scale changes - inconsistent with audio track

This commit is contained in:
Leland Lucius 2021-02-04 02:56:26 -06:00
parent 3144f0120a
commit 773a86d66e
6 changed files with 235 additions and 33 deletions

View File

@ -38,41 +38,22 @@ enum
OnSetTimeTrackRangeID,
};
class TimeTrackMenuTable : public PopupMenuTable
{
TimeTrackMenuTable()
: PopupMenuTable{ "TimeTrack" }
{}
DECLARE_POPUP_MENU(TimeTrackMenuTable);
public:
static TimeTrackMenuTable &Instance();
private:
void InitUserData(void *pUserData) override
{
mpData = static_cast<CommonTrackControls::InitMenuData*>(pUserData);
}
void DestroyMenu() override
{
mpData = nullptr;
}
CommonTrackControls::InitMenuData *mpData{};
void OnSetTimeTrackRange(wxCommandEvent & /*event*/);
void OnTimeTrackLin(wxCommandEvent & /*event*/);
void OnTimeTrackLog(wxCommandEvent & /*event*/);
void OnTimeTrackLogInt(wxCommandEvent & /*event*/);
};
TimeTrackMenuTable &TimeTrackMenuTable::Instance()
{
static TimeTrackMenuTable instance;
return instance;
}
void TimeTrackMenuTable::InitUserData(void *pUserData)
{
mpData = static_cast<CommonTrackControls::InitMenuData*>(pUserData);
}
void TimeTrackMenuTable::DestroyMenu()
{
mpData = nullptr;
}
void TimeTrackMenuTable::OnSetTimeTrackRange(wxCommandEvent & /*event*/)
{
TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
@ -86,17 +67,19 @@ void TimeTrackMenuTable::OnSetTimeTrackRange(wxCommandEvent & /*event*/)
_("Lower speed limit"),
_("Lower speed limit"),
lower,
10,
1000);
TimeTrackControls::kRangeMin,
TimeTrackControls::kRangeMax);
upper = wxGetNumberFromUser(_("Change upper speed limit (%) to:"),
_("Upper speed limit"),
_("Upper speed limit"),
upper,
lower + 1,
1000);
TimeTrackControls::kRangeMax);
if (lower >= 10 && upper <= 1000 && lower < upper) {
if (lower >= TimeTrackControls::kRangeMin &&
upper <= TimeTrackControls::kRangeMax &&
lower < upper) {
AudacityProject *const project = &mpData->project;
pTrack->SetRangeLower((double)lower / 100.0);
pTrack->SetRangeUpper((double)upper / 100.0);

View File

@ -29,6 +29,36 @@ public:
const AudacityProject *pProject) override;
PopupMenuTable *GetMenuExtension(Track *pTrack) override;
static const int kRangeMin {10};
static const int kRangeMax {1000};
};
#include "../../../widgets/PopupMenuTable.h"
class TimeTrackMenuTable : public PopupMenuTable
{
TimeTrackMenuTable()
: PopupMenuTable{ "TimeTrack" }
{}
DECLARE_POPUP_MENU(TimeTrackMenuTable);
public:
static TimeTrackMenuTable &Instance();
protected:
void InitUserData(void *pUserData) override;
private:
void DestroyMenu() override;
CommonTrackControls::InitMenuData *mpData{};
void OnSetTimeTrackRange(wxCommandEvent & /*event*/);
void OnTimeTrackLin(wxCommandEvent & /*event*/);
void OnTimeTrackLog(wxCommandEvent & /*event*/);
void OnTimeTrackLogInt(wxCommandEvent & /*event*/);
};
#endif

View File

@ -10,15 +10,20 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../Audacity.h"
#include "TimeTrackVRulerControls.h"
#include "TimeTrackVZoomHandle.h"
#include "../../../HitTestResult.h"
#include "../../../AColor.h"
#include "../../../AllThemeResources.h"
#include "../../../ProjectHistory.h"
#include "../../../RefreshCode.h"
#include "../../../Theme.h"
#include "../../../TimeTrack.h"
#include "../../../TrackArtist.h"
#include "../../../TrackPanelDrawingContext.h"
#include "../../../TrackPanelMouseEvent.h"
#include "../../../UIHandle.h"
#include "../../../widgets/Ruler.h"
TimeTrackVRulerControls::~TimeTrackVRulerControls()
@ -33,6 +38,28 @@ namespace {
}
}
std::vector<UIHandlePtr> TimeTrackVRulerControls::HitTest(
const TrackPanelMouseState &st,
const AudacityProject *pProject)
{
std::vector<UIHandlePtr> results;
if ( st.state.GetX() <= st.rect.GetRight() - kGuard ) {
auto pTrack = FindTrack()->SharedPointer<TimeTrack>( );
if (pTrack) {
auto result = std::make_shared<TimeTrackVZoomHandle>(
pTrack, st.rect, st.state.m_y );
result = AssignUIHandlePtr(mVZoomHandle, result);
results.push_back(result);
}
}
auto more = TrackVRulerControls::HitTest(st, pProject);
std::copy(more.begin(), more.end(), std::back_inserter(results));
return results;
}
void TimeTrackVRulerControls::Draw(
TrackPanelDrawingContext &context,
const wxRect &rect_, unsigned iPass )

View File

@ -13,6 +13,8 @@ Paul Licameli split from TrackPanel.cpp
#include "../../ui/TrackVRulerControls.h"
class TimeTrackVZoomHandle;
// This class is here for completeness, by analogy with other track
// types, but it does nothing.
class TimeTrackVRulerControls final : public TrackVRulerControls
@ -26,6 +28,10 @@ public:
: TrackVRulerControls( pTrackView ) {}
~TimeTrackVRulerControls();
std::vector<UIHandlePtr> HitTest(
const TrackPanelMouseState &state,
const AudacityProject *) override;
private:
// TrackPanelDrawable implementation
@ -36,6 +42,7 @@ private:
// TrackVRulerControls implementation
void UpdateRuler( const wxRect &rect ) override;
std::weak_ptr<TimeTrackVZoomHandle> mVZoomHandle;
};
#endif

View File

@ -0,0 +1,103 @@
/**********************************************************************
Audacity: A Digital Audio Editor
TimeTrackVZoomHandle.cpp
Paul Licameli split from TimeTrackVZoomHandle.cpp
**********************************************************************/
#include "../../../Audacity.h"
#include "TimeTrackVZoomHandle.h"
#include "TimeTrackVRulerControls.h"
#include "TimeTrackControls.h"
#include "../../../Experimental.h"
#include "../../../HitTestResult.h"
#include "../../../NumberScale.h"
#include "../../../Prefs.h"
#include "../../../ProjectHistory.h"
#include "../../../RefreshCode.h"
#include "../../../TrackPanelMouseEvent.h"
#include "../../../TimeTrack.h"
TimeTrackVZoomHandle::TimeTrackVZoomHandle(
const std::shared_ptr<TimeTrack> &pTrack, const wxRect &rect, int y)
: mpTrack{ pTrack }
{
}
TimeTrackVZoomHandle::~TimeTrackVZoomHandle() = default;
void TimeTrackVZoomHandle::Enter( bool, AudacityProject* )
{
#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
mChangeHighlight = RefreshCode::RefreshCell;
#endif
}
UIHandle::Result TimeTrackVZoomHandle::Click
(const TrackPanelMouseEvent &, AudacityProject *)
{
return RefreshCode::RefreshNone;
}
UIHandle::Result TimeTrackVZoomHandle::Drag
(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
{
using namespace RefreshCode;
auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
if (!pTrack)
return Cancelled;
return RefreshNone;
}
HitTestPreview TimeTrackVZoomHandle::Preview
(const TrackPanelMouseState &st, AudacityProject *)
{
static wxCursor arrowCursor{ wxCURSOR_ARROW };
return {
XO("Right-click for menu."),
&arrowCursor
// , message
};
}
UIHandle::Result TimeTrackVZoomHandle::Release
(const TrackPanelMouseEvent &evt, AudacityProject *pProject,
wxWindow *pParent)
{
auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
using namespace RefreshCode;
if (!pTrack)
return RefreshNone;
const wxMouseEvent &event = evt.event;
const bool shiftDown = event.ShiftDown();
const bool rightUp = event.RightUp();
// Popup menu...
if (
rightUp &&
!(event.ShiftDown() || event.CmdDown()))
{
CommonTrackControls::InitMenuData data {
*pProject, pTrack.get(), pParent, RefreshNone
};
auto pMenu = PopupMenuTable::BuildMenu(pParent, &TimeTrackMenuTable::Instance(), &data);
pParent->PopupMenu(pMenu.get(), event.m_x, event.m_y);
}
return UpdateVRuler | RefreshAll;
}
UIHandle::Result TimeTrackVZoomHandle::Cancel(AudacityProject*)
{
// Cancel is implemented! And there is no initial state to restore,
// so just return a code.
return RefreshCode::RefreshAll;
}

View File

@ -0,0 +1,52 @@
/**********************************************************************
Audacity: A Digital Audio Editor
TimeTrackVZoomHandle.h
Paul Licameli split from TimeTrackVZoomHandle.h
**********************************************************************/
#ifndef __AUDACITY_TIMETRACK_VZOOM_HANDLE__
#define __AUDACITY_TIMETRACK_VZOOM_HANDLE__
#include "../../../UIHandle.h" // to inherit
class TimeTrack;
class TimeTrackVZoomHandle final : public UIHandle
{
TimeTrackVZoomHandle(const TimeTrackVZoomHandle&);
public:
explicit TimeTrackVZoomHandle
(const std::shared_ptr<TimeTrack> &pTrack, const wxRect &rect, int y);
TimeTrackVZoomHandle &operator=(const TimeTrackVZoomHandle&) = default;
~TimeTrackVZoomHandle() override;
void Enter( bool forward, AudacityProject * ) 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 *pProject) override;
private:
std::weak_ptr<TimeTrack> mpTrack;
};
#endif