17#include <wx/dcbuffer.h>
18#include <wx/graphics.h>
19#include <wx/statusbr.h>
32#if wxUSE_ACCESSIBILITY
44 {
return std::make_shared<CloudSyncStatusField>(
project); }
95 std::make_unique<CloudSyncStatusBarFieldItem>(),
123 SetBackgroundStyle(wxBG_STYLE_PAINT);
126 Bind(wxEVT_PAINT, [
this](
auto&) {
OnPaint(); });
128#if wxUSE_ACCESSIBILITY
181 wxAutoBufferedPaintDC dc(
this);
182 std::unique_ptr<wxGraphicsContext> gc(wxGraphicsContext::Create(dc));
186 const wxSize widgetSize = GetSize();
187 const wxSize bitmapSize = bitmap->GetSize();
189 gc->SetBrush(wxBrush(GetBackgroundColour()));
190 gc->DrawRectangle(0, 0, widgetSize.x, widgetSize.y);
192 *bitmap,
Padding, (widgetSize.y - bitmapSize.y) / 2.0, bitmapSize.x,
200 gc->SetFont(GetFont(), GetForegroundColour());
206 gc->SetAntialiasMode(wxANTIALIAS_NONE);
210 const auto progressFilledPen =
211 gc->CreatePen(wxGraphicsPenInfo {}
212 .Colour(wxColour(0xc3c3c3))
215 const auto progressEmptyPen =
216 gc->CreatePen(wxGraphicsPenInfo {}
217 .Colour(wxColour(0xc3c3c3))
219 const auto zeroPen = gc->CreatePen(
220 wxGraphicsPenInfo {}.Width(0).Style(wxPENSTYLE_TRANSPARENT));
222 const auto progressFilledBrush = gc->CreateBrush(wxColour(0x3cf03c));
223 const auto progressEmptyBrush = gc->CreateBrush(wxColour(0xffffff));
225 const auto progressBarBorderLeft =
228 const auto progressBarBorderRight =
231 const auto progressBarBorderTop =
234 const auto progressBarBorderBottom =
237 const auto filledWidth =
240 const auto progressBarFillLeft =
242 const auto progressBarFillRight = progressBarFillLeft + filledWidth;
244 const auto progressBarEmptyLeft =
245 progressBarFillRight + (progress > 0 ? 1 : 0);
246 const auto progressBarEmptyRight =
253 gc->SetPen(progressEmptyPen);
255 gc->SetPen(progressFilledPen);
258 progressBarBorderLeft, progressBarBorderTop, progressBarBorderLeft,
259 progressBarBorderBottom);
264 progressBarFillLeft, progressBarBorderTop, progressBarFillRight,
265 progressBarBorderTop);
268 progressBarFillLeft, progressBarBorderBottom, progressBarFillRight,
269 progressBarBorderBottom);
272 gc->SetBrush(progressFilledBrush);
276 progressBarFillRight - progressBarFillLeft + 1, filledHeight);
281 gc->SetPen(progressEmptyPen);
284 progressBarEmptyLeft, progressBarBorderTop, progressBarEmptyRight,
285 progressBarBorderTop);
288 progressBarEmptyLeft, progressBarBorderBottom,
289 progressBarEmptyRight, progressBarBorderBottom);
292 gc->SetBrush(progressEmptyBrush);
296 progressBarEmptyRight - progressBarEmptyLeft + 1, filledHeight);
300 gc->SetPen(progressFilledPen);
302 gc->SetPen(progressEmptyPen);
305 progressBarBorderRight, progressBarBorderTop, progressBarBorderRight,
306 progressBarBorderBottom);
342 , mCloudStatusChangedSubscription { mCloudExtension.SubscribeStatusChanged(
348CloudSyncStatusField::~CloudSyncStatusField() =
default;
361int CloudSyncStatusField::GetWidth()
const
363 return mCloudExtension.IsCloudProject() ?
364 (GetStatusWidget().GetPreferredWidth(
mState) +
371 GetStatusWidget().SetRect(rect);
374bool CloudSyncStatusField::IsVisible()
const
376 return mState != State::Hidden;
384void CloudSyncStatusField::MarkDirty()
386 auto field =
dynamic_cast<CloudSyncStatusBarFieldItem*
>(
390 field->MarkDirty(mProject);
392 auto& statusWidget = GetStatusWidget();
394 statusWidget.Show(
mState != State::Hidden);
395 statusWidget.UpdateName();
397 if (statusWidget.GetParent())
398 statusWidget.GetParent()->Refresh();
400 statusWidget.Refresh();
403void CloudSyncStatusField::OnCloudStatusChanged(
410 case ProjectSyncStatus::Local:
411 return State::Hidden;
412 case ProjectSyncStatus::Unsynced:
414 case ProjectSyncStatus::Synced:
415 return State::Synced;
416 case ProjectSyncStatus::Failed:
417 return State::Failed;
418 case ProjectSyncStatus::Syncing:
419 return State::Uploading;
421 return State::Hidden;
425 if (
mState == State::Uploading)
426 mProgress =
static_cast<int>(message.
Progress * 100.0);
438 mStatusWidget->Show(mCloudExtension.IsCloudProject());
441 return *mStatusWidget;
445CloudSyncStatusField::GetStatusWidget()
const
StatusBarField RateStatusBarField()
ID of the third field in the status bar. This field is used to display the current rate.
static void OnSize(wxSizeEvent &evt)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
An explicitly nonlocalized string, not meant for the user to see.
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
A listener notified of changes in preferences.
static ProjectWindow & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Abstract base class for status bar fields.
wxBitmap & Bitmap(int iIndex)
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
CloudSyncStatusField(AudacityProject &project)
void OnCloudStatusChanged(const CloudStatusChangedMessage &extension)
static CloudSyncStatusField & Get(AudacityProject &project)
TranslatableString GetText() const
void OnSize(const wxRect &rect)
TranslatableString GetText(const AudacityProject &project) const override
Retrieves the current text of the field.
bool IsVisible(const AudacityProject &project) const override
Returns true if the field is visible in the status bar of the given project.
void MarkDirty(const AudacityProject &project)
CloudSyncStatusBarFieldItem()
int GetDefaultWidth(const AudacityProject &project) const override
void SetText(AudacityProject &project, const TranslatableString &msg) override
Sets the current text of the field.
void OnSize(AudacityProject &project) override
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
ProjectFileIOExtensionRegistry::Extension extension
const AttachedProjectObjects::RegisteredFactory key
const auto ProgressBarHeight
const auto ProgressBarBorderSize
const auto StatusFieldPadding
const auto ProgressBarWidth
StatusBarFieldItemRegistrator rateStatusBarField
const auto CloudSyncFailedMessage
const auto CloudSyncProgressMessage
const StatusBarField FieldId
static StatusBarFieldItem * Get(const StatusBarField &identifier)
Returns the field with the given identifier or nullptr if field is not present.
static int GetFieldIndex(const AudacityProject &project, const StatusBarField &identifier)
Returns the zero based index of the field or -1 if field is not present.