19#include <private/qdialog_p.h>
22using namespace std::chrono_literals;
76 label->setAlignment(Qt::Alignment(align));
83 q->setCancelButtonText(cancelText);
99 int additionalSpacing = 0;
107 for (
int attempt=5; attempt--;) {
126 centered ?
q->width()/2 - cs.
width()/2 :
q->width() - mr - cs.
width(),
127 q->height() - mb - cs.
height(),
132 label->setGeometry(ml, additionalSpacing,
q->width() - ml - mr, lh);
246 d->useDefaultCancelText =
true;
273 const QString &cancelButtonText,
274 int minimum,
int maximum,
314 qWarning(
"QProgressDialog::setLabel: Attempt to set the same label again");
319 d->adoptChildWidget(
label);
334 return d->label->text();
342 d->label->setText(
text);
343 d->ensureSizeIsAtLeastSizeHint();
361 if (
d->cancel == cancelButton) {
363 qWarning(
"QProgressDialog::setCancelButton: Attempt to set the same button again");
367 d->cancel = cancelButton;
370#ifndef QT_NO_SHORTCUT
374#ifndef QT_NO_SHORTCUT
375 delete d->escapeShortcut;
376 d->escapeShortcut =
nullptr;
379 d->adoptChildWidget(cancelButton);
393 d->useDefaultCancelText =
false;
394 d->setCancelButtonText(cancelButtonText);
401 if (!cancelButtonText.
isNull()) {
408 q->setCancelButton(
nullptr);
425 qWarning(
"QProgressDialog::setBar: Cannot set a null progress bar");
430 qWarning(
"QProgressDialog::setBar: Cannot set a new progress bar "
431 "while the old one is active");
434 qWarning(
"QProgressDialog::setBar: Attempt to set the same progress bar again");
439 d->adoptChildWidget(bar);
447 if (
c->parentWidget() ==
q)
450 c->setParent(
q, { });
478 return d->cancellationFlag;
494 return d->bar->maximum();
515 return d->bar->minimum();
553 if (
d->autoClose ||
d->forceHide)
556 d->cancellationFlag =
false;
557 d->shownOnce =
false;
558 d->setValueCalled =
false;
559 d->forceTimer->stop();
566 if (
d->receiverToDisconnectOnClose)
581 d->forceHide =
false;
582 d->cancellationFlag =
true;
589 return d->bar->value();
612 if (
d->setValueCalled && progress ==
d->bar->value())
615 d->bar->setValue(progress);
618 if (
isModal() && !
d->processingEvents) {
623 if ((!
d->setValueCalled && progress == 0 ) || progress ==
minimum()) {
624 d->starttime.start();
625 d->forceTimer->start(
d->showTime);
626 d->setValueCalled =
true;
629 d->setValueCalled =
true;
630 bool need_show =
false;
631 using namespace std::chrono;
632 nanoseconds
elapsed =
d->starttime.durationElapsed();
638 const int myprogress = std::max(progress -
minimum(), 1);
639 const int remainingSteps = totalSteps - myprogress;
640 nanoseconds estimate;
641 if (remainingSteps >= INT_MAX /
elapsed.count())
642 estimate = (remainingSteps / myprogress) *
elapsed;
644 estimate = (
elapsed * remainingSteps) / myprogress;
645 need_show = estimate >=
d->showTime;
649 d->ensureSizeIsAtLeastSizeHint();
656 if (progress ==
d->bar->maximum() &&
d->autoReset)
669 QSize labelSize =
d->label ?
d->label->sizeHint() :
QSize(0, 0);
670 QSize barSize =
d->bar->sizeHint();
699 d->retranslateStrings();
721 std::chrono::milliseconds msecs{ms};
723 if (
d->bar->value() ==
d->bar->minimum()) {
724 d->forceTimer->stop();
725 d->forceTimer->start(msecs);
732 return int(
d->showTime.count());
796 d->ensureSizeIsAtLeastSizeHint();
797 d->forceTimer->stop();
810 d->forceTimer->stop();
811 if (
d->shownOnce ||
d->cancellationFlag)
830 d->receiverToDisconnectOnClose = receiver;
831 d->memberToDisconnectOnClose = member;
837#include "moc_qprogressdialog.cpp"
void clear()
Clears the contents of the byte array and makes it null.
The QCloseEvent class contains parameters that describe a close event.
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes some pending events for the calling thread according to the specified flags.
The QDialog class is the base class of dialog windows.
void closeEvent(QCloseEvent *) override
\reimp
void showEvent(QShowEvent *) override
\reimp
void start() noexcept
Starts this timer.
Type type() const
Returns the event type.
The QLabel widget provides a text or image display.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
The QProgressBar widget provides a horizontal or vertical progress bar.
QSize sizeHint() const override
\reimp
void setRange(int minimum, int maximum)
Sets the progress bar's minimum and maximum values to minimum and maximum respectively.
QByteArray memberToDisconnectOnClose
void retranslateStrings()
void init(const QString &labelText, const QString &cancelText, int min, int max)
void setCancelButtonText(const QString &cancelButtonText)
std::chrono::milliseconds showTime
QPointer< QObject > receiverToDisconnectOnClose
void ensureSizeIsAtLeastSizeHint()
QProgressDialogPrivate()=default
void _q_disconnectOnClose()
bool useDefaultCancelText
void adoptChildWidget(QWidget *c)
QShortcut * escapeShortcut
The QProgressDialog class provides feedback on the progress of a slow operation.
void showEvent(QShowEvent *event) override
\reimp
void setMinimum(int minimum)
void canceled()
This signal is emitted when the cancel button is clicked.
void setBar(QProgressBar *bar)
Sets the progress bar widget to bar.
void setValue(int progress)
int minimum
the lowest value represented by the progress bar
QString labelText
the label's text
void closeEvent(QCloseEvent *event) override
\reimp
void setMaximum(int maximum)
QProgressDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructs a progress dialog.
void setRange(int minimum, int maximum)
Sets the progress dialog's minimum and maximum values to minimum and maximum, respectively.
void changeEvent(QEvent *event) override
\reimp
bool wasCanceled
whether the dialog was canceled
bool autoClose
whether the dialog gets hidden by reset()
bool autoReset
whether the progress dialog calls reset() as soon as value() equals maximum()
void setAutoReset(bool reset)
void cancel()
Resets the progress dialog.
int minimumDuration
the time that must pass before the dialog appears
void setLabel(QLabel *label)
Sets the label to label.
QSize sizeHint() const override
Returns a size that fits the contents of the progress dialog.
int maximum
the highest value represented by the progress bar
void resizeEvent(QResizeEvent *event) override
\reimp
void forceShow()
Shows the dialog if it is still hidden after the algorithm has been started and minimumDuration milli...
int value
the current amount of progress made.
void reset()
Resets the progress dialog.
~QProgressDialog()
Destroys the progress dialog.
void setLabelText(const QString &text)
void setAutoClose(bool close)
void setMinimumDuration(int ms)
void setCancelButton(QPushButton *button)
Sets the cancel button to the push button, cancelButton.
void setCancelButtonText(const QString &text)
Sets the cancel button's text to cancelButtonText.
The QResizeEvent class contains event parameters for resize events.
The QShortcut class is used to create keyboard shortcuts.
The QShowEvent class provides an event that is sent when a widget is shown.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr QSize expandedTo(const QSize &) const noexcept
Returns a size holding the maximum width and height of this size and the given otherSize.
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isNull() const
Returns true if this string is null; otherwise returns false.
@ SH_ProgressDialog_CenterCancelButton
@ SH_ProgressDialog_TextLabelAlignment
@ PM_LayoutVerticalSpacing
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Combined button and popup list for selecting options.
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLbitfield GLuint64 timeout
[4]
GLuint GLsizei const GLchar * label
[43]
GLdouble GLdouble GLdouble GLdouble q
static QT_BEGIN_NAMESPACE constexpr auto defaultShowTime
static constexpr auto minWaitTime
static double elapsed(qint64 after, qint64 before)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent