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