1/* 2 * Copyright 2017 Julian Harnath <julian.harnath@rwth-aachen.de> 3 * Copyright 2020-2021 Andrew Lindesay <apl@lindesay.co.nz> 4 * All rights reserved. Distributed under the terms of the MIT license. 5 */ 6 7 8#include "WorkStatusView.h" 9 10#include <CardLayout.h> 11#include <Catalog.h> 12#include <LayoutBuilder.h> 13#include <SeparatorView.h> 14#include <StatusBar.h> 15#include <StringFormat.h> 16#include <StringView.h> 17 18#include <stdio.h> 19 20#include "BarberPole.h" 21 22 23#undef B_TRANSLATION_CONTEXT 24#define B_TRANSLATION_CONTEXT "WorkStatusView" 25 26#define VIEW_INDEX_BARBER_POLE (int32) 0 27#define VIEW_INDEX_PROGRESS_BAR (int32) 1 28 29 30static const BSize kStatusBarSize = BSize(100,20); 31 32 33WorkStatusView::WorkStatusView(const char* name) 34 : 35 BView(name, 0), 36 fProgressBar(new BStatusBar("progress bar")), 37 fBarberPole(new BarberPole("barber pole")), 38 fProgressLayout(new BCardLayout()), 39 fProgressView(new BView("progress view", 0)), 40 fStatusText(new BStringView("status text", NULL)) 41{ 42 fProgressView->SetLayout(fProgressLayout); 43 fProgressLayout->AddView(fBarberPole); 44 fProgressLayout->AddView(fProgressBar); 45 46 fBarberPole->SetExplicitSize(kStatusBarSize); 47 fProgressBar->SetMaxValue(1.0f); 48 fProgressBar->SetBarHeight(kStatusBarSize.Height()); 49 fProgressBar->SetExplicitSize(kStatusBarSize); 50 51 fStatusText->SetFontSize(be_plain_font->Size() * 0.9f); 52 53 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 54 .Add(new BSeparatorView()) 55 .AddGroup(B_HORIZONTAL) 56 .SetInsets(5, 2, 5, 2) 57 .Add(fProgressLayout, 0.2f) 58 .Add(fStatusText) 59 .AddGlue() 60 .End() 61 ; 62} 63 64 65WorkStatusView::~WorkStatusView() 66{ 67} 68 69 70void 71WorkStatusView::SetBusy(const BString& text) 72{ 73 SetText(text); 74 SetBusy(); 75} 76 77 78void 79WorkStatusView::SetBusy() 80{ 81 fBarberPole->Start(); 82 if (fProgressLayout->VisibleIndex() != VIEW_INDEX_BARBER_POLE) 83 fProgressLayout->SetVisibleItem(VIEW_INDEX_BARBER_POLE); 84} 85 86 87void 88WorkStatusView::SetIdle() 89{ 90 fBarberPole->Stop(); 91 fProgressLayout->SetVisibleItem(VIEW_INDEX_BARBER_POLE); 92 SetText(NULL); 93} 94 95 96void 97WorkStatusView::SetProgress(float value) 98{ 99 fProgressBar->SetTo(value); 100 if (fProgressLayout->VisibleIndex() != VIEW_INDEX_PROGRESS_BAR) 101 fProgressLayout->SetVisibleItem(VIEW_INDEX_PROGRESS_BAR); 102} 103 104 105void 106WorkStatusView::SetText(const BString& text) 107{ 108 fStatusText->SetText(text); 109} 110