kivio

kivioarrowheadformatdlg.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 "kivioarrowheadformatdlg.h"
21
22#include <tqlabel.h>
23#include <tqgroupbox.h>
24#include <tqlayout.h>
25#include <tqbitmap.h>
26#include <tqpixmap.h>
27#include <tqpainter.h>
28#include <tqframe.h>
29
30#include <kcombobox.h>
31#include <tdelocale.h>
32#include <kiconloader.h>
33
34#include <KoUnitWidgets.h>
35
36#include "kivio_view.h"
37#include "kivioglobal.h"
38
39KivioArrowHeadFormatDlg::KivioArrowHeadFormatDlg(KivioView* parent, const char* name)
40 : KDialogBase(parent, name, true, i18n("Arrowhead Format"), Ok|Cancel|Default, Ok)
41{
42 m_unit = KoUnit::U_PT;
43 init();
44}
45
46void KivioArrowHeadFormatDlg::init()
47{
48 TQWidget* mainWidget = new TQWidget(this);
49 setMainWidget(mainWidget);
50 TQGridLayout* gl = new TQGridLayout(mainWidget, 2, 1, 0, KDialog::spacingHint());
51
52 TQLabel* startAHHeaderIcon = new TQLabel(mainWidget);
53 startAHHeaderIcon->setPixmap(SmallIcon("start_arrowhead", 16));
54 startAHHeaderIcon->setFixedSize(16, 16);
55 TQLabel* startAHHeaderLabel = new TQLabel(i18n("<b>Arrowhead at Origin</b>"), mainWidget);
56 TQFont font = startAHHeaderLabel->font();
57 TQFrame* startAHHeaderLine = new TQFrame(mainWidget);
58 startAHHeaderLine->setFrameStyle(TQFrame::HLine|TQFrame::Plain);
59 TQLabel* startAHTypeLbl = new TQLabel(i18n("&Type:"), mainWidget);
60 m_startAHTypeCBox = new KComboBox(mainWidget);
61 loadArrowHeads(m_startAHTypeCBox);
62 startAHTypeLbl->setBuddy(m_startAHTypeCBox);
63 TQLabel* startAHWidthLbl = new TQLabel(i18n("&Width:"), mainWidget);
64 m_startAHWidthUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
65 startAHWidthLbl->setBuddy(m_startAHWidthUSBox);
66 TQLabel* startAHHeightLbl = new TQLabel(i18n("&Length:"), mainWidget);
67 m_startAHHeightUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
68 startAHHeightLbl->setBuddy(m_startAHHeightUSBox);
69
70 TQLabel* endAHHeaderIcon = new TQLabel(mainWidget);
71 endAHHeaderIcon->setPixmap(SmallIcon("end_arrowhead", 16));
72 endAHHeaderIcon->setFixedSize(16, 16);
73 TQLabel* endAHHeaderLabel = new TQLabel(i18n("<b>Arrowhead at End</b>"), mainWidget);
74 TQFrame* endAHHeaderLine = new TQFrame(mainWidget);
75 endAHHeaderLine->setFrameStyle(TQFrame::HLine|TQFrame::Plain);
76 TQLabel* endAHTypeLbl = new TQLabel(i18n("T&ype:"), mainWidget);
77 m_endAHTypeCBox = new KComboBox(mainWidget);
78 loadArrowHeads(m_endAHTypeCBox);
79 endAHTypeLbl->setBuddy(m_endAHTypeCBox);
80 TQLabel* endAHWidthLbl = new TQLabel(i18n("W&idth:"), mainWidget);
81 m_endAHWidthUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
82 endAHWidthLbl->setBuddy(m_endAHWidthUSBox);
83 TQLabel* endAHHeightLbl = new TQLabel(i18n("L&ength:"), mainWidget);
84 m_endAHHeightUSBox = new KoUnitDoubleSpinBox(mainWidget, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
85 endAHHeightLbl->setBuddy(m_endAHHeightUSBox);
86
87 gl->addWidget(startAHHeaderIcon, 0, 0);
88 gl->addMultiCellWidget(startAHHeaderLabel, 0, 0, 1, 2);
89 gl->addMultiCellWidget(startAHHeaderLine, 1, 1, 0, 2);
90 gl->addMultiCellWidget(startAHTypeLbl, 2, 2, 0, 1);
91 gl->addWidget(m_startAHTypeCBox, 2, 2);
92 gl->addMultiCellWidget(startAHWidthLbl, 3, 3, 0, 1);
93 gl->addWidget(m_startAHWidthUSBox, 3, 2);
94 gl->addMultiCellWidget(startAHHeightLbl, 4, 4, 0, 1);
95 gl->addWidget(m_startAHHeightUSBox, 4, 2);
96
97 gl->addMultiCell(new TQSpacerItem(KDialog::marginHint(), KDialog::marginHint(),
98 TQSizePolicy::Minimum, TQSizePolicy::Fixed), 5, 5, 0, 2);
99
100 gl->addWidget(endAHHeaderIcon, 6, 0);
101 gl->addMultiCellWidget(endAHHeaderLabel, 6, 6, 1, 2);
102 gl->addMultiCellWidget(endAHHeaderLine, 7, 7, 0, 2);
103 gl->addMultiCellWidget(endAHTypeLbl, 8, 8, 0, 1);
104 gl->addWidget(m_endAHTypeCBox, 8, 2);
105 gl->addMultiCellWidget(endAHWidthLbl, 9, 9, 0, 1);
106 gl->addWidget(m_endAHWidthUSBox, 9, 2);
107 gl->addMultiCellWidget(endAHHeightLbl, 10, 10, 0, 1);
108 gl->addWidget(m_endAHHeightUSBox, 10, 2);
109 gl->setRowStretch(11, 10);
110}
111
112void KivioArrowHeadFormatDlg::loadArrowHeads(KComboBox* combo)
113{
114 TQBitmap mask;
115 TQPixmap pixAll = Kivio::arrowHeadPixmap();
116 TQPixmap pix(pixAll.width(), 17);
117 TQPainter p(&pix, combo);
118 int cindex = 0;
119
120 // insert item "None"
121 combo->insertItem(i18n("no line end", "None"),cindex++);
122
123 for (int y = 0; y < pixAll.height(); y += 17 ) {
124 p.drawPixmap(0, 0, pixAll, 0, y, pix.width(), pix.height());
125 combo->insertItem(pix,cindex++);
126 }
127
128 p.end();
129}
130
131int KivioArrowHeadFormatDlg::startAHType()
132{
133 return m_startAHTypeCBox->currentItem();
134}
135
136double KivioArrowHeadFormatDlg::startAHWidth()
137{
138 return m_startAHWidthUSBox->value();
139}
140
141double KivioArrowHeadFormatDlg::startAHHeight()
142{
143 return m_startAHHeightUSBox->value();
144}
145
146int KivioArrowHeadFormatDlg::endAHType()
147{
148 return m_endAHTypeCBox->currentItem();
149}
150
151double KivioArrowHeadFormatDlg::endAHWidth()
152{
153 return m_endAHWidthUSBox->value();
154}
155
156double KivioArrowHeadFormatDlg::endAHHeight()
157{
158 return m_endAHHeightUSBox->value();
159}
160
161void KivioArrowHeadFormatDlg::setUnit(KoUnit::Unit u)
162{
163 m_unit = u;
164 m_startAHWidthUSBox->setUnit(u);
165 m_startAHHeightUSBox->setUnit(u);
166 m_endAHWidthUSBox->setUnit(u);
167 m_endAHHeightUSBox->setUnit(u);
168}
169
170void KivioArrowHeadFormatDlg::setStartAHType(int t)
171{
172 m_startAHTypeCBox->setCurrentItem(t);
173}
174
175void KivioArrowHeadFormatDlg::setStartAHWidth(double w)
176{
177 m_startAHWidthUSBox->setValue(KoUnit::toUserValue(w, m_unit));
178}
179
180void KivioArrowHeadFormatDlg::setStartAHHeight(double h)
181{
182 m_startAHHeightUSBox->setValue(KoUnit::toUserValue(h, m_unit));
183}
184
185void KivioArrowHeadFormatDlg::setEndAHType(int t)
186{
187 m_endAHTypeCBox->setCurrentItem(t);
188}
189
190void KivioArrowHeadFormatDlg::setEndAHWidth(double w)
191{
192 m_endAHWidthUSBox->setValue(KoUnit::toUserValue(w, m_unit));
193}
194
195void KivioArrowHeadFormatDlg::setEndAHHeight(double h)
196{
197 m_endAHHeightUSBox->setValue(KoUnit::toUserValue(h, m_unit));
198}
199
200void KivioArrowHeadFormatDlg::slotDefault()
201{
202 setStartAHType(0);
203 setEndAHType(0);
204 setStartAHWidth(10.0);
205 setStartAHHeight(10.0);
206 setEndAHWidth(10.0);
207 setEndAHHeight(10.0);
208}
209
210#include "kivioarrowheadformatdlg.moc"