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