1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
8
** This file is free software; you can redistribute it and/or modify
9
** it under the terms of the GNU General Public License as published by
10
** the Free Software Foundation; either version 2 of the License, or
11
** (at your option) any later version.
13
** This program is distributed in the hope that it will be useful,
14
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
** GNU General Public License for more details.
18
** You should have received a copy of the GNU General Public License
19
** along with this program; if not, write to the Free Software
20
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
** This copyright notice MUST APPEAR in all copies of the script!
24
**********************************************************************/
25
#include "qg_dlgimage.h"
27
#include <QDoubleValidator>
29
#include "rs_graphic.h"
32
* Constructs a QG_DlgImage as a child of 'parent', with the
33
* name 'name' and widget flags set to 'f'.
35
* The dialog will by default be modeless, unless you set 'modal' to
36
* true to construct a modal dialog.
38
QG_DlgImage::QG_DlgImage(QWidget* parent, bool modal, Qt::WindowFlags fl)
47
* Destroys the object and frees any allocated resources
49
QG_DlgImage::~QG_DlgImage()
52
// no need to delete child widgets, Qt does it all for us
56
* Sets the strings of the subwidgets using the current
59
void QG_DlgImage::languageChange()
64
void QG_DlgImage::setImage(RS_Image& e) {
66
val = new QDoubleValidator(leScale);
67
//pen = spline->getPen();
68
wPen->setPen(image->getPen(false), true, false, "Pen");
69
RS_Graphic* graphic = image->getGraphic();
71
cbLayer->init(*(graphic->getLayerList()), false, false);
73
RS_Layer* lay = image->getLayer(false);
75
cbLayer->setLayer(*lay);
77
leInsertX->setValidator(val);
78
leInsertY->setValidator(val);
79
leWidth->setValidator(val);
80
leHeight->setValidator(val);
81
leScale->setValidator(val);
82
leAngle->setValidator(val);
83
scale = image->getUVector().magnitude();
84
leInsertX->setText(QString("%1").arg(image->getInsertionPoint().x));
85
leInsertY->setText(QString("%1").arg(image->getInsertionPoint().y));
86
leWidth->setText(QString("%1").arg(image->getImageWidth()));
87
leHeight->setText(QString("%1").arg(image->getImageHeight()));
88
leScale->setText(QString("%1").arg(scale));
89
leAngle->setText(QString("%1").arg( RS_Math::rad2deg(image->getUVector().angle()) ));
90
lePath->setText(image->getFile());
91
leSize->setText(QString("%1 x %2").arg(image->getWidth()).arg(image->getHeight()));
92
leDPI->setText(QString("%1").arg(RS_Units::scaleToDpi(scale,image->getGraphicUnit())));
96
void QG_DlgImage::changeWidth() {
97
double width = leWidth->text().toDouble();
98
scale = width / image->getWidth();
99
leHeight->setText(QString("%1").arg(image->getHeight() * scale));
100
leScale->setText(QString("%1").arg(scale));
102
void QG_DlgImage::changeHeight() {
103
double height = leHeight->text().toDouble();
104
scale = height / image->getHeight();
105
leWidth->setText(QString("%1").arg(image->getWidth() * scale));
106
leScale->setText(QString("%1").arg(scale));
108
void QG_DlgImage::changeScale() {
109
scale = leScale->text().toDouble();
110
leWidth->setText(QString("%1").arg(image->getWidth() * scale));
111
leHeight->setText(QString("%1").arg(image->getHeight() * scale));
112
leDPI->setText(QString("%1").arg(RS_Units::scaleToDpi(scale, image->getGraphicUnit())));
115
void QG_DlgImage::changeDPI(){
116
scale = RS_Units::dpiToScale(leDPI->text().toDouble(), image->getGraphicUnit());
117
leScale->setText(QString("%1").arg(scale));
118
leWidth->setText(QString("%1").arg(image->getWidth() * scale));
119
leHeight->setText(QString("%1").arg(image->getHeight() * scale));
122
void QG_DlgImage::updateImage() {
123
image->setPen(wPen->getPen());
124
image->setLayer(cbLayer->currentText());
125
image->setInsertionPoint(RS_Vector(leInsertX->text().toDouble(), leInsertY->text().toDouble()) );
126
double orgScale = image->getUVector().magnitude();
128
double orgAngle = image->getUVector().angle();
129
double angle = RS_Math::deg2rad( leAngle->text().toDouble() );
130
image->scale(image->getInsertionPoint(), RS_Vector(scale, scale));
131
image->rotate(image->getInsertionPoint(), angle - orgAngle);