2015-01-14 18:52:16 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialoglayoutprogress.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 14 1, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-01-14 18:52:16 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2015-01-14 18:52:16 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "dialoglayoutprogress.h"
|
|
|
|
#include "ui_dialoglayoutprogress.h"
|
2015-06-19 13:21:46 +02:00
|
|
|
#include "../options.h"
|
|
|
|
#include "../core/vapplication.h"
|
2015-01-14 18:52:16 +01:00
|
|
|
|
|
|
|
#include <QMessageBox>
|
2015-02-09 17:34:50 +01:00
|
|
|
#include <QPushButton>
|
2015-10-18 21:30:51 +02:00
|
|
|
#include <QMovie>
|
|
|
|
#include <QtDebug>
|
2019-03-29 18:52:37 +01:00
|
|
|
#include <QTime>
|
2015-01-14 18:52:16 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-29 18:52:37 +01:00
|
|
|
DialogLayoutProgress::DialogLayoutProgress(QElapsedTimer timer, qint64 timeout, QWidget *parent)
|
|
|
|
: QDialog(parent),
|
|
|
|
ui(new Ui::DialogLayoutProgress),
|
|
|
|
m_movie(new QMovie(QStringLiteral("://icon/16x16/progress.gif"))),
|
|
|
|
m_timer(timer),
|
|
|
|
m_timeout(timeout),
|
|
|
|
progressTimer(new QTimer(this))
|
2015-01-14 18:52:16 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-02-10 20:27:11 +01:00
|
|
|
|
2017-01-03 09:46:28 +01:00
|
|
|
qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
|
2015-02-10 20:27:11 +01:00
|
|
|
|
2019-03-29 18:52:37 +01:00
|
|
|
ui->progressBar->setMaximum(static_cast<int>(timeout/1000));
|
2015-01-14 18:52:16 +01:00
|
|
|
ui->progressBar->setValue(0);
|
|
|
|
|
2019-03-29 18:52:37 +01:00
|
|
|
ui->labelProgress->setMovie(m_movie);
|
|
|
|
m_movie->start();
|
2015-05-06 14:49:27 +02:00
|
|
|
|
2015-01-14 18:52:16 +01:00
|
|
|
QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(bCancel != nullptr)
|
2017-05-30 18:52:38 +02:00
|
|
|
connect(bCancel, &QPushButton::clicked, this, [this](){emit Abort();});
|
2015-01-14 18:52:16 +01:00
|
|
|
setModal(true);
|
2015-01-22 17:22:37 +01:00
|
|
|
|
|
|
|
this->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
|
2019-03-29 18:52:37 +01:00
|
|
|
|
|
|
|
connect(progressTimer, &QTimer::timeout, this, [this]()
|
|
|
|
{
|
|
|
|
const qint64 elapsed = m_timer.elapsed();
|
|
|
|
const int timeout = static_cast<int>(m_timeout - elapsed);
|
2019-03-30 10:13:53 +01:00
|
|
|
QTime t(0, 0);
|
2019-03-29 18:52:37 +01:00
|
|
|
t = t.addMSecs(timeout);
|
|
|
|
ui->labelTimeLeft->setText(tr("Time left: %1").arg(t.toString()));
|
|
|
|
ui->progressBar->setValue(static_cast<int>(elapsed/1000));
|
|
|
|
|
|
|
|
if (timeout <= 1000)
|
|
|
|
{
|
|
|
|
emit Abort();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
progressTimer->start(1000);
|
2015-01-14 18:52:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogLayoutProgress::~DialogLayoutProgress()
|
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
delete m_movie;
|
2015-01-14 18:52:16 +01:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLayoutProgress::Start()
|
|
|
|
{
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-29 18:52:37 +01:00
|
|
|
void DialogLayoutProgress::Finished()
|
2015-01-14 18:52:16 +01:00
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
progressTimer->stop();
|
|
|
|
done(QDialog::Accepted);
|
2015-01-14 18:52:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-29 18:52:37 +01:00
|
|
|
void DialogLayoutProgress::Efficiency(qreal value)
|
2015-01-14 18:52:16 +01:00
|
|
|
{
|
2019-03-30 10:14:32 +01:00
|
|
|
ui->labelMessage->setText(tr("Efficiency coefficient: %1%").arg(qRound(value * 10.) / 10.));
|
2015-01-14 18:52:16 +01:00
|
|
|
}
|
|
|
|
|
2015-11-05 14:01:33 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogLayoutProgress::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
QDialog::showEvent( event );
|
|
|
|
if ( event->spontaneous() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInitialized)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// do your init stuff here
|
|
|
|
|
|
|
|
setMaximumSize(size());
|
|
|
|
setMinimumSize(size());
|
|
|
|
|
|
|
|
isInitialized = true;//first show windows are held
|
|
|
|
}
|