1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
// -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
/* This file is part of the KDE project
Copyright (C) 2004-2005 Thorsten Zachmann <zachmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KPrPenStyleWidget.h"
#include "penstyle.h"
#include "KPrPBPreview.h"
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqvbox.h>
#include <kcolorbutton.h>
#include <kcombobox.h>
#include <klocale.h>
#include <knuminput.h>
KPrPenStyleWidget::KPrPenStyleWidget( TQWidget *tqparent, const char *name, const KoPenCmd::Pen &pen, bool configureLineEnds )
: TQWidget( tqparent, name )
, m_pen( pen )
{
TQVBoxLayout *tqlayout = new TQVBoxLayout( this );
tqlayout->addWidget( m_ui = new PenStyleUI( this ) );
TQSpacerItem* spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
tqlayout->addItem( spacer );
connect( m_ui->colorChooser, TQT_SIGNAL( changed( const TQColor& ) ),
this, TQT_SLOT( slotPenChanged() ) );
m_ui->styleCombo->insertItem( i18n( "No Outline" ) );
m_ui->styleCombo->insertItem( "__________" );
m_ui->styleCombo->insertItem( "__ __ __ __" );
m_ui->styleCombo->insertItem( "_ _ _ _ _ _" );
m_ui->styleCombo->insertItem( "__ _ __ _ __" );
m_ui->styleCombo->insertItem( "__ _ _ __ _" );
m_ui->widthInput->setRange( 1, 10, 1, false);
connect( m_ui->styleCombo, TQT_SIGNAL( activated( int ) ),
this, TQT_SLOT( slotPenChanged() ) );
connect( m_ui->widthInput, TQT_SIGNAL( valueChanged( double ) ),
this, TQT_SLOT( slotPenChanged() ) );
m_ui->lineBeginCombo->insertItem( i18n("Normal") );
m_ui->lineBeginCombo->insertItem( i18n("Arrow") );
m_ui->lineBeginCombo->insertItem( i18n("Square") );
m_ui->lineBeginCombo->insertItem( i18n("Circle") );
m_ui->lineBeginCombo->insertItem( i18n("Line Arrow") );
m_ui->lineBeginCombo->insertItem( i18n("Dimension Line") );
m_ui->lineBeginCombo->insertItem( i18n("Double Arrow") );
m_ui->lineBeginCombo->insertItem( i18n("Double Line Arrow") );
connect( m_ui->lineBeginCombo, TQT_SIGNAL( activated( int ) ),
this, TQT_SLOT( slotLineBeginChanged() ) );
m_ui->lineEndCombo->insertItem( i18n("Normal") );
m_ui->lineEndCombo->insertItem( i18n("Arrow") );
m_ui->lineEndCombo->insertItem( i18n("Square") );
m_ui->lineEndCombo->insertItem( i18n("Circle") );
m_ui->lineEndCombo->insertItem( i18n("Line Arrow") );
m_ui->lineEndCombo->insertItem( i18n("Dimension Line") );
m_ui->lineEndCombo->insertItem( i18n("Double Arrow") );
m_ui->lineEndCombo->insertItem( i18n("Double Line Arrow") );
connect( m_ui->lineEndCombo, TQT_SIGNAL( activated( int ) ),
this, TQT_SLOT( slotLineEndChanged() ) );
if ( !configureLineEnds )
m_ui->arrowGroup->hide();
//m_ui->arrowGroup->setEnabled( configureLineEnds );
slotReset();
}
KPrPenStyleWidget::~KPrPenStyleWidget()
{
delete m_ui;
}
void KPrPenStyleWidget::setPen( const KoPen &pen )
{
m_ui->colorChooser->setColor( pen.color() );
switch ( pen.style() )
{
case NoPen:
m_ui->styleCombo->setCurrentItem( 0 );
break;
case SolidLine:
m_ui->styleCombo->setCurrentItem( 1 );
break;
case DashLine:
m_ui->styleCombo->setCurrentItem( 2 );
break;
case DotLine:
m_ui->styleCombo->setCurrentItem( 3 );
break;
case DashDotLine:
m_ui->styleCombo->setCurrentItem( 4 );
break;
case DashDotDotLine:
m_ui->styleCombo->setCurrentItem( 5 );
break;
case MPenStyle:
break; // not supported.
}
m_ui->widthInput->setValue( pen.pointWidth() );
m_ui->pbPreview->setPen( pen );
}
void KPrPenStyleWidget::setLineBegin( LineEnd lb )
{
m_ui->lineBeginCombo->setCurrentItem( (int)lb );
m_ui->pbPreview->setLineBegin( lb );
}
void KPrPenStyleWidget::setLineEnd( LineEnd le )
{
m_ui->lineEndCombo->setCurrentItem( (int)le );
m_ui->pbPreview->setLineEnd( le );
}
KoPen KPrPenStyleWidget::getKPPen() const
{
KoPen pen;
switch ( m_ui->styleCombo->currentItem() )
{
case 0:
pen.setStyle( Qt::NoPen );
break;
case 1:
pen.setStyle( Qt::SolidLine );
break;
case 2:
pen.setStyle( Qt::DashLine );
break;
case 3:
pen.setStyle( Qt::DotLine );
break;
case 4:
pen.setStyle( Qt::DashDotLine );
break;
case 5:
pen.setStyle( Qt::DashDotDotLine );
break;
}
pen.setColor( m_ui->colorChooser->color() );
pen.setPointWidth( m_ui->widthInput->value() );
return pen;
}
LineEnd KPrPenStyleWidget::getLineBegin() const
{
return (LineEnd) m_ui->lineBeginCombo->currentItem();
}
LineEnd KPrPenStyleWidget::getLineEnd() const
{
return (LineEnd) m_ui->lineEndCombo->currentItem();
}
int KPrPenStyleWidget::getPenConfigChange() const
{
int flags = 0;
if ( getLineEnd() != m_pen.lineEnd )
flags = flags | KoPenCmd::LineEnd;
if ( getLineBegin() != m_pen.lineBegin )
flags = flags | KoPenCmd::LineBegin;
if ( getKPPen().color() != m_pen.pen.color() )
flags = flags | KoPenCmd::Color;
if ( getKPPen().style() != m_pen.pen.style() )
flags = flags | KoPenCmd::Style;
if ( getKPPen().pointWidth() != m_pen.pen.pointWidth() )
flags = flags | KoPenCmd::Width;
return flags;
}
KoPenCmd::Pen KPrPenStyleWidget::getPen() const
{
KoPenCmd::Pen pen( getKPPen(), getLineBegin(), getLineEnd() );
return pen;
}
void KPrPenStyleWidget::setPen( const KoPenCmd::Pen &pen )
{
m_pen = pen;
slotReset();
}
void KPrPenStyleWidget::apply()
{
int flags = getPenConfigChange();
if ( flags & KoPenCmd::LineEnd )
m_pen.lineEnd = getLineEnd();
if ( flags & KoPenCmd::LineBegin )
m_pen.lineBegin = getLineBegin();
if ( flags & KoPenCmd::Color )
m_pen.pen.setColor( getKPPen().color() );
if ( flags & KoPenCmd::Style )
m_pen.pen.setStyle( getKPPen().style() );
if ( flags & KoPenCmd::Width )
m_pen.pen.setPointWidth( getKPPen().pointWidth() );
}
void KPrPenStyleWidget::slotReset()
{
setPen( m_pen.pen );
m_ui->widthLabel->setEnabled( m_pen.pen.style() != NoPen );
m_ui->widthInput->setEnabled( m_pen.pen.style() != NoPen );
setLineBegin( m_pen.lineBegin );
setLineEnd( m_pen.lineEnd );
}
void KPrPenStyleWidget::slotPenChanged()
{
KoPen pen = getKPPen();
m_ui->widthLabel->setEnabled( pen.style() != NoPen );
m_ui->widthInput->setEnabled( pen.style() != NoPen );
m_ui->pbPreview->setPen( pen );
}
void KPrPenStyleWidget::slotLineBeginChanged()
{
m_ui->pbPreview->setLineBegin( getLineBegin() );
}
void KPrPenStyleWidget::slotLineEndChanged()
{
m_ui->pbPreview->setLineEnd( getLineEnd() );
}
#include "KPrPenStyleWidget.moc"
|