~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to kivio/kiviopart/ui/kivioarrowheadformatdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
#include "kivioarrowheadformatdlg.h"
 
21
 
 
22
#include <qlabel.h>
 
23
#include <qgroupbox.h>
 
24
#include <qlayout.h>
 
25
#include <qbitmap.h>
 
26
#include <qpixmap.h>
 
27
#include <qpainter.h>
 
28
 
 
29
#include <kcombobox.h>
 
30
#include <klocale.h>
 
31
 
 
32
#include <koUnitWidgets.h>
 
33
 
 
34
#include "kivio_view.h"
 
35
#include "kivioglobal.h"
 
36
 
 
37
KivioArrowHeadFormatDlg::KivioArrowHeadFormatDlg(KivioView* parent, const char* name)
 
38
  : KDialogBase(parent, name, true, i18n("Arrowhead Format"), Ok|Cancel|Default, Ok)
 
39
{
 
40
  m_unit = KoUnit::U_PT;
 
41
  init();
 
42
}
 
43
 
 
44
void KivioArrowHeadFormatDlg::init()
 
45
{
 
46
  QWidget* mainWidget = new QWidget(this);
 
47
  setMainWidget(mainWidget);
 
48
  QGridLayout* gl = new QGridLayout(mainWidget, 2, 1, KDialog::marginHint(), KDialog::spacingHint());
 
49
 
 
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);
 
61
 
 
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);
 
73
 
 
74
  gl->addWidget(startGBox, 0, 0);
 
75
  gl->addWidget(endGBox, 1, 0);
 
76
}
 
77
 
 
78
void KivioArrowHeadFormatDlg::loadArrowHeads(KComboBox* combo)
 
79
{
 
80
  QBitmap mask;
 
81
  QPixmap pixAll = Kivio::arrowHeadPixmap();
 
82
  int tw = combo->fontMetrics().width(" 99:");
 
83
 
 
84
  QPixmap pix(pixAll.width() + tw + 3, 17);
 
85
  QPainter p(&pix, combo);
 
86
  int cindex = 0;
 
87
 
 
88
  // insert item "0: None"
 
89
  pix.fill(white);
 
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"));
 
92
  mask = pix;
 
93
  pix.setMask(mask);
 
94
  combo->insertItem(pix,cindex++);
 
95
 
 
96
  for (int y = 0; y < pixAll.height(); y += 17 ) {
 
97
    pix.fill(white);
 
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());
 
100
 
 
101
    mask = pix;
 
102
    pix.setMask(mask);
 
103
    combo->insertItem(pix,cindex++);
 
104
  }
 
105
 
 
106
  p.end();
 
107
}
 
108
 
 
109
int KivioArrowHeadFormatDlg::startAHType()
 
110
{
 
111
  return m_startAHTypeCBox->currentItem();
 
112
}
 
113
 
 
114
double KivioArrowHeadFormatDlg::startAHWidth()
 
115
{
 
116
  return KoUnit::ptFromUnit(m_startAHWidthUSBox->value(), m_unit);
 
117
}
 
118
 
 
119
double KivioArrowHeadFormatDlg::startAHHeight()
 
120
{
 
121
  return KoUnit::ptFromUnit(m_startAHHeightUSBox->value(), m_unit);
 
122
}
 
123
 
 
124
int KivioArrowHeadFormatDlg::endAHType()
 
125
{
 
126
  return m_endAHTypeCBox->currentItem();
 
127
}
 
128
 
 
129
double KivioArrowHeadFormatDlg::endAHWidth()
 
130
{
 
131
  return KoUnit::ptFromUnit(m_endAHWidthUSBox->value(), m_unit);
 
132
}
 
133
 
 
134
double KivioArrowHeadFormatDlg::endAHHeight()
 
135
{
 
136
  return KoUnit::ptFromUnit(m_endAHHeightUSBox->value(), m_unit);
 
137
}
 
138
 
 
139
void KivioArrowHeadFormatDlg::setUnit(KoUnit::Unit u)
 
140
{
 
141
  m_unit = u;
 
142
  m_startAHWidthUSBox->setUnit(u);
 
143
  m_startAHHeightUSBox->setUnit(u);
 
144
  m_endAHWidthUSBox->setUnit(u);
 
145
  m_endAHHeightUSBox->setUnit(u);
 
146
}
 
147
 
 
148
void KivioArrowHeadFormatDlg::setStartAHType(int t)
 
149
{
 
150
  m_startAHTypeCBox->setCurrentItem(t);
 
151
}
 
152
 
 
153
void KivioArrowHeadFormatDlg::setStartAHWidth(double w)
 
154
{
 
155
  m_startAHWidthUSBox->setValue(KoUnit::ptToUnit(w, m_unit));
 
156
}
 
157
 
 
158
void KivioArrowHeadFormatDlg::setStartAHHeight(double h)
 
159
{
 
160
  m_startAHHeightUSBox->setValue(KoUnit::ptToUnit(h, m_unit));
 
161
}
 
162
 
 
163
void KivioArrowHeadFormatDlg::setEndAHType(int t)
 
164
{
 
165
  m_endAHTypeCBox->setCurrentItem(t);
 
166
}
 
167
 
 
168
void KivioArrowHeadFormatDlg::setEndAHWidth(double w)
 
169
{
 
170
  m_endAHWidthUSBox->setValue(KoUnit::ptToUnit(w, m_unit));
 
171
}
 
172
 
 
173
void KivioArrowHeadFormatDlg::setEndAHHeight(double h)
 
174
{
 
175
  m_endAHHeightUSBox->setValue(KoUnit::ptToUnit(h, m_unit));
 
176
}
 
177
 
 
178
void KivioArrowHeadFormatDlg::slotDefault()
 
179
{
 
180
  setStartAHType(0);
 
181
  setEndAHType(0);
 
182
  setStartAHWidth(10.0);
 
183
  setStartAHHeight(10.0);
 
184
  setEndAHWidth(10.0);
 
185
  setEndAHHeight(10.0);
 
186
}
 
187
 
 
188
#include "kivioarrowheadformatdlg.moc"