Seamly2D
Code documentation
mouse_coordinates.cpp
Go to the documentation of this file.
1  /******************************************************************************
2  * @file mouse_coordinates.cpp
3  ** @author DS Caskey
4  ** @date Nov 6, 2022
5  **
6  ** @brief
7  ** @copyright
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  #include "mouse_coordinates.h"
24  #include "ui_mouse_coordinates.h"
25 
26 #include <QLabel>
27 #include <QPointF>
28 #include <QString>
29 #include <Qt>
30 
31 #include "../vmisc/vabstractapplication.h"
32 
33 //---------------------------------------------------------------------------------------------------------------------
34 /*
35  * A widget for displaying the mouse coordinates in pattern units.
36  *
37  * Constructor.
38  */
39 MouseCoordinates::MouseCoordinates(const Unit &units, QWidget *parent)
40  : QWidget(parent)
41  , ui(new Ui::MouseCoordinates)
42  , m_units(units)
43 {
44  ui->setupUi(this);
45  updateCoordinates(QPointF());
46  ui->unitsText_Label->setText(UnitsToStr(m_units));
47 }
48 
49 //---------------------------------------------------------------------------------------------------------------------
50 /*
51  * Destructor
52  */
54 
55 //---------------------------------------------------------------------------------------------------------------------
56 /*
57  * @brief Show user updated mouse oordinates. Converts from pixels to pattern units.
58  * @param scenePos mouse position.
59  */
60 void MouseCoordinates::updateCoordinates(const QPointF &scenePos)
61 {
62  ui->xposText_Label->setText(QString(QString::number(qApp->fromPixel(scenePos.x()), 'f', 2 )));
63  ui->yposText_Label->setText(QString(QString::number(qApp->fromPixel(scenePos.y()), 'f', 2 )));
64 }
MouseCoordinates(const Unit &units, QWidget *parent=nullptr)
Ui::MouseCoordinates * ui
void updateCoordinates(const QPointF &scenePos)
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
Unit
Definition: def.h:105
#define qApp
Definition: vapplication.h:67