1
/* This file is part of the KDE project
2
Copyright (C) 2003 Peter Simonsson <psn@linux.se>
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.
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.
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., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
20
#include "kivioarrowheadformatdlg.h"
23
#include <qgroupbox.h>
29
#include <kcombobox.h>
32
#include <koUnitWidgets.h>
34
#include "kivio_view.h"
35
#include "kivioglobal.h"
37
KivioArrowHeadFormatDlg::KivioArrowHeadFormatDlg(KivioView* parent, const char* name)
38
: KDialogBase(parent, name, true, i18n("Arrowhead Format"), Ok|Cancel|Default, Ok)
40
m_unit = KoUnit::U_PT;
44
void KivioArrowHeadFormatDlg::init()
46
QWidget* mainWidget = new QWidget(this);
47
setMainWidget(mainWidget);
48
QGridLayout* gl = new QGridLayout(mainWidget, 2, 1, KDialog::marginHint(), KDialog::spacingHint());
50
QGroupBox* startGBox = new QGroupBox(2, Qt::Horizontal, i18n("Start Arrowhead"), mainWidget);
51
QLabel* startAHTypeLbl = new QLabel(i18n("&Type:"), startGBox);
52
m_startAHTypeCBox = new KComboBox(startGBox);
53
loadArrowHeads(m_startAHTypeCBox);
54
startAHTypeLbl->setBuddy(m_startAHTypeCBox);
55
QLabel* startAHWidthLbl = new QLabel(i18n("&Width:"), startGBox);
56
m_startAHWidthUSBox = new KoUnitDoubleSpinBox(startGBox, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
57
startAHWidthLbl->setBuddy(m_startAHWidthUSBox);
58
QLabel* startAHHeightLbl = new QLabel(i18n("&Height:"), startGBox);
59
m_startAHHeightUSBox = new KoUnitDoubleSpinBox(startGBox, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
60
startAHHeightLbl->setBuddy(m_startAHHeightUSBox);
62
QGroupBox* endGBox = new QGroupBox(2, Qt::Horizontal, i18n("End Arrowhead"), mainWidget);
63
QLabel* endAHTypeLbl = new QLabel(i18n("&Type:"), endGBox);
64
m_endAHTypeCBox = new KComboBox(endGBox);
65
loadArrowHeads(m_endAHTypeCBox);
66
endAHTypeLbl->setBuddy(m_endAHTypeCBox);
67
QLabel* endAHWidthLbl = new QLabel(i18n("&Width:"), endGBox);
68
m_endAHWidthUSBox = new KoUnitDoubleSpinBox(endGBox, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
69
endAHWidthLbl->setBuddy(m_endAHWidthUSBox);
70
QLabel* endAHHeightLbl = new QLabel(i18n("&Height:"), endGBox);
71
m_endAHHeightUSBox = new KoUnitDoubleSpinBox(endGBox, 0.0, 1000.0, 0.1, 1.0, m_unit, 2);
72
endAHHeightLbl->setBuddy(m_endAHHeightUSBox);
74
gl->addWidget(startGBox, 0, 0);
75
gl->addWidget(endGBox, 1, 0);
78
void KivioArrowHeadFormatDlg::loadArrowHeads(KComboBox* combo)
81
QPixmap pixAll = Kivio::arrowHeadPixmap();
82
int tw = combo->fontMetrics().width(" 99:");
84
QPixmap pix(pixAll.width() + tw + 3, 17);
85
QPainter p(&pix, combo);
88
// insert item "0: None"
90
p.drawText(0,0,tw,pix.height(),AlignRight|AlignVCenter,QString("%1:").arg(cindex));
91
p.drawText(tw+3,0,pix.width()-tw-3,pix.height(),AlignLeft|AlignVCenter,i18n("no line end", "None"));
94
combo->insertItem(pix,cindex++);
96
for (int y = 0; y < pixAll.height(); y += 17 ) {
98
p.drawText(0,0,tw,pix.height(),AlignRight|AlignVCenter,QString("%1:").arg(cindex));
99
p.drawPixmap(tw+3,0,pixAll,0,y,pix.width(),pix.height());
103
combo->insertItem(pix,cindex++);
109
int KivioArrowHeadFormatDlg::startAHType()
111
return m_startAHTypeCBox->currentItem();
114
double KivioArrowHeadFormatDlg::startAHWidth()
116
return KoUnit::ptFromUnit(m_startAHWidthUSBox->value(), m_unit);
119
double KivioArrowHeadFormatDlg::startAHHeight()
121
return KoUnit::ptFromUnit(m_startAHHeightUSBox->value(), m_unit);
124
int KivioArrowHeadFormatDlg::endAHType()
126
return m_endAHTypeCBox->currentItem();
129
double KivioArrowHeadFormatDlg::endAHWidth()
131
return KoUnit::ptFromUnit(m_endAHWidthUSBox->value(), m_unit);
134
double KivioArrowHeadFormatDlg::endAHHeight()
136
return KoUnit::ptFromUnit(m_endAHHeightUSBox->value(), m_unit);
139
void KivioArrowHeadFormatDlg::setUnit(KoUnit::Unit u)
142
m_startAHWidthUSBox->setUnit(u);
143
m_startAHHeightUSBox->setUnit(u);
144
m_endAHWidthUSBox->setUnit(u);
145
m_endAHHeightUSBox->setUnit(u);
148
void KivioArrowHeadFormatDlg::setStartAHType(int t)
150
m_startAHTypeCBox->setCurrentItem(t);
153
void KivioArrowHeadFormatDlg::setStartAHWidth(double w)
155
m_startAHWidthUSBox->setValue(KoUnit::ptToUnit(w, m_unit));
158
void KivioArrowHeadFormatDlg::setStartAHHeight(double h)
160
m_startAHHeightUSBox->setValue(KoUnit::ptToUnit(h, m_unit));
163
void KivioArrowHeadFormatDlg::setEndAHType(int t)
165
m_endAHTypeCBox->setCurrentItem(t);
168
void KivioArrowHeadFormatDlg::setEndAHWidth(double w)
170
m_endAHWidthUSBox->setValue(KoUnit::ptToUnit(w, m_unit));
173
void KivioArrowHeadFormatDlg::setEndAHHeight(double h)
175
m_endAHHeightUSBox->setValue(KoUnit::ptToUnit(h, m_unit));
178
void KivioArrowHeadFormatDlg::slotDefault()
182
setStartAHWidth(10.0);
183
setStartAHHeight(10.0);
185
setEndAHHeight(10.0);
188
#include "kivioarrowheadformatdlg.moc"