Seamly2D
Code documentation
dialogsinglepoint.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 dialogsinglepoint.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date November 15, 2013
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 "dialogsinglepoint.h"
53 
54 #include <QDoubleSpinBox>
55 #include <QLineEdit>
56 
57 #include "../vmisc/def.h"
58 #include "../vmisc/vabstractapplication.h"
59 #include "dialogtool.h"
60 #include "ui_dialogsinglepoint.h"
61 
62 //---------------------------------------------------------------------------------------------------------------------
63 /**
64  * @brief DialogSinglePoint create dialog
65  * @param data container with data
66  * @param parent parent widget
67  */
68 DialogSinglePoint::DialogSinglePoint(const VContainer *data, const quint32 &toolId, QWidget *parent)
69  : DialogTool(data, toolId, parent)
70  , ui(new Ui::DialogSinglePoint), point(QPointF())
71 {
72  ui->setupUi(this);
73  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
74  setWindowIcon(QIcon(":/toolicon/32x32/point_basepoint_icon.png"));
75 
76  ui->lineEditName->setClearButtonEnabled(true);
77 
78  ui->doubleSpinBoxX->setRange(0, qApp->fromPixel(SceneSize));
79  ui->doubleSpinBoxY->setRange(0, qApp->fromPixel(SceneSize));
80  labelEditNamePoint = ui->labelEditName;
82 
83  flagName = true;
85 
86  connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogTool::NamePointChanged);
87 }
88 
89 //---------------------------------------------------------------------------------------------------------------------
90 /**
91  * @brief mousePress get mouse position
92  * @param scenePos position of cursor
93  */
94 void DialogSinglePoint::mousePress(const QPointF &scenePos)
95 {
96  if (isInitialized == false)
97  {
98  ui->doubleSpinBoxX->setValue(qApp->fromPixel(scenePos.x()));
99  ui->doubleSpinBoxY->setValue(qApp->fromPixel(scenePos.y()));
100  this->show();
101  }
102  else
103  {
104  ui->doubleSpinBoxX->setValue(qApp->fromPixel(scenePos.x()));
105  ui->doubleSpinBoxY->setValue(qApp->fromPixel(scenePos.y()));
106  }
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
111 {
112  point = QPointF(qApp->toPixel(ui->doubleSpinBoxX->value()), qApp->toPixel(ui->doubleSpinBoxY->value()));
113  pointName = ui->lineEditName->text();
114 }
115 
116 //---------------------------------------------------------------------------------------------------------------------
117 /**
118  * @brief setData set name and point
119  * @param name name of point
120  * @param point data for point
121  */
122 void DialogSinglePoint::SetData(const QString &name, const QPointF &point)
123 {
124  pointName = name;
125  this->point = point;
126  isInitialized = true;
127  ui->lineEditName->setText(name);
128  ui->doubleSpinBoxX->setValue(qApp->fromPixel(point.x()));
129  ui->doubleSpinBoxY->setValue(qApp->fromPixel(point.y()));
130 }
131 
132 //---------------------------------------------------------------------------------------------------------------------
134 {
135  delete ui;
136 }
137 
138 //---------------------------------------------------------------------------------------------------------------------
139 /**
140  * @brief getPoint return point
141  * @return point
142  */
144 {
145  return point;
146 }
The DialogSinglePoint class dialog for ToolSinglePoint. Help create point and edit option.
DialogSinglePoint(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
DialogSinglePoint create dialog.
QPointF GetPoint() const
getPoint return point
void SetData(const QString &name, const QPointF &point)
setData set name and point
void mousePress(const QPointF &scenePos)
mousePress get mouse position
QPointF point
point data of point
virtual void SaveData() Q_DECL_OVERRIDE
SaveData Put dialog data in local variables.
Ui::DialogSinglePoint * ui
ui keeps information about user interface
virtual ~DialogSinglePoint() Q_DECL_OVERRIDE
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
virtual void CheckState()
CheckState enable, when all is correct, or disable, when something wrong, button ok.
void NamePointChanged()
NamePointChanged check name of point.
bool flagName
flagName true if name is correct
Definition: dialogtool.h:183
QString pointName
pointName name of point
Definition: dialogtool.h:231
void initializeOkCancel(T *ui)
initializeOkCancel initialize OK and Cancel buttons
Definition: dialogtool.h:379
bool isInitialized
isInitialized true if window is initialized
Definition: dialogtool.h:180
QLabel * labelEditNamePoint
labelEditNamePoint label used when need show wrong name of point
Definition: dialogtool.h:214
The VContainer class container of all variables.
Definition: vcontainer.h:141
#define SceneSize
Definition: def.h:57
#define qApp
Definition: vapplication.h:67