Seamly2D
Code documentation
dialoglayoutprogress.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file dialoglayoutprogress.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 14 1, 2015
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "dialoglayoutprogress.h"
53 #include "ui_dialoglayoutprogress.h"
54 #include "../options.h"
55 #include "../core/vapplication.h"
56 
57 #include <QMessageBox>
58 #include <QPushButton>
59 #include <QMovie>
60 #include <QtDebug>
61 
62 //---------------------------------------------------------------------------------------------------------------------
63 DialogLayoutProgress::DialogLayoutProgress(int count, QWidget *parent)
64  :QDialog(parent), ui(new Ui::DialogLayoutProgress), maxCount(count), movie(nullptr), isInitialized(false)
65 {
66  ui->setupUi(this);
67 
68  qApp->Seamly2DSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
69 
70  ui->progressBar->setMaximum(maxCount);
71  ui->progressBar->setValue(0);
72 
73  ui->labelMessage->setText(tr("Arranged workpieces: %1 from %2").arg(0).arg(count));
74 
75  movie = new QMovie("://icon/16x16/progress.gif");
76  ui->labelProgress->setMovie (movie);
77  movie->start ();
78 
79  QPushButton *bCancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
80  SCASSERT(bCancel != nullptr)
81  connect(bCancel, &QPushButton::clicked, this, [this](){emit Abort();});
82  setModal(true);
83 
84  this->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
85 }
86 
87 //---------------------------------------------------------------------------------------------------------------------
89 {
90  delete ui;
91  delete movie;
92 }
93 
94 //---------------------------------------------------------------------------------------------------------------------
96 {
97  show();
98 }
99 
100 //---------------------------------------------------------------------------------------------------------------------
102 {
103  ui->progressBar->setValue(count);
104  ui->labelMessage->setText(tr("Arranged workpieces: %1 from %2").arg(count).arg(maxCount));
105 }
106 
107 //---------------------------------------------------------------------------------------------------------------------
109 {
110  switch (state)
111  {
113  return;
115  qCritical() << tr("Couldn't prepare data for creation layout");
116  break;
118  qCritical() << tr("One or more pattern pieces are bigger than the paper format you selected. Please select a bigger paper format.");
119  break;
121  default:
122  break;
123  }
124 
125  done(QDialog::Rejected);
126 }
127 
128 //---------------------------------------------------------------------------------------------------------------------
130 {
131  done(QDialog::Accepted);
132 }
133 
134 //---------------------------------------------------------------------------------------------------------------------
135 void DialogLayoutProgress::showEvent(QShowEvent *event)
136 {
137  QDialog::showEvent( event );
138  if ( event->spontaneous() )
139  {
140  return;
141  }
142 
143  if (isInitialized)
144  {
145  return;
146  }
147  // do your init stuff here
148 
149  setMaximumSize(size());
150  setMinimumSize(size());
151 
152  isInitialized = true;//first show windows are held
153 }
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
void Error(const LayoutErrors &state)
DialogLayoutProgress(int count, QWidget *parent=nullptr)
Ui::DialogLayoutProgress * ui
#define SCASSERT(cond)
Definition: def.h:317
#define qApp
Definition: vapplication.h:67
LayoutErrors
Definition: vlayoutdef.h:60