File indexing completed on 2024-04-21 03:42:08

0001 /*
0002     KmPlot - a math. function plotter for the KDE-Desktop
0003 
0004     SPDX-FileCopyrightText: 2004 Fredrik Edemar <f_edemar@linux.se>
0005     SPDX-FileCopyrightText: 2006 David Saxton <david@bluehaze.org>
0006 
0007     This file is part of the KDE Project.
0008     KmPlot is part of the KDE-EDU Project.
0009 
0010     SPDX-License-Identifier: GPL-2.0-or-later
0011 
0012 */
0013 
0014 #include "kmplotprogress.h"
0015 
0016 #include <QCoreApplication>
0017 #include <QDebug>
0018 #include <QIcon>
0019 #include <QProgressBar>
0020 #include <QPushButton>
0021 #include <QTimer>
0022 
0023 KmPlotProgress::KmPlotProgress(QWidget *parent)
0024     : QWidget(parent)
0025 {
0026     m_button = new QPushButton(this);
0027     m_button->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
0028     m_button->setGeometry(QRect(0, 0, 30, 23));
0029     m_button->setMaximumHeight(height() - 10);
0030     connect(m_button, &QPushButton::clicked, this, &KmPlotProgress::cancelDraw);
0031 
0032     m_progress = new QProgressBar(this);
0033     m_progress->setGeometry(QRect(30, 0, 124, 23));
0034     m_progress->setMaximumHeight(height() - 10);
0035 
0036     m_showTimer = new QTimer(this);
0037     m_showTimer->setSingleShot(true);
0038     connect(m_showTimer, &QTimer::timeout, this, &KmPlotProgress::showProgressBar);
0039 
0040     hide();
0041     setMinimumWidth(154);
0042 }
0043 
0044 KmPlotProgress::~KmPlotProgress()
0045 {
0046 }
0047 
0048 void KmPlotProgress::showProgressBar()
0049 {
0050     show();
0051     QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
0052 }
0053 
0054 void KmPlotProgress::setProgress(double progress)
0055 {
0056     qDebug() << "progress=" << progress;
0057 
0058     Q_ASSERT(progress >= 0);
0059 
0060     if (progress >= 1) {
0061         hide();
0062         m_showTimer->stop();
0063     } else {
0064         if (!isVisible() && !m_showTimer->isActive())
0065             m_showTimer->start(500);
0066 
0067         m_progress->setValue(int(progress * 100));
0068     }
0069 
0070     QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
0071 }
0072 
0073 #include "moc_kmplotprogress.cpp"