1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2015 A. Stebich (librecad@mail.lordofbikes.de)
6 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
7 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
8 **
9 **
10 ** This file may be distributed and/or modified under the terms of the
11 ** GNU General Public License version 2 as published by the Free Software
12 ** Foundation and appearing in the file gpl-2.0.txt included in the
13 ** packaging of this file.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ** GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 **
24 ** This copyright notice MUST APPEAR in all copies of the script!
25 **
26 **********************************************************************/
27 #include "qg_layerdialog.h"
28 
29 #include <QMessageBox>
30 #include "rs_layer.h"
31 #include "rs_layerlist.h"
32 
33 /*
34  *  Constructs a QG_LayerDialog as a child of 'parent', with the
35  *  name 'name' and widget flags set to 'f'.
36  *
37  *  The dialog will by default be modeless, unless you set 'modal' to
38  *  true to construct a modal dialog.
39  */
QG_LayerDialog(QWidget * parent,QString name,bool modal,Qt::WindowFlags fl)40 QG_LayerDialog::QG_LayerDialog(QWidget* parent, QString name, bool modal, Qt::WindowFlags fl)
41     : QDialog(parent, fl)
42 {
43     setModal(modal);
44     setObjectName(name);
45     setupUi(this);
46 
47 
48     init();
49 }
50 
51 
52 /*
53  *  Sets the strings of the subwidgets using the current
54  *  language.
55  */
languageChange()56 void QG_LayerDialog::languageChange()
57 {
58     retranslateUi(this);
59 }
60 
setLayer(RS_Layer * l)61 void QG_LayerDialog::setLayer(RS_Layer* l) {
62     layer = l;
63 	layerName = layer->getName();
64     leName->setText(layerName);
65     wPen->setPen(layer->getPen(), false, false, tr("Default Pen"));
66     cbConstructionLayer->setChecked(l->isConstruction());
67 
68     if (layer->getName()=="0") {
69         leName->setEnabled(false);
70     }
71 }
72 
updateLayer()73 void QG_LayerDialog::updateLayer() {
74     layer->setName(leName->text());
75     layer->setPen(wPen->getPen());
76     layer->setConstruction(cbConstructionLayer->isChecked());
77 }
78 
validate()79 void QG_LayerDialog::validate() {
80 	if (layerList &&
81                 (editLayer == false || layerName != leName->text())) {
82                 RS_Layer* l = layerList->find(leName->text());
83 		if (l) {
84 			QMessageBox::information(parentWidget(),
85 									 QMessageBox::tr("Layer Properties"),
86 									 QMessageBox::tr("Layer with a name \"%1\" "
87 													 "already exists. Please specify "
88 													 "a different name.")
89                                                                          .arg(leName->text()),
90 									 QMessageBox::Ok);
91 			leName->setFocus();
92 			leName->selectAll();
93 		}
94 		else
95 			accept();
96 	}
97 	else
98 		accept();
99 }
100 
setLayerList(RS_LayerList * ll)101 void QG_LayerDialog::setLayerList( RS_LayerList * ll ){
102     layerList = ll;
103 }
104 
init()105 void QG_LayerDialog::init(){
106 	leName->setFocus();
107 	layer = NULL;
108 	layerList = NULL;
109 	layerName = "";
110 	editLayer = false;
111 }
112 
setEditLayer(bool el)113 void QG_LayerDialog::setEditLayer( bool el ){
114 	editLayer = el;
115 }
116 
117 
118 //! @return a reference to the QLineEdit object.
getQLineEdit()119 QLineEdit* QG_LayerDialog::getQLineEdit () {
120         return leName;
121 }
122