kivio

kiviostencilformatdlg.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Peter Simonsson <psn@linux.se>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "kiviostencilformatdlg.h"
21
22#include <tqlabel.h>
23#include <tqlayout.h>
24#include <tqbitmap.h>
25#include <tqpixmap.h>
26#include <tqpainter.h>
27
28#include <kcolorbutton.h>
29#include <tdelocale.h>
30
31#include <KoUnitWidgets.h>
32
33#include "kivio_view.h"
34
35KivioStencilFormatDlg::KivioStencilFormatDlg(KivioView* parent, const char* name)
36 : KDialogBase(parent, name, true, i18n("Stencil & Connector Format"), Ok|Cancel|Default, Ok)
37{
38 m_unit = KoUnit::U_PT;
39 init();
40}
41
42void KivioStencilFormatDlg::init()
43{
44 TQWidget* mainWidget = new TQWidget(this);
45 setMainWidget(mainWidget);
46 TQGridLayout* gl = new TQGridLayout(mainWidget, 3, 2, KDialog::marginHint(), KDialog::spacingHint());
47
48 TQLabel* lineWidthLbl = new TQLabel(i18n("Line &width:"), mainWidget);
49 m_lineWidthUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
50 lineWidthLbl->setBuddy(m_lineWidthUSBox);
51 TQLabel* lineColorLbl = new TQLabel(i18n("Line &color:"), mainWidget);
52 m_lineCBtn = new KColorButton(mainWidget);
53 lineColorLbl->setBuddy(m_lineCBtn);
54 TQLabel* patternLbl = new TQLabel(i18n("Line &style:"), mainWidget);
55 m_patternCBox = new KComboBox(mainWidget);
56 patternLbl->setBuddy(m_patternCBox);
57 initLinePatterns();
58 TQLabel* lineEndStyleLbl = new TQLabel(i18n("Line &end style:"), mainWidget);
59 m_lineEndStyleCBox = new KComboBox(mainWidget);
60 lineEndStyleLbl->setBuddy(m_lineEndStyleCBox);
61 initLineEndStyles();
62 TQLabel* fillColorLbl = new TQLabel(i18n("&Fill color:"), mainWidget);
63 m_fillCBtn = new KColorButton(mainWidget);
64 fillColorLbl->setBuddy(m_fillCBtn);
65 TQLabel* fillPatternLbl = new TQLabel(i18n("F&ill style:"), mainWidget);
66 m_fillPatternCBox = new KComboBox(mainWidget);
67 fillPatternLbl->setBuddy(m_fillPatternCBox);
68 initFillPatterns();
69
70 gl->addWidget(lineWidthLbl, 0, 0);
71 gl->addWidget(m_lineWidthUSBox, 0, 1);
72 gl->addWidget(lineColorLbl, 1, 0);
73 gl->addWidget(m_lineCBtn, 1, 1);
74 gl->addWidget(patternLbl, 2, 0);
75 gl->addWidget(m_patternCBox, 2, 1);
76 gl->addWidget(lineEndStyleLbl, 3, 0);
77 gl->addWidget(m_lineEndStyleCBox, 3, 1);
78 gl->addWidget(fillColorLbl, 4, 0);
79 gl->addWidget(m_fillCBtn, 4, 1);
80 gl->addWidget(fillPatternLbl, 5, 0);
81 gl->addWidget(m_fillPatternCBox, 5, 1);
82}
83
84void KivioStencilFormatDlg::initLinePatterns()
85{
86 TQBitmap mask;
87 TQPixmap pix(m_patternCBox->width(), 17);
88 TQPainter p(&pix, m_patternCBox);
89 TQPen pen;
90 pen.setColor(TQColor(0, 0, 0));
91 pen.setWidth(3);
92
93 for (int i = NoPen; i <= DashDotDotLine ; i++ ) {
94 pix.fill(white);
95 pen.setStyle(static_cast<TQt::PenStyle>(i));
96 p.setPen(pen);
97 p.drawLine(0, 8, pix.width(), 8);
98
99 mask = pix;
100 pix.setMask(mask);
101 m_patternCBox->insertItem(pix, i);
102 }
103
104 p.end();
105}
106
107void KivioStencilFormatDlg::initFillPatterns()
108{
109 TQBitmap mask;
110 TQPixmap pix(m_fillPatternCBox->width(), m_fillPatternCBox->fontMetrics().height() + 4);
111 TQPainter p(&pix, m_fillPatternCBox);
112 TQBrush brush;
113 brush.setColor(TQColor(0, 0, 0));
114
115 for (int i = NoBrush; i <= DiagCrossPattern; i++ ) {
116 pix.fill(white);
117 brush.setStyle(static_cast<TQt::BrushStyle>(i));
118 p.setBrush(brush);
119 p.fillRect(0, 0, pix.width(), pix.height(), brush);
120
121 m_fillPatternCBox->insertItem(pix, i);
122 }
123
124 p.end();
125}
126
127void KivioStencilFormatDlg::initLineEndStyles()
128{
129 TQBitmap mask;
130 TQPixmap pix(m_lineEndStyleCBox->width(), 17);
131 TQPainter p(&pix, m_lineEndStyleCBox);
132 TQPen pen;
133 pen.setColor(TQColor(0, 0, 0));
134 pen.setWidth(4);
135 pen.setStyle(TQt::SolidLine);
136 pen.setJoinStyle(TQt::RoundJoin);
137 p.setBrush(white);
138
139 for (int i = 0; i < 3; i++) {
140 pix.fill(white);
141 pen.setCapStyle(static_cast<TQt::PenCapStyle>(i * 0x10));
142 p.setPen(pen);
143 p.drawLine(6, 8, pix.width() - 12, 8);
144
145 mask = pix;
146 pix.setMask(mask);
147 m_lineEndStyleCBox->insertItem(pix, i);
148 }
149
150 p.end();
151}
152
153double KivioStencilFormatDlg::lineWidth()
154{
155 return m_lineWidthUSBox->value();
156}
157
158TQColor KivioStencilFormatDlg::lineColor()
159{
160 return m_lineCBtn->color();
161}
162
163int KivioStencilFormatDlg::linePattern()
164{
165 return m_patternCBox->currentItem();
166}
167
168TQColor KivioStencilFormatDlg::fillColor()
169{
170 return m_fillCBtn->color();
171}
172
173int KivioStencilFormatDlg::fillPattern()
174{
175 return m_fillPatternCBox->currentItem();
176}
177
178int KivioStencilFormatDlg::lineEndStyle()
179{
180 return m_lineEndStyleCBox->currentItem() * 0x10;
181}
182
183void KivioStencilFormatDlg::setLineWidth(double w, KoUnit::Unit u)
184{
185 m_unit = u;
186 m_lineWidthUSBox->setUnit(u);
187 m_lineWidthUSBox->setValue(KoUnit::toUserValue(w, u));
188}
189
190void KivioStencilFormatDlg::setLineColor(TQColor c)
191{
192 m_lineCBtn->setColor(c);
193}
194
195void KivioStencilFormatDlg::setLinePattern(int p)
196{
197 m_patternCBox->setCurrentItem(p);
198}
199
200void KivioStencilFormatDlg::setFillColor(TQColor c)
201{
202 m_fillCBtn->setColor(c);
203}
204
205void KivioStencilFormatDlg::setFillPattern(int p)
206{
207 m_fillPatternCBox->setCurrentItem(p);
208}
209
210void KivioStencilFormatDlg::setLineEndStyle(int s)
211{
212 m_lineEndStyleCBox->setCurrentItem(s / 0x10);
213}
214
215void KivioStencilFormatDlg::slotDefault()
216{
217 setLineWidth(1.0, m_unit);
218 setLineColor(TQColor(0, 0, 0));
219 setLinePattern(1);
220 setFillColor(TQColor(255, 255, 255));
221 setFillPattern(1);
222}
223
224#include "kiviostencilformatdlg.moc"