mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-18 17:10:55 +02:00
Move many declarations into LabelTrackView & define its Copy()
This commit is contained in:
parent
604fbd0a2c
commit
e3efd52026
@ -36,6 +36,7 @@
|
||||
#include "Project.h"
|
||||
#include "ProjectWindow.h"
|
||||
#include "ViewInfo.h"
|
||||
#include "tracks/labeltrack/ui/LabelTrackView.h"
|
||||
#include "widgets/AudacityMessageBox.h"
|
||||
#include "widgets/ErrorDialog.h"
|
||||
#include "widgets/Grid.h"
|
||||
@ -421,7 +422,7 @@ bool LabelDialog::TransferDataFromWindow()
|
||||
|
||||
// Add the label to it
|
||||
lt->AddLabel(rd.selectedRegion, rd.title);
|
||||
lt->Unselect();
|
||||
LabelTrackView::Get( *lt ).SetSelectedIndex( -1 );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
File diff suppressed because it is too large
Load Diff
133
src/LabelTrack.h
133
src/LabelTrack.h
@ -17,21 +17,11 @@
|
||||
#include "Track.h"
|
||||
|
||||
|
||||
class wxFont;
|
||||
class wxKeyEvent;
|
||||
class wxMouseEvent;
|
||||
class wxTextFile;
|
||||
class wxWindow;
|
||||
class wxIcon;
|
||||
class wxBitmap;
|
||||
class TrackList;
|
||||
|
||||
class AudacityProject;
|
||||
class DirManager;
|
||||
class TimeWarper;
|
||||
class ZoomInfo;
|
||||
|
||||
class LabelTrackEvent;
|
||||
|
||||
struct LabelTrackHit;
|
||||
struct TrackPanelDrawingContext;
|
||||
@ -45,13 +35,6 @@ public:
|
||||
// Copies region but then overwrites other times
|
||||
LabelStruct(const SelectedRegion& region, double t0, double t1,
|
||||
const wxString &aTitle);
|
||||
void DrawLines( wxDC & dc, const wxRect & r) const;
|
||||
void DrawGlyphs
|
||||
( wxDC & dc, const wxRect & r, int GlyphLeft, int GlyphRight) const;
|
||||
void DrawText( wxDC & dc, const wxRect & r) const;
|
||||
void DrawTextBox( wxDC & dc, const wxRect & r) const;
|
||||
void DrawHighlight( wxDC & dc, int xPos1, int xPos2, int charHeight) const;
|
||||
void getXPos( wxDC & dc, int * xPos1, int cursorPos) const;
|
||||
const SelectedRegion &getSelectedRegion() const { return selectedRegion; }
|
||||
double getDuration() const { return selectedRegion.duration(); }
|
||||
double getT0() const { return selectedRegion.t0(); }
|
||||
@ -99,27 +82,11 @@ public:
|
||||
|
||||
using LabelArray = std::vector<LabelStruct>;
|
||||
|
||||
const int NUM_GLYPH_CONFIGS = 3;
|
||||
const int NUM_GLYPH_HIGHLIGHTS = 4;
|
||||
const int MAX_NUM_ROWS =80;
|
||||
|
||||
class AUDACITY_DLL_API LabelTrack final
|
||||
: public Track
|
||||
, public wxEvtHandler
|
||||
{
|
||||
friend class LabelTrackView;
|
||||
friend class LabelStruct;
|
||||
|
||||
public:
|
||||
static void DoEditLabels(
|
||||
AudacityProject &project, LabelTrack *lt = nullptr, int index = -1);
|
||||
static int DialogForLabelName(
|
||||
AudacityProject &project, const SelectedRegion& region,
|
||||
const wxString& initialValue, wxString& value);
|
||||
|
||||
bool IsTextSelected() const;
|
||||
|
||||
void CreateCustomGlyphs();
|
||||
LabelTrack(const std::shared_ptr<DirManager> &projDirManager);
|
||||
LabelTrack(const LabelTrack &orig);
|
||||
|
||||
@ -129,16 +96,6 @@ class AUDACITY_DLL_API LabelTrack final
|
||||
|
||||
void SetOffset(double dOffset) override;
|
||||
|
||||
static const int DefaultFontSize = 12;
|
||||
|
||||
static wxFont GetFont(const wxString &faceName, int size = DefaultFontSize);
|
||||
static void ResetFont();
|
||||
|
||||
void Draw( TrackPanelDrawingContext &context, const wxRect & r ) const;
|
||||
|
||||
int GetSelectedIndex() const;
|
||||
void SetSelectedIndex( int index );
|
||||
|
||||
double GetOffset() const override;
|
||||
double GetStartTime() const override;
|
||||
double GetEndTime() const override;
|
||||
@ -166,49 +123,10 @@ public:
|
||||
|
||||
void Silence(double t0, double t1) override;
|
||||
void InsertSilence(double t, double len) override;
|
||||
void OverGlyph(LabelTrackHit &hit, int x, int y) const;
|
||||
static wxBitmap & GetGlyph( int i);
|
||||
|
||||
|
||||
struct Flags {
|
||||
int mInitialCursorPos, mCurrentCursorPos, mSelIndex;
|
||||
bool mRightDragging, mDrawCursor;
|
||||
};
|
||||
void ResetFlags();
|
||||
Flags SaveFlags() const
|
||||
{
|
||||
return {
|
||||
mInitialCursorPos, mCurrentCursorPos, mSelIndex,
|
||||
mRightDragging, mDrawCursor
|
||||
};
|
||||
}
|
||||
void RestoreFlags( const Flags& flags );
|
||||
|
||||
int OverATextBox(int xx, int yy) const;
|
||||
bool OverTextBox(const LabelStruct *pLabel, int x, int y) const;
|
||||
bool CutSelectedText();
|
||||
bool CopySelectedText();
|
||||
bool PasteSelectedText(double sel0, double sel1);
|
||||
static bool IsTextClipSupported();
|
||||
|
||||
void HandleGlyphClick
|
||||
(LabelTrackHit &hit,
|
||||
const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo,
|
||||
SelectedRegion *newSel);
|
||||
void HandleTextClick
|
||||
(const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo,
|
||||
SelectedRegion *newSel);
|
||||
bool HandleGlyphDragRelease
|
||||
(LabelTrackHit &hit,
|
||||
const wxMouseEvent & evt, wxRect & r, const ZoomInfo &zoomInfo,
|
||||
SelectedRegion *newSel);
|
||||
void HandleTextDragRelease(const wxMouseEvent & evt);
|
||||
|
||||
void Import(wxTextFile & f);
|
||||
void Export(wxTextFile & f) const;
|
||||
|
||||
void Unselect();
|
||||
|
||||
// Whether any label box is selected -- not, whether the track is selected.
|
||||
bool HasSelection() const;
|
||||
|
||||
@ -219,23 +137,10 @@ public:
|
||||
void OnLabelAdded( const wxString &title, int pos );
|
||||
//This returns the index of the label we just added.
|
||||
int AddLabel(const SelectedRegion ®ion, const wxString &title);
|
||||
//And this tells us the index, if there is a label already there.
|
||||
int GetLabelIndex(double t, double t1);
|
||||
|
||||
//This deletes the label at given index.
|
||||
void DeleteLabel(int index);
|
||||
|
||||
//get current cursor position,
|
||||
// relative to the left edge of the track panel
|
||||
bool CalcCursorX(int * x) const;
|
||||
|
||||
void CalcHighlightXs(int *x1, int *x2) const;
|
||||
|
||||
void MayAdjustLabel
|
||||
( LabelTrackHit &hit,
|
||||
int iLabel, int iEdge, bool bAllowSwapping, double fNewTime);
|
||||
void MayMoveLabel( int iLabel, int iEdge, double fNewTime);
|
||||
|
||||
// This pastes labels without shifting existing ones
|
||||
bool PasteOver(double t, const Track *src);
|
||||
|
||||
@ -261,52 +166,14 @@ public:
|
||||
private:
|
||||
TrackKind GetKind() const override { return TrackKind::Label; }
|
||||
|
||||
void ShowContextMenu();
|
||||
void OnContextMenu(wxCommandEvent & evt);
|
||||
|
||||
mutable int mSelIndex; /// Keeps track of the currently selected label
|
||||
int mxMouseDisplacement; /// Displacement of mouse cursor from the centre being dragged.
|
||||
LabelArray mLabels;
|
||||
|
||||
static int mIconHeight;
|
||||
static int mIconWidth;
|
||||
static int mTextHeight;
|
||||
static bool mbGlyphsReady;
|
||||
static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS * NUM_GLYPH_HIGHLIGHTS];
|
||||
|
||||
static int mFontHeight;
|
||||
int mCurrentCursorPos; /// current cursor position
|
||||
int mInitialCursorPos; /// initial cursor position
|
||||
|
||||
bool mRightDragging; /// flag to tell if it's a valid dragging
|
||||
bool mDrawCursor; /// flag to tell if drawing the
|
||||
/// cursor or not
|
||||
int mRestoreFocus; /// Restore focus to this track
|
||||
/// when done editing
|
||||
|
||||
// Set in copied label tracks
|
||||
double mClipLen;
|
||||
|
||||
int miLastLabel; // used by FindNextLabel and FindPrevLabel
|
||||
|
||||
void ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const;
|
||||
void ComputeTextPosition(const wxRect & r, int index) const;
|
||||
|
||||
public:
|
||||
int FindCurrentCursorPosition(int xPos);
|
||||
void SetCurrentCursorPosition(int xPos);
|
||||
|
||||
private:
|
||||
void calculateFontHeight(wxDC & dc) const;
|
||||
void RemoveSelectedText();
|
||||
|
||||
void OnLabelAdded( LabelTrackEvent& );
|
||||
void OnLabelDeleted( LabelTrackEvent& );
|
||||
void OnLabelPermuted( LabelTrackEvent& );
|
||||
|
||||
static wxFont msFont;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<TrackView> DoGetView() override;
|
||||
std::shared_ptr<TrackControls> DoGetControls() override;
|
||||
};
|
||||
|
@ -88,7 +88,7 @@ audio tracks.
|
||||
#include "widgets/Ruler.h"
|
||||
#include "AllThemeResources.h"
|
||||
#include "TrackPanelDrawingContext.h"
|
||||
#include "tracks/ui/TrackView.h"
|
||||
#include "tracks/labeltrack/ui/LabelTrackView.h"
|
||||
|
||||
|
||||
#undef PROFILE_WAVEFORM
|
||||
@ -414,7 +414,7 @@ void TrackArt::DrawTrack(TrackPanelDrawingContext &context,
|
||||
},
|
||||
#endif // USE_MIDI
|
||||
[&](const LabelTrack *lt) {
|
||||
lt->Draw( context, rect );
|
||||
LabelTrackView::Get( *lt ).Draw( context, rect );
|
||||
},
|
||||
[&](const TimeTrack *tt) {
|
||||
DrawTimeTrack( context, tt, rect );
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "../Shuttle.h"
|
||||
#include "../ShuttleGui.h"
|
||||
#include "CommandContext.h"
|
||||
#include "../tracks/labeltrack/ui/LabelTrackView.h"
|
||||
|
||||
SetLabelCommand::SetLabelCommand()
|
||||
{
|
||||
@ -103,15 +104,16 @@ bool SetLabelCommand::Apply(const CommandContext & context)
|
||||
|
||||
// Only one label can be selected.
|
||||
if( bHasSelected ) {
|
||||
auto &view = LabelTrackView::Get( *labelTrack );
|
||||
if( mbSelected )
|
||||
{
|
||||
labelTrack->SetSelectedIndex( ii );
|
||||
view.SetSelectedIndex( ii );
|
||||
double t0 = pLabel->selectedRegion.t0();
|
||||
double t1 = pLabel->selectedRegion.t1();
|
||||
selectedRegion.setTimes( t0, t1);
|
||||
}
|
||||
else if( labelTrack->GetSelectedIndex() == ii )
|
||||
labelTrack->SetSelectedIndex( -1 );
|
||||
else if( view.GetSelectedIndex() == ii )
|
||||
view.SetSelectedIndex( -1 );
|
||||
}
|
||||
|
||||
labelTrack->SortLabels();
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "../prefs/PrefsDialog.h"
|
||||
#include "../prefs/SpectrogramSettings.h"
|
||||
#include "../prefs/WaveformSettings.h"
|
||||
#include "../tracks/labeltrack/ui/LabelTrackView.h"
|
||||
#include "../widgets/AudacityMessageBox.h"
|
||||
|
||||
// private helper classes and functions
|
||||
@ -49,7 +50,8 @@ bool DoPasteText(AudacityProject &project)
|
||||
if (pLabelTrack->HasSelection()) {
|
||||
|
||||
// Yes, so try pasting into it
|
||||
if (pLabelTrack->PasteSelectedText(selectedRegion.t0(),
|
||||
auto &view = LabelTrackView::Get( *pLabelTrack );
|
||||
if (view.PasteSelectedText(selectedRegion.t0(),
|
||||
selectedRegion.t1()))
|
||||
{
|
||||
ProjectHistory::Get( project )
|
||||
@ -57,7 +59,7 @@ bool DoPasteText(AudacityProject &project)
|
||||
|
||||
// Make sure caret is in view
|
||||
int x;
|
||||
if (pLabelTrack->CalcCursorX(&x)) {
|
||||
if (view.CalcCursorX(&x)) {
|
||||
trackPanel.ScrollIntoView(x);
|
||||
}
|
||||
|
||||
@ -301,7 +303,8 @@ void OnCut(const CommandContext &context)
|
||||
// in the middle of editing the label text and select "Cut".
|
||||
|
||||
for (auto lt : tracks.Selected< LabelTrack >()) {
|
||||
if (lt->CutSelectedText()) {
|
||||
auto &view = LabelTrackView::Get( *lt );
|
||||
if (view.CutSelectedText()) {
|
||||
trackPanel.Refresh(false);
|
||||
return;
|
||||
}
|
||||
@ -408,7 +411,8 @@ void OnCopy(const CommandContext &context)
|
||||
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
|
||||
|
||||
for (auto lt : tracks.Selected< LabelTrack >()) {
|
||||
if (lt->CopySelectedText()) {
|
||||
auto &view = LabelTrackView::Get( *lt );
|
||||
if (view.CopySelectedText()) {
|
||||
//trackPanel.Refresh(false);
|
||||
return;
|
||||
}
|
||||
@ -1095,7 +1099,9 @@ const ReservedCommandFlag
|
||||
CutCopyAvailableFlag{
|
||||
[](const AudacityProject &project){
|
||||
auto range = TrackList::Get( project ).Any<const LabelTrack>()
|
||||
+ &LabelTrack::IsTextSelected;
|
||||
+ [](const LabelTrack *pTrack){
|
||||
return LabelTrackView::Get( *pTrack ).IsTextSelected();
|
||||
};
|
||||
if ( !range.empty() )
|
||||
return true;
|
||||
|
||||
|
@ -32,7 +32,7 @@ int DoAddLabel(
|
||||
bool useDialog;
|
||||
gPrefs->Read(wxT("/GUI/DialogForNameNewLabel"), &useDialog, false);
|
||||
if (useDialog) {
|
||||
if (LabelTrack::DialogForLabelName(
|
||||
if (LabelTrackView::DialogForLabelName(
|
||||
project, region, wxEmptyString, title) == wxID_CANCEL)
|
||||
return -1; // index
|
||||
}
|
||||
@ -257,7 +257,7 @@ struct Handler : CommandHandlerObject {
|
||||
void OnEditLabels(const CommandContext &context)
|
||||
{
|
||||
auto &project = context.project;
|
||||
LabelTrack::DoEditLabels(project);
|
||||
LabelTrackView::DoEditLabels(project);
|
||||
}
|
||||
|
||||
void OnAddLabel(const CommandContext &context)
|
||||
@ -319,12 +319,13 @@ void OnPasteNewLabel(const CommandContext &context)
|
||||
// Unselect the last label, so we'll have just one active label when
|
||||
// we're done
|
||||
if (plt)
|
||||
plt->Unselect();
|
||||
LabelTrackView::Get( *plt ).SetSelectedIndex( -1 );
|
||||
|
||||
// Add a NEW label, paste into it
|
||||
// Paul L: copy whatever defines the selected region, not just times
|
||||
LabelTrackView::Get( *lt ).AddLabel(selectedRegion);
|
||||
if (lt->PasteSelectedText(selectedRegion.t0(),
|
||||
auto &view = LabelTrackView::Get( *lt );
|
||||
view.AddLabel(selectedRegion);
|
||||
if (view.PasteSelectedText(selectedRegion.t0(),
|
||||
selectedRegion.t1()))
|
||||
bPastedSomething = true;
|
||||
|
||||
|
@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp
|
||||
#include "../../../Audacity.h"
|
||||
#include "LabelDefaultClickHandle.h"
|
||||
|
||||
#include "LabelTrackView.h"
|
||||
#include "../../ui/TrackView.h"
|
||||
#include "../../../HitTestResult.h"
|
||||
#include "../../../LabelTrack.h"
|
||||
@ -26,7 +27,9 @@ LabelDefaultClickHandle::~LabelDefaultClickHandle()
|
||||
}
|
||||
|
||||
struct LabelDefaultClickHandle::LabelState {
|
||||
std::vector< std::pair< std::weak_ptr<LabelTrack>, LabelTrack::Flags > > mPairs;
|
||||
std::vector<
|
||||
std::pair< std::weak_ptr<LabelTrack>, LabelTrackView::Flags >
|
||||
> mPairs;
|
||||
};
|
||||
|
||||
void LabelDefaultClickHandle::SaveState( AudacityProject *pProject )
|
||||
@ -35,17 +38,21 @@ void LabelDefaultClickHandle::SaveState( AudacityProject *pProject )
|
||||
auto &pairs = mLabelState->mPairs;
|
||||
auto &tracks = TrackList::Get( *pProject );
|
||||
|
||||
for (auto lt : tracks.Any<LabelTrack>())
|
||||
for (auto lt : tracks.Any<LabelTrack>()) {
|
||||
auto &view = LabelTrackView::Get( *lt );
|
||||
pairs.push_back( std::make_pair(
|
||||
lt->SharedPointer<LabelTrack>(), lt->SaveFlags() ) );
|
||||
lt->SharedPointer<LabelTrack>(), view.SaveFlags() ) );
|
||||
}
|
||||
}
|
||||
|
||||
void LabelDefaultClickHandle::RestoreState( AudacityProject *pProject )
|
||||
{
|
||||
if ( mLabelState ) {
|
||||
for ( const auto &pair : mLabelState->mPairs )
|
||||
if (auto pLt = TrackList::Get( *pProject ).Lock(pair.first))
|
||||
pLt->RestoreFlags( pair.second );
|
||||
if (auto pLt = TrackList::Get( *pProject ).Lock(pair.first)) {
|
||||
auto &view = LabelTrackView::Get( *pLt );
|
||||
view.RestoreFlags( pair.second );
|
||||
}
|
||||
mLabelState.reset();
|
||||
}
|
||||
}
|
||||
@ -64,8 +71,9 @@ UIHandle::Result LabelDefaultClickHandle::Click
|
||||
const auto pLT = evt.pCell.get();
|
||||
for (auto lt : TrackList::Get( *pProject ).Any<LabelTrack>()) {
|
||||
if (pLT != &TrackView::Get( *lt )) {
|
||||
lt->ResetFlags();
|
||||
lt->Unselect();
|
||||
auto &view = LabelTrackView::Get( *lt );
|
||||
view.ResetFlags();
|
||||
view.SetSelectedIndex( -1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp
|
||||
#include "../../../Audacity.h"
|
||||
#include "LabelGlyphHandle.h"
|
||||
|
||||
#include "LabelTrackView.h"
|
||||
#include "../../../HitTestResult.h"
|
||||
#include "../../../LabelTrack.h"
|
||||
#include "../../../ProjectHistory.h"
|
||||
@ -102,7 +103,7 @@ UIHandlePtr LabelGlyphHandle::HitTest
|
||||
// LabelGlyphHandle can be copyable:
|
||||
auto pHit = std::make_shared<LabelTrackHit>( pLT );
|
||||
|
||||
pLT->OverGlyph(*pHit, state.m_x, state.m_y);
|
||||
LabelTrackView::Get( *pLT ).OverGlyph(*pHit, state.m_x, state.m_y);
|
||||
|
||||
// IF edge!=0 THEN we've set the cursor and we're done.
|
||||
// signal this by setting the tip.
|
||||
@ -128,8 +129,8 @@ UIHandle::Result LabelGlyphHandle::Click
|
||||
const wxMouseEvent &event = evt.event;
|
||||
|
||||
auto &viewInfo = ViewInfo::Get( *pProject );
|
||||
mpLT->HandleGlyphClick
|
||||
(*mpHit, event, mRect, viewInfo, &viewInfo.selectedRegion);
|
||||
LabelTrackView::Get( *mpLT ).HandleGlyphClick(
|
||||
*mpHit, event, mRect, viewInfo, &viewInfo.selectedRegion);
|
||||
|
||||
if (! mpHit->mIsAdjustingLabel )
|
||||
{
|
||||
@ -158,8 +159,8 @@ UIHandle::Result LabelGlyphHandle::Drag
|
||||
|
||||
const wxMouseEvent &event = evt.event;
|
||||
auto &viewInfo = ViewInfo::Get( *pProject );
|
||||
mpLT->HandleGlyphDragRelease
|
||||
(*mpHit, event, mRect, viewInfo, &viewInfo.selectedRegion);
|
||||
LabelTrackView::Get( *mpLT ).HandleGlyphDragRelease(
|
||||
*mpHit, event, mRect, viewInfo, &viewInfo.selectedRegion);
|
||||
|
||||
// Refresh all so that the change of selection is redrawn in all tracks
|
||||
return result | RefreshCode::RefreshAll | RefreshCode::DrawOverlays;
|
||||
@ -179,8 +180,8 @@ UIHandle::Result LabelGlyphHandle::Release
|
||||
|
||||
const wxMouseEvent &event = evt.event;
|
||||
auto &viewInfo = ViewInfo::Get( *pProject );
|
||||
if (mpLT->HandleGlyphDragRelease
|
||||
(*mpHit, event, mRect, viewInfo, &viewInfo.selectedRegion)) {
|
||||
if (LabelTrackView::Get( *mpLT ).HandleGlyphDragRelease(
|
||||
*mpHit, event, mRect, viewInfo, &viewInfo.selectedRegion)) {
|
||||
ProjectHistory::Get( *pProject ).PushState(_("Modified Label"),
|
||||
_("Label Edit"),
|
||||
UndoPush::CONSOLIDATE);
|
||||
|
@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp
|
||||
#include "../../../Audacity.h"
|
||||
#include "LabelTextHandle.h"
|
||||
|
||||
#include "LabelTrackView.h"
|
||||
#include "../../../Experimental.h"
|
||||
|
||||
#include "../../../HitTestResult.h"
|
||||
@ -54,7 +55,8 @@ UIHandlePtr LabelTextHandle::HitTest
|
||||
// If Control is down, let the select handle be hit instead
|
||||
int labelNum;
|
||||
if (!state.ControlDown() &&
|
||||
(labelNum = pLT->OverATextBox(state.m_x, state.m_y) ) >= 0) {
|
||||
(labelNum = LabelTrackView::Get( *pLT ).
|
||||
OverATextBox(state.m_x, state.m_y) ) >= 0) {
|
||||
auto result = std::make_shared<LabelTextHandle>( pLT, labelNum );
|
||||
result = AssignUIHandlePtr(holder, result);
|
||||
return result;
|
||||
@ -85,7 +87,8 @@ UIHandle::Result LabelTextHandle::Click
|
||||
auto &viewInfo = ViewInfo::Get( *pProject );
|
||||
|
||||
mSelectedRegion = viewInfo.selectedRegion;
|
||||
pLT->HandleTextClick( event, evt.rect, viewInfo, &viewInfo.selectedRegion );
|
||||
LabelTrackView::Get( *pLT )
|
||||
.HandleTextClick( event, evt.rect, viewInfo, &viewInfo.selectedRegion );
|
||||
|
||||
{
|
||||
// IF the user clicked a label, THEN select all other tracks by Label
|
||||
@ -122,8 +125,9 @@ UIHandle::Result LabelTextHandle::Drag
|
||||
|
||||
const wxMouseEvent &event = evt.event;
|
||||
auto pLT = TrackList::Get( *pProject ).Lock(mpLT);
|
||||
auto pView = pLT ? &LabelTrackView::Get( *pLT ) : nullptr;
|
||||
if(pLT)
|
||||
pLT->HandleTextDragRelease(event);
|
||||
pView->HandleTextDragRelease(event);
|
||||
|
||||
// locate the initial mouse position
|
||||
if (event.LeftIsDown()) {
|
||||
@ -132,9 +136,9 @@ UIHandle::Result LabelTextHandle::Drag
|
||||
mLabelTrackStartYPos = event.m_y;
|
||||
|
||||
if (pLT &&
|
||||
(pLT->GetSelectedIndex() != -1) &&
|
||||
pLT->OverTextBox(
|
||||
pLT->GetLabel(pLT->GetSelectedIndex()),
|
||||
(pView->GetSelectedIndex() != -1) &&
|
||||
pView->OverTextBox(
|
||||
pLT->GetLabel(pView->GetSelectedIndex()),
|
||||
mLabelTrackStartXPos,
|
||||
mLabelTrackStartYPos))
|
||||
mLabelTrackStartYPos = -1;
|
||||
@ -171,7 +175,7 @@ UIHandle::Result LabelTextHandle::Release
|
||||
const wxMouseEvent &event = evt.event;
|
||||
auto pLT = TrackList::Get( *pProject ).Lock(mpLT);
|
||||
if (pLT)
|
||||
pLT->HandleTextDragRelease(event);
|
||||
LabelTrackView::Get( *pLT ).HandleTextDragRelease(event);
|
||||
|
||||
// handle mouse left button up
|
||||
if (event.LeftUp())
|
||||
|
@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp
|
||||
#include "../../../Audacity.h"
|
||||
#include "LabelTrackControls.h"
|
||||
|
||||
#include "LabelTrackView.h"
|
||||
#include "../../../HitTestResult.h"
|
||||
#include "../../../LabelTrack.h"
|
||||
#include "../../../widgets/PopupMenuTable.h"
|
||||
@ -103,10 +104,10 @@ void LabelTrackMenuTable::OnSetFont(wxCommandEvent &)
|
||||
// Correct for empty facename, or bad preference file:
|
||||
// get the name of a really existing font, to highlight by default
|
||||
// in the list box
|
||||
facename = LabelTrack::GetFont(facename).GetFaceName();
|
||||
facename = LabelTrackView::GetFont(facename).GetFaceName();
|
||||
|
||||
long fontsize = gPrefs->Read(wxT("/GUI/LabelFontSize"),
|
||||
LabelTrack::DefaultFontSize);
|
||||
LabelTrackView::DefaultFontSize);
|
||||
|
||||
/* i18n-hint: (noun) This is the font for the label track.*/
|
||||
wxDialogWrapper dlg(mpData->pParent, wxID_ANY, wxString(_("Label Track Font")));
|
||||
@ -160,7 +161,7 @@ void LabelTrackMenuTable::OnSetFont(wxCommandEvent &)
|
||||
gPrefs->Write(wxT("/GUI/LabelFontSize"), sc->GetValue());
|
||||
gPrefs->Flush();
|
||||
|
||||
LabelTrack::ResetFont();
|
||||
LabelTrackView::ResetFont();
|
||||
|
||||
mpData->result = RefreshCode::RefreshAll;
|
||||
}
|
||||
|
@ -27,12 +27,61 @@ LabelTrackView::LabelTrackView( const std::shared_ptr<Track> &pTrack )
|
||||
// Default is to allow two rows so that NEW users get the
|
||||
// idea that labels can 'stack' when they would overlap.
|
||||
DoSetHeight(73);
|
||||
|
||||
ResetFont();
|
||||
CreateCustomGlyphs();
|
||||
ResetFlags();
|
||||
|
||||
// Events will be emitted by the track
|
||||
const auto pLabelTrack = FindLabelTrack();
|
||||
BindTo( pLabelTrack.get() );
|
||||
}
|
||||
|
||||
LabelTrackView::~LabelTrackView()
|
||||
{
|
||||
}
|
||||
|
||||
void LabelTrackView::Reparent( const std::shared_ptr<Track> &parent )
|
||||
{
|
||||
auto oldParent = FindLabelTrack();
|
||||
auto newParent = track_cast<LabelTrack*>(parent.get());
|
||||
if (oldParent.get() != newParent) {
|
||||
UnbindFrom( oldParent.get() );
|
||||
BindTo( newParent );
|
||||
}
|
||||
CommonTrackView::Reparent( parent );
|
||||
}
|
||||
|
||||
void LabelTrackView::BindTo( LabelTrack *pParent )
|
||||
{
|
||||
pParent->Bind(
|
||||
EVT_LABELTRACK_ADDITION, &LabelTrackView::OnLabelAdded, this );
|
||||
pParent->Bind(
|
||||
EVT_LABELTRACK_DELETION, &LabelTrackView::OnLabelDeleted, this );
|
||||
pParent->Bind(
|
||||
EVT_LABELTRACK_PERMUTED, &LabelTrackView::OnLabelPermuted, this );
|
||||
}
|
||||
|
||||
void LabelTrackView::UnbindFrom( LabelTrack *pParent )
|
||||
{
|
||||
pParent->Unbind(
|
||||
EVT_LABELTRACK_ADDITION, &LabelTrackView::OnLabelAdded, this );
|
||||
pParent->Unbind(
|
||||
EVT_LABELTRACK_DELETION, &LabelTrackView::OnLabelDeleted, this );
|
||||
pParent->Unbind(
|
||||
EVT_LABELTRACK_PERMUTED, &LabelTrackView::OnLabelPermuted, this );
|
||||
}
|
||||
|
||||
void LabelTrackView::Copy( const TrackView &other )
|
||||
{
|
||||
TrackView::Copy( other );
|
||||
|
||||
if ( const auto pOther = dynamic_cast< const LabelTrackView* >( &other ) ) {
|
||||
// only one field is important to preserve in undo/redo history
|
||||
mSelIndex = pOther->mSelIndex;
|
||||
}
|
||||
}
|
||||
|
||||
LabelTrackView &LabelTrackView::Get( LabelTrack &track )
|
||||
{
|
||||
return static_cast< LabelTrackView& >( TrackView::Get( track ) );
|
||||
|
@ -15,8 +15,23 @@ Paul Licameli split from class LabelTrack
|
||||
|
||||
class LabelGlyphHandle;
|
||||
class LabelTextHandle;
|
||||
class LabelDefaultClickHandle;
|
||||
class LabelStruct;
|
||||
class LabelTrack;
|
||||
struct LabelTrackEvent;
|
||||
struct LabelTrackHit;
|
||||
class SelectedRegion;
|
||||
struct TrackPanelDrawingContext;
|
||||
class ZoomInfo;
|
||||
|
||||
class wxBitmap;
|
||||
class wxCommandEvent;
|
||||
class wxDC;
|
||||
class wxMouseEvent;
|
||||
|
||||
constexpr int NUM_GLYPH_CONFIGS = 3;
|
||||
constexpr int NUM_GLYPH_HIGHLIGHTS = 4;
|
||||
constexpr int MAX_NUM_ROWS =80;
|
||||
|
||||
class wxKeyEvent;
|
||||
|
||||
@ -25,7 +40,11 @@ class LabelTrackView final : public CommonTrackView
|
||||
LabelTrackView( const LabelTrackView& ) = delete;
|
||||
LabelTrackView &operator=( const LabelTrackView& ) = delete;
|
||||
|
||||
void Reparent( const std::shared_ptr<Track> &parent ) override;
|
||||
|
||||
public:
|
||||
enum : int { DefaultFontSize = 12 };
|
||||
|
||||
explicit
|
||||
LabelTrackView( const std::shared_ptr<Track> &pTrack );
|
||||
~LabelTrackView() override;
|
||||
@ -43,6 +62,9 @@ public:
|
||||
int restoreFocus = -1);
|
||||
|
||||
private:
|
||||
void BindTo( LabelTrack *pParent );
|
||||
void UnbindFrom( LabelTrack *pParent );
|
||||
|
||||
std::vector<UIHandlePtr> DetailedHitTest
|
||||
(const TrackPanelMouseState &state,
|
||||
const AudacityProject *pProject, int currentTool, bool bMultiTool)
|
||||
@ -59,11 +81,149 @@ private:
|
||||
|
||||
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
|
||||
|
||||
// Preserve some view state too for undo/redo purposes
|
||||
void Copy( const TrackView &other ) override;
|
||||
|
||||
public:
|
||||
static void DoEditLabels(
|
||||
AudacityProject &project, LabelTrack *lt = nullptr, int index = -1);
|
||||
|
||||
static int DialogForLabelName(
|
||||
AudacityProject &project, const SelectedRegion& region,
|
||||
const wxString& initialValue, wxString& value);
|
||||
|
||||
bool IsTextSelected() const;
|
||||
|
||||
private:
|
||||
void CreateCustomGlyphs();
|
||||
|
||||
public:
|
||||
static wxFont GetFont(const wxString &faceName, int size = DefaultFontSize);
|
||||
static void ResetFont();
|
||||
|
||||
void Draw( TrackPanelDrawingContext &context, const wxRect & r ) const;
|
||||
|
||||
int GetSelectedIndex() const;
|
||||
void SetSelectedIndex( int index );
|
||||
|
||||
bool CutSelectedText();
|
||||
bool CopySelectedText();
|
||||
bool PasteSelectedText(double sel0, double sel1);
|
||||
|
||||
private:
|
||||
void OverGlyph(LabelTrackHit &hit, int x, int y) const;
|
||||
|
||||
static wxBitmap & GetGlyph( int i);
|
||||
|
||||
struct Flags {
|
||||
int mInitialCursorPos, mCurrentCursorPos, mSelIndex;
|
||||
bool mRightDragging, mDrawCursor;
|
||||
};
|
||||
|
||||
void ResetFlags();
|
||||
Flags SaveFlags() const
|
||||
{
|
||||
return {
|
||||
mInitialCursorPos, mCurrentCursorPos, mSelIndex,
|
||||
mRightDragging, mDrawCursor
|
||||
};
|
||||
}
|
||||
void RestoreFlags( const Flags& flags );
|
||||
|
||||
int OverATextBox(int xx, int yy) const;
|
||||
bool OverTextBox(const LabelStruct *pLabel, int x, int y) const;
|
||||
|
||||
static bool IsTextClipSupported();
|
||||
|
||||
void HandleGlyphClick
|
||||
(LabelTrackHit &hit,
|
||||
const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo,
|
||||
SelectedRegion *newSel);
|
||||
void HandleTextClick
|
||||
(const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo,
|
||||
SelectedRegion *newSel);
|
||||
bool HandleGlyphDragRelease
|
||||
(LabelTrackHit &hit,
|
||||
const wxMouseEvent & evt, wxRect & r, const ZoomInfo &zoomInfo,
|
||||
SelectedRegion *newSel);
|
||||
void HandleTextDragRelease(const wxMouseEvent & evt);
|
||||
|
||||
public:
|
||||
void AddedLabel( const wxString &title, int pos );
|
||||
void DeletedLabel( int index );
|
||||
|
||||
private:
|
||||
//And this tells us the index, if there is a label already there.
|
||||
int GetLabelIndex(double t, double t1);
|
||||
|
||||
public:
|
||||
//get current cursor position,
|
||||
// relative to the left edge of the track panel
|
||||
bool CalcCursorX(int * x) const;
|
||||
|
||||
private:
|
||||
void CalcHighlightXs(int *x1, int *x2) const;
|
||||
|
||||
void MayAdjustLabel
|
||||
( LabelTrackHit &hit,
|
||||
int iLabel, int iEdge, bool bAllowSwapping, double fNewTime);
|
||||
void MayMoveLabel( int iLabel, int iEdge, double fNewTime);
|
||||
|
||||
void ShowContextMenu();
|
||||
void OnContextMenu(wxCommandEvent & evt);
|
||||
|
||||
mutable int mSelIndex{-1}; /// Keeps track of the currently selected label
|
||||
int mxMouseDisplacement; /// Displacement of mouse cursor from the centre being dragged.
|
||||
|
||||
static int mIconHeight;
|
||||
static int mIconWidth;
|
||||
static int mTextHeight;
|
||||
|
||||
static bool mbGlyphsReady;
|
||||
static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS * NUM_GLYPH_HIGHLIGHTS];
|
||||
|
||||
static int mFontHeight;
|
||||
int mCurrentCursorPos; /// current cursor position
|
||||
int mInitialCursorPos; /// initial cursor position
|
||||
|
||||
bool mRightDragging; /// flag to tell if it's a valid dragging
|
||||
bool mDrawCursor; /// flag to tell if drawing the
|
||||
/// cursor or not
|
||||
int mRestoreFocus{-2}; /// Restore focus to this track
|
||||
/// when done editing
|
||||
|
||||
void ComputeTextPosition(const wxRect & r, int index) const;
|
||||
void ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const;
|
||||
static void DrawLines( wxDC & dc, const LabelStruct &ls, const wxRect & r);
|
||||
static void DrawGlyphs( wxDC & dc, const LabelStruct &ls, const wxRect & r,
|
||||
int GlyphLeft, int GlyphRight);
|
||||
static void DrawText( wxDC & dc, const LabelStruct &ls, const wxRect & r);
|
||||
static void DrawTextBox( wxDC & dc, const LabelStruct &ls, const wxRect & r);
|
||||
static void DrawHighlight(
|
||||
wxDC & dc, const LabelStruct &ls, int xPos1, int xPos2, int charHeight);
|
||||
|
||||
int FindCurrentCursorPosition(int xPos);
|
||||
void SetCurrentCursorPosition(int xPos);
|
||||
|
||||
static void calculateFontHeight(wxDC & dc);
|
||||
bool HasSelection() const;
|
||||
void RemoveSelectedText();
|
||||
|
||||
void OnLabelAdded( LabelTrackEvent& );
|
||||
void OnLabelDeleted( LabelTrackEvent& );
|
||||
void OnLabelPermuted( LabelTrackEvent& );
|
||||
|
||||
std::shared_ptr<LabelTrack> FindLabelTrack();
|
||||
std::shared_ptr<const LabelTrack> FindLabelTrack() const;
|
||||
|
||||
std::weak_ptr<LabelGlyphHandle> mGlyphHandle;
|
||||
std::weak_ptr<LabelTextHandle> mTextHandle;
|
||||
|
||||
static wxFont msFont;
|
||||
|
||||
friend LabelDefaultClickHandle;
|
||||
friend LabelGlyphHandle;
|
||||
friend LabelTextHandle;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
|
||||
std::shared_ptr<Track> DoFindTrack() override;
|
||||
|
||||
void Reparent( const std::shared_ptr<Track> &parent );
|
||||
virtual void Reparent( const std::shared_ptr<Track> &parent );
|
||||
|
||||
private:
|
||||
std::weak_ptr< Track > mwTrack;
|
||||
|
Loading…
x
Reference in New Issue
Block a user