1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-29 08:43:56 +01:00

TrackPanel no longer implements track selection click or rearrange drag...

... also implement ESC key for the drag
This commit is contained in:
Paul Licameli
2015-08-09 13:48:27 -04:00
committed by Paul Licameli
parent 46b97084eb
commit 703abe87bc
9 changed files with 330 additions and 190 deletions

View File

@@ -195,6 +195,8 @@ is time to refresh some aspect of the screen.
//This loads the appropriate set of cursors, depending on platform.
#include "../images/Cursors.h"
#include "widgets/ASlider.h"
DEFINE_EVENT_TYPE(EVT_TRACK_PANEL_TIMER)
/*
@@ -381,7 +383,6 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
mResizeCursor = std::make_unique<wxCursor>(wxCURSOR_SIZENS);
mRearrangeCursor = std::make_unique<wxCursor>(wxCURSOR_HAND);
mAdjustLeftSelectionCursor = std::make_unique<wxCursor>(wxCURSOR_POINT_LEFT);
mAdjustRightSelectionCursor = std::make_unique<wxCursor>(wxCURSOR_POINT_RIGHT);
@@ -873,7 +874,6 @@ void TrackPanel::HandleInterruptedDrag()
So this includes the cases:
IsAdjustingLabel,
IsRearranging,
IsStretching
*/
@@ -1123,9 +1123,6 @@ bool TrackPanel::SetCursorByActivity( )
case IsSelecting:
SetCursor(*mSelectCursor);
return true;
case IsRearranging:
SetCursor( unsafe ? *mDisabledCursor : *mRearrangeCursor);
return true;
case IsAdjustingLabel:
case IsSelectingLabelText:
return true;
@@ -1142,36 +1139,6 @@ bool TrackPanel::SetCursorByActivity( )
return false;
}
#if defined(__WXMAC__)
/* i18n-hint: Command names a modifier key on Macintosh keyboards */
#define CTRL_CLICK _("Command-Click")
#else
/* i18n-hint: Ctrl names a modifier key on Windows or Linux keyboards */
#define CTRL_CLICK _("Ctrl-Click")
#endif
/// When in the "label" (TrackInfo or vertical ruler), we can either vertical zoom or re-order tracks.
/// Dont't change cursor/tip to zoom if display is not waveform (either linear of dB) or Spectrum
void TrackPanel::SetCursorAndTipWhenInLabel( Track * ,
const wxMouseEvent &, wxString &tip )
{
if( GetTrackCount() > 1 ) {
// Set a status message if over TrackInfo.
//tip = _("Drag the track vertically to change the order of the tracks.");
// i18n-hint: %s is replaced by (translation of) 'Ctrl-Click' on windows, 'Command-Click' on Mac
tip = wxString::Format( _("%s to select or deselect track. Drag up or down to change track order."),
CTRL_CLICK );
SetCursor( *mArrowCursor );
}
else {
// Set a status message if over TrackInfo.
// i18n-hint: %s is replaced by (translation of) 'Ctrl-Click' on windows, 'Command-Click' on Mac
tip = wxString::Format( _("%s to select or deselect track."),
CTRL_CLICK );
SetCursor(*mArrowCursor);
}
}
/// When in the resize area we can adjust size or relative size.
void TrackPanel::SetCursorAndTipWhenInVResizeArea( bool bLinked, wxString &tip )
{
@@ -1492,9 +1459,6 @@ void TrackPanel::HandleCursor(wxMouseEvent & event)
pCursor = hitTest.preview.cursor;
if (pCursor)
SetCursor(*pCursor);
else if (foundCell.type == CellType::Label ||
foundCell.type == CellType::VRuler)
SetCursorAndTipWhenInLabel(track, event, tip);
}
// Is it a label track?
@@ -1671,11 +1635,12 @@ void TrackPanel::HandleSelect(wxMouseEvent & event)
}
// Counts tracks, counting stereo tracks as one track.
size_t TrackPanel::GetTrackCount(){
size_t TrackPanel::GetTrackCount() const
{
size_t count = 0;
TrackListIterator iter(GetTracks());
for (Track *t = iter.First(); t; t = iter.Next()) {
TrackListConstIterator iter(GetTracks());
for (auto t = iter.First(); t; t = iter.Next()) {
count += 1;
if( t->GetLinked() ){
t = iter.Next();
@@ -1687,11 +1652,12 @@ size_t TrackPanel::GetTrackCount(){
}
// Counts selected tracks, counting stereo tracks as one track.
size_t TrackPanel::GetSelectedTrackCount(){
size_t TrackPanel::GetSelectedTrackCount() const
{
size_t count = 0;
TrackListIterator iter(GetTracks());
for (Track *t = iter.First(); t; t = iter.Next()) {
TrackListConstIterator iter(GetTracks());
for (auto t = iter.First(); t; t = iter.Next()) {
count += t->GetSelected() ? 1:0;
if( t->GetLinked() ){
t = iter.Next();
@@ -3062,120 +3028,6 @@ bool TrackInfo::HideTopItem( const wxRect &rect, const wxRect &subRect,
return subRect.y + subRect.height - allowance >= rect.y + limit;
}
/// This handles when the user clicks on the "Label" area
/// of a track, ie the part with all the buttons and the drop
/// down menu, etc.
// That is, TrackInfo and vertical ruler rect.
void TrackPanel::HandleLabelClick(wxMouseEvent & event)
{
// AS: If not a click, ignore the mouse event.
if (!event.ButtonDown() && !event.ButtonDClick()) {
return;
}
// MIDI tracks use the right mouse button, but other tracks get confused
// if they see anything other than a left click.
bool isleft = event.Button(wxMOUSE_BTN_LEFT);
bool unsafe = IsUnsafe();
const auto foundCell = FindCell(event.m_x, event.m_y);
auto &t = foundCell.pTrack;
auto &rect = foundCell.rect;
if (!isleft) {
return;
}
// DM: If they weren't clicking on a particular part of a track label,
// deselect other tracks and select this one.
// JH: also, capture the current track for rearranging, so the user
// can drag the track up or down to swap it with others
if (!unsafe) {
mRearrangeCount = 0;
SetCapturedTrack(t, IsRearranging);
TrackPanel::CalculateRearrangingThresholds(event);
}
GetProject()->HandleListSelection(t, event.ShiftDown(), event.ControlDown(), !unsafe);
}
/// The user is dragging one of the tracks: change the track order
/// accordingly
void TrackPanel::HandleRearrange(wxMouseEvent & event)
{
// are we finishing the drag?
if (event.LeftUp()) {
if (mRearrangeCount != 0) {
wxString dir;
/* i18n-hint: a direction as in up or down.*/
dir = mRearrangeCount < 0 ? _("up") : _("down");
/* i18n-hint: will substitute name of track for first %s, "up" or "down" for the other.*/
MakeParentPushState(wxString::Format(_("Moved '%s' %s"),
mCapturedTrack->GetName().c_str(),
dir.c_str()),
_("Move Track"));
}
SetCapturedTrack(NULL);
SetCursor(*mArrowCursor);
return;
}
// probably harmless during play? However, we do disallow the click, so check this too.
bool unsafe = IsUnsafe();
if (unsafe)
return;
MixerBoard* pMixerBoard = this->GetMixerBoard(); // Update mixer board, too.
if (event.m_y < mMoveUpThreshold || event.m_y < 0) {
mTracks->MoveUp(mCapturedTrack);
--mRearrangeCount;
if (pMixerBoard)
if(auto pPlayable = dynamic_cast< const PlayableTrack* >( mCapturedTrack ))
pMixerBoard->MoveTrackCluster(pPlayable, true /* up */);
}
else if (event.m_y > mMoveDownThreshold || event.m_y > GetRect().GetHeight()) {
mTracks->MoveDown(mCapturedTrack);
++mRearrangeCount;
if (pMixerBoard)
if(auto pPlayable = dynamic_cast< const PlayableTrack* >( mCapturedTrack ))
pMixerBoard->MoveTrackCluster(pPlayable, false /* down */);
}
else
{
return;
}
// JH: if we moved up or down, recalculate the thresholds and make sure the
// track is fully on-screen.
TrackPanel::CalculateRearrangingThresholds(event);
EnsureVisible(mCapturedTrack);
}
/// Figure out how far the user must drag the mouse up or down
/// before the track will swap with the one above or below
void TrackPanel::CalculateRearrangingThresholds(wxMouseEvent & event)
{
wxASSERT(mCapturedTrack);
// JH: this will probably need to be tweaked a bit, I'm just
// not sure what formula will have the best feel for the
// user.
if (mTracks->CanMoveUp(mCapturedTrack))
mMoveUpThreshold =
event.m_y - mTracks->GetGroupHeight( mTracks->GetPrev(mCapturedTrack,true) );
else
mMoveUpThreshold = INT_MIN;
if (mTracks->CanMoveDown(mCapturedTrack))
mMoveDownThreshold =
event.m_y + mTracks->GetGroupHeight( mTracks->GetNext(mCapturedTrack,true) );
else
mMoveDownThreshold = INT_MAX;
}
/// ButtonDown means they just clicked and haven't released yet.
/// We use this opportunity to save which track they clicked on,
/// and the initial height of the track, so as they drag we can
@@ -3811,9 +3663,6 @@ try
HandleResize(event);
HandleCursor(event);
break;
case IsRearranging:
HandleRearrange(event);
break;
case IsAdjustingLabel:
// Reach this case only when the captured track was label
HandleGlyphDragRelease(static_cast<LabelTrack *>(mCapturedTrack), event);
@@ -4069,13 +3918,6 @@ void TrackPanel::HandleTrackSpecificMouseEvent(wxMouseEvent & event)
ProcessUIHandleResult(this, mRuler, pTrack, pTrack, refreshResult);
}
else {
if (foundCell.type == CellType::VRuler) {
}
else if (foundCell.type == CellType::Label)
HandleLabelClick(event);
}
HandleCursor(event);
return;
}