Audacity  3.0.3
AdornedRulerPanel.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  AdornedRulerPanel.h
6 
7  Dominic Mazzoni
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_ADORNED_RULER_PANEL__
12 #define __AUDACITY_ADORNED_RULER_PANEL__
13 
14 #include "CellularPanel.h"
15 #include "widgets/Ruler.h" // member variable
16 #include "Prefs.h"
17 #include "ViewInfo.h" // for PlayRegion
18 
19 class AudacityProject;
20 struct SelectedRegionEvent;
21 class TrackList;
22 
23 // This is an Audacity Specific ruler panel.
24 class AUDACITY_DLL_API AdornedRulerPanel final
25 : public CellularPanel
26 , private PrefsListener
27 {
28 public:
29  static AdornedRulerPanel &Get( AudacityProject &project );
30  static const AdornedRulerPanel &Get( const AudacityProject &project );
31  static void Destroy( AudacityProject &project );
32 
34  wxWindow* parent,
35  wxWindowID id,
36  const wxPoint& pos = wxDefaultPosition,
37  const wxSize& size = wxDefaultSize,
38  ViewInfo *viewinfo = NULL);
39 
41 
42  void Refresh
43  (bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL)
44  override;
45 
46  bool AcceptsFocus() const override { return s_AcceptsFocus; }
47  bool AcceptsFocusFromKeyboard() const override { return true; }
48  void SetFocusFromKbd() override;
49 
50 public:
51  int GetRulerHeight() { return GetRulerHeight( ShowingScrubRuler() ); }
52  static int GetRulerHeight(bool showScrubBar);
53  wxRect GetInnerRect() const { return mInner; }
54 
55  void SetLeftOffset(int offset);
56 
57  void DrawSelection();
58 
59  void SetPlayRegion(double playRegionStart, double playRegionEnd);
60  void ClearPlayRegion();
61  void TogglePinnedHead();
62 
63  void GetMaxSize(wxCoord *width, wxCoord *height);
64 
65  void InvalidateRuler();
66 
67  void UpdatePrefs() override;
68  void ReCreateButtons();
69 
70  void UpdateQuickPlayPos(wxCoord &mousePosX, bool shiftDown);
71 
72  bool ShowingScrubRuler() const;
73  //void OnToggleScrubRulerFromMenu(wxCommandEvent& );
74  bool SetPanelSize();
75 
76  void DrawBothOverlays();
77 
78 
79 private:
80  void DoIdle();
81  void OnIdle( wxIdleEvent &evt );
82  void OnAudioStartStop(wxCommandEvent & evt);
83  void OnPaint(wxPaintEvent &evt);
84  void OnSize(wxSizeEvent &evt);
85  void OnThemeChange(wxCommandEvent& evt);
86  void OnSelectionChange(SelectedRegionEvent& evt);
87  void DoSelectionChange( const SelectedRegion &selectedRegion );
88  bool UpdateRects();
89  void HandleQPClick(wxMouseEvent &event, wxCoord mousePosX);
90  void HandleQPDrag(wxMouseEvent &event, wxCoord mousePosX);
91  void HandleQPRelease(wxMouseEvent &event);
92  void StartQPPlay(bool looped, bool cutPreview);
93 
94  void DoDrawBackground(wxDC * dc);
95  void DoDrawEdge(wxDC *dc);
96  void DoDrawMarks(wxDC * dc, bool /*text */ );
97  void DoDrawPlayRegion(wxDC * dc);
98 
99 public:
100  void DoDrawScrubIndicator(wxDC * dc, wxCoord xx, int width, bool scrub, bool seek);
101  void UpdateButtonStates();
102 
103 private:
104  static bool s_AcceptsFocus;
105  struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
106  using TempAllowFocus = std::unique_ptr<bool, Resetter>;
107 
108 public:
109  static TempAllowFocus TemporarilyAllowFocus();
110 
111 private:
112  enum class MenuChoice { QuickPlay, Scrub };
113  void ShowContextMenu( MenuChoice choice, const wxPoint *pPosition);
114 
115  double Pos2Time(int p, bool ignoreFisheye = false);
116  int Time2Pos(double t, bool ignoreFisheye = false);
117 
118  bool IsWithinMarker(int mousePosX, double markerTime);
119 
120 private:
121 
125 
126  wxRect mOuter;
127  wxRect mScrubZone;
128  wxRect mInner;
129 
130  int mLeftOffset; // Number of pixels before we hit the 'zero position'.
131 
132 
133  double mIndTime;
136 
138 
140 
142 
143  //
144  // Pop-up menu
145  //
146  void ShowMenu(const wxPoint & pos);
147  void ShowScrubMenu(const wxPoint & pos);
148  void DragSelection();
149  void HandleSnapping();
150  void OnSyncSelToQuickPlay(wxCommandEvent &evt);
151  //void OnTimelineToolTips(wxCommandEvent &evt);
152  void OnAutoScroll(wxCommandEvent &evt);
153  void OnTogglePlayRegion(wxCommandEvent &evt);
154  void OnClearPlayRegion(wxCommandEvent &evt);
155  void OnSetPlayRegionToSelection(wxCommandEvent &evt);
156 
157  void OnPinnedButton(wxCommandEvent & event);
158  void OnTogglePinnedState(wxCommandEvent & event);
159 
162 
168  mesSelectingPlayRegionRange
169  };
170 
172  double mLeftDownClickUnsnapped; // click position in seconds, before snap
173  double mLeftDownClick; // click position in seconds
175 
176  DECLARE_EVENT_TABLE()
177 
178  wxWindow *mButtons[3];
179  bool mNeedButtonUpdate { true };
180 
181  //
182  // CellularPanel implementation
183  //
184 
185  // Get the root object defining a recursive subdivision of the panel's
186  // area into cells
187  std::shared_ptr<TrackPanelNode> Root() override;
188 public:
189  AudacityProject * GetProject() const override;
190 private:
191  TrackPanelCell *GetFocusedCell() override;
192  void SetFocusedCell() override;
194  (TrackPanelCell *pClickedTrack, TrackPanelCell *pLatestCell,
195  unsigned refreshResult) override;
196 
197  void UpdateStatusMessage( const TranslatableString & ) override;
198 
199  void CreateOverlays();
200 
201  // Cooperating objects
202  class TrackPanelGuidelineOverlay;
203  std::shared_ptr<TrackPanelGuidelineOverlay> mOverlay;
204 
205  class ScrubbingRulerOverlay;
206 
207 private:
208  class CommonRulerHandle;
209  class QPHandle;
211  class ScrubbingHandle;
212 
213  class CommonCell;
214 
215  class QPCell;
216  std::shared_ptr<QPCell> mQPCell;
217 
218  class ScrubbingCell;
219  std::shared_ptr<ScrubbingCell> mScrubbingCell;
220 
221  // classes implementing subdivision for CellularPanel
222  struct Subgroup;
223  struct MainGroup;
224 
225  std::pair<double, double> mLastDrawnPlayRegion{};
226  bool mLastPlayRegionActive = false;
227  double mLastDrawnH{};
228  double mLastDrawnZoom{};
229  bool mDirtyPlayRegion{};
230 };
231 
232 #endif //define __AUDACITY_ADORNED_RULER_PANEL__
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
AdornedRulerPanel::mLeftOffset
int mLeftOffset
Definition: AdornedRulerPanel.h:130
AdornedRulerPanel::mTimelineToolTip
bool mTimelineToolTip
Definition: AdornedRulerPanel.h:161
SelectedRegionEvent
Definition: ViewInfo.h:28
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
CellularPanel::GetFocusedCell
virtual TrackPanelCell * GetFocusedCell()=0
AdornedRulerPanel::HandleQPRelease
void HandleQPRelease(wxMouseEvent &event)
SelectUtilities::ClearPlayRegion
void ClearPlayRegion(AudacityProject &project)
Definition: SelectUtilities.cpp:211
AdornedRulerPanel::mIsRecording
bool mIsRecording
Definition: AdornedRulerPanel.h:141
AdornedRulerPanel::mScrubZone
wxRect mScrubZone
Definition: AdornedRulerPanel.h:127
AdornedRulerPanel
This is an Audacity Specific ruler panel which additionally has border, selection markers,...
Definition: AdornedRulerPanel.h:27
AdornedRulerPanel::CommonCell
Definition: AdornedRulerPanel.cpp:500
AdornedRulerPanel::mTracks
TrackList * mTracks
Definition: AdornedRulerPanel.h:124
AdornedRulerPanel::TempAllowFocus
std::unique_ptr< bool, Resetter > TempAllowFocus
Definition: AdornedRulerPanel.h:106
AdornedRulerPanel::mQuickPlayPos
double mQuickPlayPos
Definition: AdornedRulerPanel.h:135
AdornedRulerPanel::mesNone
@ mesNone
Definition: AdornedRulerPanel.h:164
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1280
ViewInfo
Definition: ViewInfo.h:202
AdornedRulerPanel::ScrubbingHandle
Definition: AdornedRulerPanel.cpp:760
AdornedRulerPanel::mOldPlayRegion
PlayRegion mOldPlayRegion
Definition: AdornedRulerPanel.h:139
AdornedRulerPanel::GetInnerRect
wxRect GetInnerRect() const
Definition: AdornedRulerPanel.h:53
AdornedRulerPanel::mIndTime
double mIndTime
Definition: AdornedRulerPanel.h:133
AdornedRulerPanel::QPCell
Definition: AdornedRulerPanel.cpp:692
TrackInfo::UpdatePrefs
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
BackedPanel::OnSize
void OnSize(wxSizeEvent &event)
Definition: BackedPanel.cpp:71
AdornedRulerPanel::mQuickPlayPosUnsnapped
double mQuickPlayPosUnsnapped
Definition: AdornedRulerPanel.h:134
AdornedRulerPanel::mMouseEventState
MouseEventState mMouseEventState
Definition: AdornedRulerPanel.h:171
AdornedRulerPanel::mesDraggingPlayRegionEnd
@ mesDraggingPlayRegionEnd
Definition: AdornedRulerPanel.h:166
CellularPanel::ProcessUIHandleResult
virtual void ProcessUIHandleResult(TrackPanelCell *pClickedCell, TrackPanelCell *pLatestCell, unsigned refreshResult)=0
AdornedRulerPanel::HandleQPClick
void HandleQPClick(wxMouseEvent &event, wxCoord mousePosX)
PrefsListener
A listener notified of changes in preferences.
Definition: Prefs.h:392
CellularPanel::Root
virtual std::shared_ptr< TrackPanelNode > Root()=0
AdornedRulerPanel::Resetter
Definition: AdornedRulerPanel.h:105
AdornedRulerPanel::mOuter
wxRect mOuter
Definition: AdornedRulerPanel.h:126
AdornedRulerPanel::mScrubbingCell
std::shared_ptr< ScrubbingCell > mScrubbingCell
Definition: AdornedRulerPanel.h:218
AdornedRulerPanel::mLeftDownClick
double mLeftDownClick
Definition: AdornedRulerPanel.h:173
AdornedRulerPanel::mInner
wxRect mInner
Definition: AdornedRulerPanel.h:128
AdornedRulerPanel::AcceptsFocus
bool AcceptsFocus() const override
Definition: AdornedRulerPanel.h:46
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
AdornedRulerPanel::mQPCell
std::shared_ptr< QPCell > mQPCell
Definition: AdornedRulerPanel.h:215
Ruler
Used to display a Ruler.
Definition: Ruler.h:26
AdornedRulerPanel::Subgroup
Definition: AdornedRulerPanel.cpp:2246
TrackPanelCell
Definition: TrackPanelCell.h:74
AdornedRulerPanel::MenuChoice
MenuChoice
Definition: AdornedRulerPanel.h:112
AdornedRulerPanel::PlayRegionAdjustingHandle
Definition: AdornedRulerPanel.cpp:183
AdornedRulerPanel::MouseEventState
MouseEventState
Definition: AdornedRulerPanel.h:163
AdornedRulerPanel::s_AcceptsFocus
static bool s_AcceptsFocus
Definition: AdornedRulerPanel.h:104
PlayRegion
Definition: ViewInfo.h:129
AdornedRulerPanel::mLeftDownClickUnsnapped
double mLeftDownClickUnsnapped
Definition: AdornedRulerPanel.h:172
AdornedRulerPanel::ScrubbingRulerOverlay
Definition: AdornedRulerPanel.cpp:212
ViewInfo.h
Ruler.h
AdornedRulerPanel::HandleQPDrag
void HandleQPDrag(wxMouseEvent &event, wxCoord mousePosX)
AdornedRulerPanel::AcceptsFocusFromKeyboard
bool AcceptsFocusFromKeyboard() const override
Definition: AdornedRulerPanel.h:47
CellularPanel.h
CellularPanel::SetFocusedCell
virtual void SetFocusedCell()=0
CellularPanel::UpdateStatusMessage
virtual void UpdateStatusMessage(const TranslatableString &)=0
AdornedRulerPanel::mesSelectingPlayRegionClick
@ mesSelectingPlayRegionClick
Definition: AdornedRulerPanel.h:167
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
CellularPanel
Formerly part of TrackPanel, this abstract base class has no special knowledge of Track objects and i...
Definition: CellularPanel.h:34
AdornedRulerPanel::mPlayRegionDragsSelection
bool mPlayRegionDragsSelection
Definition: AdornedRulerPanel.h:160
AdornedRulerPanel::CommonRulerHandle
Definition: AdornedRulerPanel.cpp:116
AdornedRulerPanel::mProject
AudacityProject *const mProject
Definition: AdornedRulerPanel.h:123
AdornedRulerPanel::mIsSnapped
bool mIsSnapped
Definition: AdornedRulerPanel.h:137
AdornedRulerPanel::mOverlay
std::shared_ptr< TrackPanelGuidelineOverlay > mOverlay
Definition: AdornedRulerPanel.h:202
AdornedRulerPanel::ScrubbingCell
Definition: AdornedRulerPanel.cpp:837
AdornedRulerPanel::mRuler
Ruler mRuler
Definition: AdornedRulerPanel.h:122
AdornedRulerPanel::mesDraggingPlayRegionStart
@ mesDraggingPlayRegionStart
Definition: AdornedRulerPanel.h:165
Prefs.h
AdornedRulerPanel::GetRulerHeight
int GetRulerHeight()
Definition: AdornedRulerPanel.h:51
AdornedRulerPanel::MainGroup
Definition: AdornedRulerPanel.cpp:2266
CellularPanel::GetProject
virtual AudacityProject * GetProject() const =0
AdornedRulerPanel::mIsDragging
bool mIsDragging
Definition: AdornedRulerPanel.h:174
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35