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