]> Shamusworld >> Repos - architektonas/blob - src/widgets/pentoolbar.cpp
Removed useless *Listener class and references.
[architektonas] / src / widgets / pentoolbar.cpp
1 // pentoolbar.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 // JLH  05/22/2010  Fixed constructor to actually add widgets to the toolbar,
16 //                  delete created objects in destructor to prevent memory leak
17 //
18
19 #include "pentoolbar.h"
20
21 #include "colorbox.h"
22 #include "widthbox.h"
23 #include "linetypebox.h"
24 #include "rs_layer.h"
25
26 /**
27  * Constructor.
28  */
29 QG_PenToolBar::QG_PenToolBar(QMainWindow * parent/*= NULL*/, const char * name/*= NULL*/):
30         QToolBar(parent),
31         colorBox(new QG_ColorBox(true, false, this, "colorbox")),
32         widthBox(new QG_WidthBox(true, false, this, "widthbox")),
33         lineTypeBox(new QG_LineTypeBox(true, false, this, "lineTypebox"))
34 {
35         setWindowTitle(name);
36
37         colorBox->setMinimumWidth(80);
38         widthBox->setMinimumWidth(80);
39         lineTypeBox->setMinimumWidth(80);
40
41         connect(colorBox, SIGNAL(colorChanged(const RS_Color &)), this,
42                 SLOT(slotColorChanged(const RS_Color &)));
43         connect(widthBox, SIGNAL(widthChanged(RS2::LineWidth)), this,
44                 SLOT(slotWidthChanged(RS2::LineWidth)));
45         connect(lineTypeBox, SIGNAL(lineTypeChanged(RS2::LineType)), this,
46                 SLOT(slotLineTypeChanged(RS2::LineType)));
47
48         currentPen.setColor(colorBox->getColor());
49         currentPen.setWidth(widthBox->getWidth());
50         currentPen.setLineType(lineTypeBox->getLineType());
51
52         addWidget(colorBox);
53         addWidget(widthBox);
54         addWidget(lineTypeBox);
55 }
56
57 /**
58  * Destructor
59  */
60 QG_PenToolBar::~QG_PenToolBar()
61 {
62         delete colorBox;
63         delete widthBox;
64         delete lineTypeBox;
65 }
66
67 RS_Pen QG_PenToolBar::getPen()
68 {
69         return currentPen;
70 }
71
72 /**
73  * Called by the layer list if this object was added as a listener
74  * to a layer list.
75  */
76 void QG_PenToolBar::layerActivated(RS_Layer * l)
77 {
78         //printf("QG_PenToolBar::layerActivated\n");
79
80         if (l == NULL)
81                 return;
82
83         //colorBox->setColor(l->getPen().getColor());
84         //widthBox->setWidth(l->getPen().getWidth());
85
86         colorBox->setLayerColor(l->getPen().getColor());
87         widthBox->setLayerWidth(l->getPen().getWidth());
88         lineTypeBox->setLayerLineType(l->getPen().getLineType());
89
90         //if (colorBox->getColor().getFlag(C_BY_LAYER)) {
91         //printf("  Color by layer\n");
92         //colorBox->setColor(l->getPen().getColor());
93         //}
94 }
95
96 /**
97  * Called by the layer list (if this object was previously
98  * added as a listener to a layer list).
99  */
100 void QG_PenToolBar::layerEdited(RS_Layer *)
101 {
102 }
103
104 /**
105  * Called when the color was changed by the user.
106  */
107 void QG_PenToolBar::slotColorChanged(const RS_Color & color)
108 {
109         currentPen.setColor(color);
110         //printf("  color changed\n");
111
112         emit penChanged(currentPen);
113 }
114
115 /**
116  * Called when the width was changed by the user.
117  */
118 void QG_PenToolBar::slotWidthChanged(RS2::LineWidth w)
119 {
120         currentPen.setWidth(w);
121         //printf("  width changed\n");
122
123         emit penChanged(currentPen);
124 }
125
126 /**
127  * Called when the linetype was changed by the user.
128  */
129 void QG_PenToolBar::slotLineTypeChanged(RS2::LineType w)
130 {
131         currentPen.setLineType(w);
132         //printf("  line type changed\n");
133
134         emit penChanged(currentPen);
135 }