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