]> Shamusworld >> Repos - architektonas/blob - src/widgets/qg_layerbox.cpp
Initial import
[architektonas] / src / widgets / qg_layerbox.cpp
1 // qg_layerbox.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 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/11/2010  Added this text. :-)
13 //
14
15 #include "qg_layerbox.h"
16
17 #include "rs_layer.h"
18 #include "rs_layerlist.h"
19
20 /**
21  * Default Constructor. You must call init manually before using
22  * this class.
23  */
24 QG_LayerBox::QG_LayerBox(QWidget * parent, const char */*name*/): QComboBox(parent)
25 {
26         showByBlock = false;
27         showUnchanged = false;
28         unchanged = false;
29         layerList = NULL;
30         currentLayer = NULL;
31 }
32
33 /**
34  * Destructor
35  */
36 QG_LayerBox::~QG_LayerBox()
37 {
38 }
39
40 RS_Layer * QG_LayerBox::getLayer()
41 {
42         return currentLayer;
43 }
44
45 /**
46  * Initialisation (called manually only once).
47  *
48  * @param layerList Layer list which provides the layer names that are
49  *                  available.
50  * @param showByBlock true: Show attribute ByBlock.
51  */
52 void QG_LayerBox::init(RS_LayerList & layerList, bool showByBlock, bool showUnchanged)
53 {
54         this->showByBlock = showByBlock;
55         this->showUnchanged = showUnchanged;
56         this->layerList = &layerList;
57
58         if (showUnchanged)
59 //              insertItem(tr("- Unchanged -"));
60                 addItem(tr("- Unchanged -"));
61
62         for(uint i=0; i<layerList.count(); ++i)
63         {
64                 RS_Layer * lay = layerList.at(i);
65
66                 if (lay != NULL && (lay->getName() != "ByBlock" || showByBlock))
67 //                      insertItem(lay->getName());
68                         addItem(lay->getName());
69         }
70
71         connect(this, SIGNAL(activated(int)), this, SLOT(slotLayerChanged(int)));
72         setCurrentIndex(0);
73         slotLayerChanged(currentIndex());
74 }
75
76 /**
77  * Sets the layer shown in the combobox to the given layer.
78  */
79 void QG_LayerBox::setLayer(RS_Layer & layer)
80 {
81         currentLayer = &layer;
82
83         //if (layer.getName()=="ByBlock" && showByBlock) {
84         //    setCurrentItem(0);
85         //} else {
86
87 //      setCurrentText(layer.getName());
88         setItemText(currentIndex(), layer.getName());
89         //}
90
91         //if (currentItem()!=7+(int)showByBlock*2) {
92         slotLayerChanged(currentIndex());
93         //}
94 }
95
96 /**
97  * Sets the layer shown in the combobox to the given layer.
98  */
99 void QG_LayerBox::setLayer(QString & layer)
100 {
101     //if (layer.getName()=="ByBlock" && showByBlock) {
102     //    setCurrentItem(0);
103     //} else {
104 //    setCurrentText(layer);
105     setItemText(currentIndex(), layer);
106     //}
107
108     //if (currentItem()!=7+(int)showByBlock*2) {
109     slotLayerChanged(currentIndex());
110     //}
111 }
112
113 bool QG_LayerBox::isUnchanged()
114 {
115         return unchanged;
116 }
117
118 /**
119  * Called when the color has changed. This method
120  * sets the current color to the value chosen or even
121  * offers a dialog to the user that allows him/ her to
122  * choose an individual color.
123  */
124 void QG_LayerBox::slotLayerChanged(int index)
125 {
126         //currentLayer.resetFlags();
127
128         if (index == 0 && showUnchanged)
129                 unchanged = true;
130         else
131                 unchanged = false;
132
133 //      currentLayer = layerList->find(text(index));
134         currentLayer = layerList->find(itemText(index));
135
136         //printf("Current color is (%d): %s\n",
137         //       index, currentLayer.name().latin1());
138
139         emit layerChanged(currentLayer);
140 }