]> Shamusworld >> Repos - architektonas/blob - src/forms/layerdialog.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / layerdialog.cpp
1 // layerdialog.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/10/2010  Created this file. :-)
15 //
16
17 #include "layerdialog.h"
18
19 #include "layer.h"
20 #include "layerlist.h"
21
22 LayerDialog::LayerDialog(QWidget * parent/*= NULL*/, Qt::WindowFlags flags/*= 0*/):
23         QDialog(parent, flags), layer(NULL), layerList(NULL), layerName(""), editLayer(false)
24 {
25         ui.setupUi(this);
26 }
27
28 LayerDialog::~LayerDialog()
29 {
30 }
31
32 void LayerDialog::setLayer(Layer * l)
33 {
34         layer = l;
35         layerName = layer->getName();
36         ui.leName->setText(layerName);
37         ui.wPen->setPen(layer->getPen(), false, false, tr("Default Pen"));
38
39         if (layer->getName() == "0")
40                 ui.leName->setEnabled(false);
41 }
42
43 void LayerDialog::setLayerList(LayerList * ll)
44 {
45         layerList = ll;
46 }
47
48 void LayerDialog::setEditLayer(bool el)
49 {
50         editLayer = el;
51 }
52
53 void LayerDialog::updateLayer()
54 {
55         layer->setName(ui.leName->text());
56         layer->setPen(ui.wPen->getPen());
57 #if 0
58 //OK, the problem is the color widget is misreporting the color that's been set.
59 Color c = ui.wPen->getPen().getColor();
60 printf("LayerDialog::updateLayer() -> selected pen is %u, %u, %u\n", c.red(), c.green(), c.blue());
61 std::cout << ui.wPen->getPen();
62 Pen p = layer->getPen();
63 c = p.getColor();
64 printf("LayerDialog::updateLayer() -> selected pen is %u, %u, %u\n", c.red(), c.green(), c.blue());
65 std::cout << ui.wPen->getPen();
66 #endif
67 }
68
69 void LayerDialog::validate()
70 {
71         if (layerList && (!editLayer || layerName != ui.leName->text()))
72         {
73                 Layer * l = layerList->find(ui.leName->text().toLatin1());
74
75                 if (l)
76                 {
77                         QMessageBox::information(parentWidget(), QMessageBox::tr("Layer Properties"),
78                                  QMessageBox::tr("Layer with a name \"%1\" already exists. Please specify "
79                                 "a different name.").arg(ui.leName->text()), QMessageBox::Ok);
80                         ui.leName->setFocus();
81                         ui.leName->selectAll();
82                 }
83                 else
84                         accept();
85         }
86         else
87                 accept();
88 }