File indexing completed on 2024-04-21 14:55:58
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 1996 Martynas Kunigelis // krazy:exclude=copyright (email unknown) 0003 Copyright (C) 2006-2007 Urs Wolfer <uwolfer at kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License version 2 as published by the Free Software Foundation. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KPROGRESSDIALOG_H 0021 #define KPROGRESSDIALOG_H 0022 0023 #include <QProgressBar> 0024 0025 #include <kdialog.h> 0026 #include <kdelibs4support_export.h> 0027 0028 /** 0029 * @short A dialog with a progress bar 0030 * 0031 * KProgressDialog provides a dialog with a text label, a progress bar 0032 * and an optional cancel button with a KDE look 'n feel. 0033 * 0034 * Since knowing how long it can take to complete an action and it is 0035 * undesirable to show a dialog for a split second before hiding it, 0036 * there are a few ways to control the timing behavior of KProgressDialog. 0037 * There is a time out that can be set before showing the dialog as well 0038 * as an option to autohide or keep displaying the dialog once complete. 0039 * 0040 * All the functionality of QProgressBar is available through direct access 0041 * to the progress bar widget via progressBar(); 0042 * 0043 * \image html kprogressdialog.png "KDE Progress Dialog" 0044 * 0045 * @author Aaron J. Seigo 0046 * @author Urs Wolfer uwolfer @ kde.org 0047 * 0048 * @deprecated since 5.0, use QProgressDialog instead 0049 */ 0050 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KProgressDialog : public KDialog 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 /** 0056 * Constructs a KProgressDialog 0057 * 0058 * @param parent Parent of the widget 0059 * @param caption Text to display in window title bar 0060 * @param text Text to display in the dialog 0061 * @param flags The widget flags 0062 */ 0063 KDELIBS4SUPPORT_DEPRECATED explicit KProgressDialog(QWidget *parent = nullptr, const QString &caption = QString(), 0064 const QString &text = QString(), Qt::WindowFlags flags = {}); 0065 0066 /** 0067 * Destructor 0068 */ 0069 ~KProgressDialog() override; 0070 0071 /** 0072 * Returns the QProgressBar used in this dialog. 0073 * To set the number of steps or other progress bar related 0074 * settings, access the QProgressBar object directly via this method. 0075 */ 0076 QProgressBar *progressBar(); 0077 0078 /** 0079 * Returns the QProgressBar used in this dialog. 0080 * To set the number of steps or other progress bar related 0081 * settings, access the QProgressBar object directly via this method. 0082 */ 0083 const QProgressBar *progressBar() const; 0084 0085 /** 0086 * Sets the text in the dialog 0087 * 0088 * @param text the text to display 0089 */ 0090 void setLabelText(const QString &text); 0091 0092 /** 0093 * Returns the current dialog text 0094 */ 0095 QString labelText() const; 0096 0097 /** 0098 * Sets whether or not the user can cancel the process. 0099 * If the dialog is cancellable, the Cancel button will be shown 0100 * and the user can close the window using the window decorations. 0101 * If the process is not (or should not be) interuptable, 0102 * set the dialog to be modal and not cancellable. 0103 * 0104 * The default is true. 0105 * 0106 * @param allowCancel Set to true to make the dialog non-closable 0107 */ 0108 void setAllowCancel(bool allowCancel); 0109 0110 /** 0111 * Returns true if the dialog can be canceled, false otherwise 0112 */ 0113 bool allowCancel() const; 0114 0115 /** 0116 * Sets whether the cancel button is visible. setAllowCancel(false) 0117 * implies showCancelButton(false) 0118 * 0119 * The default is true. 0120 * 0121 * @param show Whether or not the cancel button should be shown 0122 */ 0123 void showCancelButton(bool show); 0124 0125 /** 0126 * Sets whether the dialog should close automagically when 0127 * all the steps in the QProgressBar have been completed. 0128 * 0129 * The default is true. 0130 */ 0131 void setAutoClose(bool close); 0132 0133 /** 0134 * Returns true if the dialog will close upon completion, 0135 * or false otherwise 0136 */ 0137 bool autoClose() const; 0138 0139 /** 0140 * Sets whether the dialog should reset the QProgressBar dialog 0141 * back to 0 steps compelete when all steps have been completed. 0142 * This is useful for KProgressDialogs that will be reused. 0143 * 0144 * The default is false. 0145 */ 0146 void setAutoReset(bool autoReset); 0147 0148 /** 0149 * Returns true if the QProgressBar widget will be reset 0150 * upon completion, or false otherwise 0151 */ 0152 bool autoReset() const; 0153 0154 /** 0155 * Returns true if the dialog was closed or canceled 0156 * before completion. If the dialog is not cancellable 0157 * it will always return false. 0158 */ 0159 bool wasCancelled() const; 0160 0161 /** 0162 * Ignores the last cancel action if the cancel button was 0163 * pressed. Useful for kdialog when combined with a KMessageBox 0164 * to display a message like "Are you sure you want to cancel?" 0165 */ 0166 void ignoreCancel(); 0167 0168 /** 0169 * Sets the text to appear on the cancel button. 0170 */ 0171 void setButtonText(const QString &text); 0172 0173 /** 0174 * Returns the text on the cancel button 0175 */ 0176 QString buttonText() const; 0177 0178 /** 0179 * Set the minimum number of milliseconds to wait before 0180 * actually showing the dialog. 0181 * 0182 * If the expected duration of the task is less than the minimumDuration, the dialog will 0183 * not appear at all. This prevents the dialog popping up for tasks that are quickly over. 0184 * For tasks that are expected to exceed the minimumDuration, the dialog will pop up after 0185 * the minimumDuration time. 0186 * If set to 0, the dialog is always shown immediately. The default is 0187 * 2000 milliseconds. 0188 */ 0189 void setMinimumDuration(int ms); 0190 0191 /** 0192 * Returns the time that must pass before the dialog appears. 0193 * @see setMinimumDuration 0194 */ 0195 int minimumDuration() const; 0196 0197 void reject() override; 0198 0199 protected: 0200 void showEvent(QShowEvent *event) override; 0201 0202 private: 0203 Q_PRIVATE_SLOT(d, void slotAutoShow()) 0204 Q_PRIVATE_SLOT(d, void slotAutoActions(int percentage)) 0205 0206 private: 0207 class KProgressDialogPrivate; 0208 friend class KProgressDialogPrivate; 0209 KProgressDialogPrivate *const d; 0210 0211 Q_DISABLE_COPY(KProgressDialog) 0212 }; 0213 0214 #endif