~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/ui/forms/qg_dlgimage.cpp

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
 
6
**
 
7
**
 
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.
 
12
**
 
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.
 
17
** 
 
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
 
21
**
 
22
** This copyright notice MUST APPEAR in all copies of the script!  
 
23
**
 
24
**********************************************************************/
 
25
#include "qg_dlgimage.h"
 
26
 
 
27
#include <QDoubleValidator>
 
28
#include "rs_image.h"
 
29
#include "rs_graphic.h"
 
30
 
 
31
/*
 
32
 *  Constructs a QG_DlgImage as a child of 'parent', with the
 
33
 *  name 'name' and widget flags set to 'f'.
 
34
 *
 
35
 *  The dialog will by default be modeless, unless you set 'modal' to
 
36
 *  true to construct a modal dialog.
 
37
 */
 
38
QG_DlgImage::QG_DlgImage(QWidget* parent, bool modal, Qt::WindowFlags fl)
 
39
    : QDialog(parent, fl)
 
40
{
 
41
    setModal(modal);
 
42
    setupUi(this);
 
43
 
 
44
}
 
45
 
 
46
/*
 
47
 *  Destroys the object and frees any allocated resources
 
48
 */
 
49
QG_DlgImage::~QG_DlgImage()
 
50
{
 
51
    delete val;
 
52
    // no need to delete child widgets, Qt does it all for us
 
53
}
 
54
 
 
55
/*
 
56
 *  Sets the strings of the subwidgets using the current
 
57
 *  language.
 
58
 */
 
59
void QG_DlgImage::languageChange()
 
60
{
 
61
    retranslateUi(this);
 
62
}
 
63
 
 
64
void QG_DlgImage::setImage(RS_Image& e) {
 
65
    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();
 
70
    if (graphic!=NULL) {
 
71
        cbLayer->init(*(graphic->getLayerList()), false, false);
 
72
    }
 
73
    RS_Layer* lay = image->getLayer(false);
 
74
    if (lay!=NULL) {
 
75
        cbLayer->setLayer(*lay);
 
76
    }
 
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())));
 
93
}
 
94
 
 
95
 
 
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));
 
101
}
 
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));
 
107
}
 
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())));
 
113
}
 
114
 
 
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));    
 
120
}
 
121
 
 
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();
 
127
    scale /= orgScale;
 
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);
 
132
 
 
133
    image->update();
 
134
}
 
135
 
 
136
 
 
137