Seamly2D
Code documentation
dialognewpattern.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 dialognewpattern.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 22 2, 2014
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 "dialognewpattern.h"
53 #include "ui_dialognewpattern.h"
54 #include "../core/vapplication.h"
55 #include "../vmisc/vsettings.h"
56 #include "../vpatterndb/vcontainer.h"
57 
58 #include <QFileDialog>
59 #include <QMessageBox>
60 #include <QPushButton>
61 #include <QSettings>
62 #include <QGuiApplication>
63 #include <QScreen>
64 
65 //---------------------------------------------------------------------------------------------------------------------
66 DialogNewPattern::DialogNewPattern(VContainer *data, const QString &patternPieceName, QWidget *parent)
67  :QDialog(parent), ui(new Ui::DialogNewPattern), data(data), isInitialized(false)
68 {
69  ui->setupUi(this);
70 
71  ui->lineEditName->setClearButtonEnabled(true);
72 
73  qApp->Seamly2DSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
74 
75  QRect position = this->frameGeometry();
76  position.moveCenter(QGuiApplication::primaryScreen()->availableGeometry().center());
77  move(position.topLeft());
78 
79  ui->lineEditName->setText(patternPieceName);
80 
81  InitUnits();
82  CheckState();
83  connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogNewPattern::CheckState);
84 }
85 
86 //---------------------------------------------------------------------------------------------------------------------
88 {
89  delete ui;
90 }
91 
92 //---------------------------------------------------------------------------------------------------------------------
94 {
95  const qint32 index = ui->comboBoxUnits->currentIndex();
96  return StrToUnits(ui->comboBoxUnits->itemData(index).toString());
97 }
98 
99 //---------------------------------------------------------------------------------------------------------------------
101 {
102  bool flagName = false;
103  if (ui->lineEditName->text().isEmpty() == false)
104  {
105  flagName = true;
106  }
107 
108  QPushButton *ok_Button = ui->buttonBox->button(QDialogButtonBox::Ok);
109  SCASSERT(ok_Button != nullptr)
110  ok_Button->setEnabled(flagName);
111 }
112 
113 //---------------------------------------------------------------------------------------------------------------------
114 void DialogNewPattern::showEvent(QShowEvent *event)
115 {
116  QDialog::showEvent( event );
117  if ( event->spontaneous() )
118  {
119  return;
120  }
121 
122  if (isInitialized)
123  {
124  return;
125  }
126  // do your init stuff here
127 
128  setMaximumSize(size());
129  setMinimumSize(size());
130 
131  isInitialized = true;//first show windows are held
132 }
133 
134 //---------------------------------------------------------------------------------------------------------------------
136 {
137  ui->comboBoxUnits->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm)));
138  ui->comboBoxUnits->addItem(tr("Millimeters"), QVariant(UnitsToStr(Unit::Mm)));
139  ui->comboBoxUnits->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch)));
140 
141  // set default unit
142  const qint32 indexUnit = ui->comboBoxUnits->findData(qApp->Seamly2DSettings()->GetUnit());
143  if (indexUnit != -1)
144  {
145  ui->comboBoxUnits->setCurrentIndex(indexUnit);
146  }
147 }
148 
149 //---------------------------------------------------------------------------------------------------------------------
150 QString DialogNewPattern::name() const
151 {
152  return ui->lineEditName->text();
153 }
Ui::DialogNewPattern * ui
DialogNewPattern(VContainer *data, const QString &patternPieceName, QWidget *parent=nullptr)
virtual ~DialogNewPattern()
QString name() const
Unit PatternUnit() const
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
The VContainer class container of all variables.
Definition: vcontainer.h:141
Unit StrToUnits(const QString &unit)
Definition: def.cpp:670
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
#define SCASSERT(cond)
Definition: def.h:317
Unit
Definition: def.h:105
#define qApp
Definition: vapplication.h:67