File indexing completed on 2025-02-23 04:34:24

0001 /**
0002  * \file progresswidget.h
0003  * Widget showing progress, similar to QProgressDialog.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 13 Jan 2017
0008  *
0009  * Copyright (C) 2017-2024  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #pragma once
0028 
0029 #include <QFrame>
0030 
0031 class QLabel;
0032 class QProgressBar;
0033 class QPushButton;
0034 
0035 /**
0036  * Widget showing progress, similar to QProgressDialog.
0037  */
0038 class ProgressWidget : public QFrame {
0039   Q_OBJECT
0040 public:
0041   /**
0042    * Constructor.
0043    * @param parent parent widget
0044    */
0045   explicit ProgressWidget(QWidget* parent = nullptr);
0046 
0047   /**
0048    * Destructor.
0049    */
0050   ~ProgressWidget() override = default;
0051 
0052   /**
0053    * Set title.
0054    * @param text title
0055    */
0056   void setWindowTitle(const QString& text);
0057 
0058   /**
0059    * Set text of label.
0060    * @param text label, default is empty
0061    */
0062   void setLabelText(const QString& text);
0063 
0064   /**
0065    * Set text of cancel button.
0066    * @param text button text, default is "Cancel"
0067    */
0068   void setCancelButtonText(const QString& text);
0069 
0070   /**
0071    * Set minimum value.
0072    * @param minimum minimum value, default is 0
0073    */
0074   void setMinimum(int minimum);
0075 
0076   /**
0077    * Set maximum value.
0078    * @param maximum maximum value, default is 100
0079    */
0080   void setMaximum(int maximum);
0081 
0082   /**
0083    * Set current amount of progress made.
0084    * @param value progress value
0085    */
0086   void setValue(int value);
0087 
0088   /**
0089    * Set value and maximum, but only if it changes the current percentage.
0090    *
0091    * This will have better performance by avoiding too many UI updates.
0092    *
0093    * @param value progress value
0094    * @param maximum maximum value
0095    */
0096   void setValueAndMaximum(int value, int maximum);
0097 
0098   /**
0099    * Set format used for progress text.
0100    * @param format format string, can contain %p, %v, %m for
0101    *               percentage, value, total
0102    */
0103   void setFormat(const QString& format);
0104 
0105   /**
0106    * Reset the progress widget.
0107    */
0108   void reset();
0109 
0110   /**
0111    * Check if the cancel button was pressed.
0112    * @return true if the progress widget was canceled.
0113    */
0114   bool wasCanceled() const { return m_wasCanceled; }
0115 
0116 signals:
0117   /**
0118    * Emitted when cancel is clicked.
0119    */
0120   void canceled();
0121 
0122 private slots:
0123   void onCancelClicked();
0124 
0125 private:
0126   QLabel* m_title;
0127   QLabel* m_label;
0128   QProgressBar* m_progress;
0129   QPushButton* m_cancelButton;
0130   int m_percentage;
0131   bool m_wasCanceled;
0132 };