1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "windowstatusbar.h"
6#include "progressbar.h"
7#include "common/common.h"
8
9class WindowStatusBarPrivate
10{
11 friend class WindowStatusBar;
12 ProgressBar *progressBar = nullptr;
13 ElidedLabel *messageLabel = nullptr;
14};
15
16WindowStatusBar::WindowStatusBar(QWidget *parent)
17 : QStatusBar(parent)
18 , d(new WindowStatusBarPrivate())
19{
20 d->progressBar = new ProgressBar;
21 d->progressBar->setFixedSize(80, 10);
22 d->messageLabel = new ElidedLabel;
23 d->messageLabel->setMaximumWidth(200);
24
25 this->addPermanentWidget(d->messageLabel);
26 this->addPermanentWidget(d->progressBar);
27 hideProgress();
28}
29
30WindowStatusBar::~WindowStatusBar()
31{
32 if (d) {
33 delete d;
34 }
35}
36
37void WindowStatusBar::setPercentage(int percentage)
38{
39 d->progressBar->setPercentage(percentage);
40}
41
42void WindowStatusBar::setMessage(const QString &message)
43{
44 d->messageLabel->setText(message);
45 d->messageLabel->setToolTip(message);
46}
47
48void WindowStatusBar::hideProgress()
49{
50 d->progressBar->hide();
51 d->messageLabel->hide();
52}
53
54void WindowStatusBar::showProgress()
55{
56 d->progressBar->show();
57 d->messageLabel->show();
58}
59
60bool WindowStatusBar::progressIsHidden()
61{
62 return d->progressBar->isHidden()
63 && d->messageLabel->isHidden();
64}
65