diff --git a/src/widgets/statuswidget.cpp b/src/widgets/statuswidget.cpp index 944a71b..45d430f 100644 --- a/src/widgets/statuswidget.cpp +++ b/src/widgets/statuswidget.cpp @@ -1,118 +1,118 @@ /* AtCore Test Client Copyright (C) <2018> Author: Chris Rizzitello - rizzitello@kde.org This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include "statuswidget.h" StatusWidget::StatusWidget(bool showStop, QWidget *parent) : QWidget(parent) { //first create the item for the print Progress. auto hBoxLayout = new QHBoxLayout; printingProgress = new QProgressBar; printingProgress->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); hBoxLayout->addWidget(printingProgress); if (showStop) { auto newButton = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); connect(newButton, &QPushButton::clicked, this, [this] { emit stopPressed(); }); hBoxLayout->addWidget(newButton); } lblTime = new QLabel(QStringLiteral("00:00:00")); lblTime->setAlignment(Qt::AlignHCenter); auto newLabel = new QLabel(QStringLiteral(" / ")); lblTimeLeft = new QLabel(QStringLiteral("??:??:??")); lblTimeLeft->setAlignment(Qt::AlignHCenter); hBoxLayout->addWidget(lblTime); hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(lblTimeLeft); printProgressWidget = new QWidget(); printProgressWidget->setLayout(hBoxLayout); //Then Create the full bar. newLabel = new QLabel(tr("AtCore State:")); lblState = new QLabel(tr("Not Connected")); lblSd = new QLabel(); spacer = new QSpacerItem(10, 20, QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(lblState); hBoxLayout->addSpacerItem(new QSpacerItem(5, 20, QSizePolicy::Fixed)); hBoxLayout->addWidget(lblSd); hBoxLayout->addSpacerItem(spacer); hBoxLayout->addWidget(printProgressWidget); setLayout(hBoxLayout); printTime = new QTime(); printTimer = new QTimer(); printTimer->setInterval(1000); printTimer->setSingleShot(false); connect(printTimer, &QTimer::timeout, this, &StatusWidget::updatePrintTime); } void StatusWidget::setSD(bool hasSd) { QString labelText = hasSd ? tr("SD") : QString(); lblSd->setText(labelText); } void StatusWidget::setState(const QString &state) { lblState->setText(state); } void StatusWidget::showPrintArea(bool visible) { printProgressWidget->setVisible(visible); if (visible) { spacer->changeSize(10, 20, QSizePolicy::Fixed, QSizePolicy::Fixed); printTime->start(); printTimer->start(); } else { printTimer->stop(); spacer->changeSize(10, 20, QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); } } void StatusWidget::updatePrintTime() { QTime temp(0, 0, 0); lblTime->setText(temp.addMSecs(printTime->elapsed()).toString(QStringLiteral("hh:mm:ss"))); } -void StatusWidget::updatePrintProgress(const float &progress) +void StatusWidget::updatePrintProgress(const int progress) { printingProgress->setValue(progress); if (progress >= 1) { QTime temp(0, 0, 0); lblTimeLeft->setText(temp.addMSecs((100 - progress) * (printTime->elapsed() / progress)).toString(QStringLiteral("hh:mm:ss"))); } else { lblTimeLeft->setText(QStringLiteral("??:??:??")); } } diff --git a/src/widgets/statuswidget.h b/src/widgets/statuswidget.h index 54a2467..4544c80 100644 --- a/src/widgets/statuswidget.h +++ b/src/widgets/statuswidget.h @@ -1,76 +1,76 @@ /* AtCore Test Client Copyright (C) <2018> Author: Chris Rizzitello - rizzitello@kde.org This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #pragma once #include #include #include #include #include #include "atcorewidgets_export.h" /** * @brief The StatusWidget class Status Bar information for atcore */ class ATCOREWIDGETS_EXPORT StatusWidget : public QWidget { Q_OBJECT public: /** * @brief Make A new Status widget * @param showStop: Set False if your client has the print job stop in another widget. * @param parent: parent of this widget. */ StatusWidget(bool showStop = true, QWidget *parent = nullptr); /** * @brief Set if the status area should show SD card inserted. * @param hasSd */ void setSD(bool hasSd); /** * @brief Set the State String * @param state: String to be shown */ void setState(const QString &state); /** * @brief Show or hide the Print progress and time * @param visible : true for show */ void showPrintArea(bool visible); /** * @brief Update the progres to the new progress * @param progress: new progress. */ - void updatePrintProgress(const float &progress); + void updatePrintProgress(const int progress); signals: void stopPressed(); private slots: void updatePrintTime(); private: QLabel *lblState = nullptr; QLabel *lblSd = nullptr; QLabel *lblTime = nullptr; QLabel *lblTimeLeft = nullptr; QTime *printTime = nullptr; QTimer *printTimer = nullptr; QSpacerItem *spacer = nullptr; QProgressBar *printingProgress = nullptr; QWidget *printProgressWidget = nullptr; };