| 1 |
/* |
| 2 |
* libkysdk-qtwidgets's Library |
| 3 |
* |
| 4 |
* Copyright (C) 2023, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhen Sun <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef KPROGRESSDIALOG_H |
| 24 |
#define KPROGRESSDIALOG_H |
| 25 |
|
| 26 |
#include "gui_g.h" |
| 27 |
#include "kdialog.h" |
| 28 |
#include "kiconbar.h" |
| 29 |
#include "kwidget.h" |
| 30 |
#include "kwindowbuttonbar.h" |
| 31 |
#include "themeController.h" |
| 32 |
#include <QBoxLayout> |
| 33 |
#include <QDialog> |
| 34 |
#include <QLabel> |
| 35 |
#include <QProgressBar> |
| 36 |
|
| 37 |
namespace kdk |
| 38 |
{ |
| 39 |
|
| 40 |
/** @defgroup DialogBoxModule |
| 41 |
* @{ |
| 42 |
*/ |
| 43 |
|
| 44 |
/** |
| 45 |
* @brief 支持三种样式 |
| 46 |
* @since 1.0.0 |
| 47 |
*/ |
| 48 |
enum BarType { |
| 49 |
ScrollBar, |
| 50 |
NothingBar, |
| 51 |
NormalBar, |
| 52 |
SpeedBar |
| 53 |
}; |
| 54 |
|
| 55 |
class KProgressDialogPrivate; |
| 56 |
|
| 57 |
/** |
| 58 |
* @brief 进度对话框,会实时显示当前进度 |
| 59 |
*/ |
| 60 |
class GUI_EXPORT KProgressDialog : public KDialog |
| 61 |
{ |
| 62 |
Q_OBJECT |
| 63 |
|
| 64 |
public: |
| 65 |
explicit KProgressDialog(QWidget *parent = nullptr); |
| 66 |
KProgressDialog(const QString &labelText, const QString &cancelButtonText = "cancel", |
| 67 |
int minimum = 0, int maximum = 100, QWidget *parent = nullptr); |
| 68 |
~KProgressDialog(); |
| 69 |
|
| 70 |
/** |
| 71 |
* @brief 设置提示文字 |
| 72 |
* @param label |
| 73 |
*/ |
| 74 |
void setLabel(QLabel *label); |
| 75 |
|
| 76 |
/** |
| 77 |
* @brief 设置取消按钮 |
| 78 |
* @param button |
| 79 |
*/ |
| 80 |
void setCancelButton(QPushButton *button); |
| 81 |
|
| 82 |
/** |
| 83 |
* @brief 设置进度条 |
| 84 |
* @param bar |
| 85 |
*/ |
| 86 |
void setBar(QProgressBar *bar); |
| 87 |
|
| 88 |
/** |
| 89 |
* @brief 设置detail的后缀 |
| 90 |
* @param suffix |
| 91 |
*/ |
| 92 |
void setSuffix(const QString &suffix); |
| 93 |
|
| 94 |
void setSuffix(const QString &numerator, const QString &denominator); |
| 95 |
|
| 96 |
void setSpeed(const float &speed); |
| 97 |
|
| 98 |
/** |
| 99 |
* @brief 设置是否显示详细信息 |
| 100 |
* @param flag |
| 101 |
*/ |
| 102 |
void setShowDetail(bool flag); |
| 103 |
|
| 104 |
/** |
| 105 |
* @brief 返回最小值 |
| 106 |
* @return |
| 107 |
*/ |
| 108 |
int minimum() const; |
| 109 |
|
| 110 |
/** |
| 111 |
* @brief 返回最大值 |
| 112 |
* @return |
| 113 |
*/ |
| 114 |
int maximum() const; |
| 115 |
|
| 116 |
/** |
| 117 |
* @brief 返回当前值 |
| 118 |
* @return |
| 119 |
*/ |
| 120 |
int value() const; |
| 121 |
|
| 122 |
/** |
| 123 |
* @brief 返回提示内容 |
| 124 |
* @return |
| 125 |
*/ |
| 126 |
QString labelText() const; |
| 127 |
|
| 128 |
/** |
| 129 |
* @brief 设置自动重置 |
| 130 |
* @param reset |
| 131 |
*/ |
| 132 |
void setAutoReset(bool reset); |
| 133 |
|
| 134 |
/** |
| 135 |
* @brief 返回是否自动重置 |
| 136 |
* @return |
| 137 |
*/ |
| 138 |
bool autoReset() const; |
| 139 |
|
| 140 |
/** |
| 141 |
* @brief 设置是否自动关闭对话框 |
| 142 |
* @param close |
| 143 |
*/ |
| 144 |
void setAutoClose(bool close); |
| 145 |
|
| 146 |
/** |
| 147 |
* @brief 返回是否自动关闭对话框 |
| 148 |
* @return |
| 149 |
*/ |
| 150 |
bool autoClose() const; |
| 151 |
|
| 152 |
/** |
| 153 |
* @brief 获取进度条 |
| 154 |
* @return |
| 155 |
*/ |
| 156 |
QProgressBar *progressBar(); |
| 157 |
|
| 158 |
void setBarType(const BarType &type); |
| 159 |
|
| 160 |
void addButton(QPushButton *button); |
| 161 |
|
| 162 |
void removeButton(QPushButton *button); |
| 163 |
|
| 164 |
BarType myType(); |
| 165 |
|
| 166 |
Q_SIGNALS: |
| 167 |
void canceled(); |
| 168 |
|
| 169 |
public Q_SLOTS: |
| 170 |
/** |
| 171 |
* @brief 取消进度条 |
| 172 |
*/ |
| 173 |
void cancel(); |
| 174 |
|
| 175 |
/** |
| 176 |
* @brief 重置进度条 |
| 177 |
*/ |
| 178 |
void reset(); |
| 179 |
|
| 180 |
/** |
| 181 |
* @brief 设置最大值 |
| 182 |
* @param maximum |
| 183 |
*/ |
| 184 |
void setMaximum(int maximum); |
| 185 |
|
| 186 |
/** |
| 187 |
* @brief 设置最小值 |
| 188 |
* @param minimum |
| 189 |
*/ |
| 190 |
void setMinimum(int minimum); |
| 191 |
|
| 192 |
/** |
| 193 |
* @brief 设置范围 |
| 194 |
* @param minimum |
| 195 |
* @param maximum |
| 196 |
*/ |
| 197 |
void setRange(int minimum, int maximum); |
| 198 |
|
| 199 |
/** |
| 200 |
* @brief 设置当前值 |
| 201 |
* @param progress |
| 202 |
*/ |
| 203 |
void setValue(int progress); |
| 204 |
|
| 205 |
/** |
| 206 |
* @brief 设置提示内容 |
| 207 |
* @param text |
| 208 |
*/ |
| 209 |
void setLabelText(const QString &text); |
| 210 |
|
| 211 |
/** |
| 212 |
* @brief 设置取消按钮内容 |
| 213 |
* @param text |
| 214 |
*/ |
| 215 |
void setCancelButtonText(const QString &text); |
| 216 |
|
| 217 |
/** |
| 218 |
* @brief 设置次级内容 |
| 219 |
* @param text |
| 220 |
*/ |
| 221 |
void setSubContent(const QString &text); |
| 222 |
|
| 223 |
protected: |
| 224 |
void changeTheme(); |
| 225 |
|
| 226 |
private: |
| 227 |
Q_DECLARE_PRIVATE(KProgressDialog) |
| 228 |
KProgressDialogPrivate *const d_ptr; |
| 229 |
}; |
| 230 |
} |
| 231 |
/** |
| 232 |
* @example testprogressdialog/widget.h |
| 233 |
* @example testprogressdialog/widget.cpp |
| 234 |
* @} |
| 235 |
*/ |
| 236 |
#endif // KPROGRESSDIALOG_H |