kpresenter

KPrPropertyEditor.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
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#include "KPrPropertyEditor.h"
20
21#include "KPrObject.h"
22#include "KPrPage.h"
23#include "KPrDocument.h"
24#include "KPrUtils.h"
25#include "KPrCommand.h"
26#include "KPrPenStyleWidget.h"
27#include "KPrBrushProperty.h"
28#include "KPrRectProperty.h"
29#include "KPrPolygonProperty.h"
30#include "KPrPieProperty.h"
31#include "KPrPictureProperty.h"
32#include "KPrTextProperty.h"
33#include "KPrObjectProperties.h"
34
35#include <tdelocale.h>
36#include <kstdguiitem.h>
37
38KPrPropertyEditor::KPrPropertyEditor( TQWidget *parent, const char *name, KPrPage *page, KPrDocument *doc )
39 : TQTabDialog( parent, name, true )
40 , m_page( page )
41 , m_doc( doc )
42 , m_objects( page->getSelectedObjects() )
43 , m_penProperty( 0 )
44 , m_brushProperty( 0 )
45 , m_rectProperty( 0 )
46 , m_polygonProperty( 0 )
47 , m_pieProperty( 0 )
48 , m_pictureProperty( 0 )
49 , m_textProperty( 0 )
50 , m_generalProperty( 0 )
51 , m_objectProperties( 0 )
52{
53 setCancelButton( KStdGuiItem::cancel().text() );
54 setOkButton( KStdGuiItem::ok().text() );
55 setApplyButton( KStdGuiItem::apply().text() );
56
57 connect( this, TQ_SIGNAL( applyButtonPressed() ), this, TQ_SLOT( slotDone() ) );
58
59 m_objectProperties = new KPrObjectProperties( m_objects );
60
61 setupTabs();
62}
63
64
65KPrPropertyEditor::~KPrPropertyEditor()
66{
67 delete m_objectProperties;
68}
69
70
71KCommand * KPrPropertyEditor::getCommand()
72{
73 KMacroCommand *macro = 0;
74
75 if ( m_penProperty )
76 {
77 int change = m_penProperty->getPenConfigChange();
78 if ( change )
79 {
80 KoPenCmd::Pen pen( m_penProperty->getPen() );
81
82 KoPenCmd *cmd = new KoPenCmd( i18n( "Apply Styles" ), m_objects, pen, m_doc, m_page, change );
83
84 if ( !macro )
85 {
86 macro = new KMacroCommand( i18n( "Apply Properties" ) );
87 }
88
89 macro->addCommand( cmd );
90 }
91 }
92
93 if ( m_brushProperty )
94 {
95 int change = m_brushProperty->getBrushPropertyChange();
96 if ( change )
97 {
98 KPrBrushCmd::Brush brush( m_brushProperty->getBrush() );
99
100 KPrBrushCmd *cmd = new KPrBrushCmd( i18n( "Apply Styles" ), m_objects, brush, m_doc, m_page, change );
101
102 if ( !macro )
103 {
104 macro = new KMacroCommand( i18n( "Apply Properties" ) );
105 }
106
107 macro->addCommand( cmd );
108 }
109 }
110
111 if ( m_rectProperty )
112 {
113 int change = m_rectProperty->getRectPropertyChange();
114
115 if ( change )
116 {
117 KPrRectValueCmd::RectValues rectValue( m_rectProperty->getRectValues() );
118
119 KPrRectValueCmd *cmd = new KPrRectValueCmd( i18n( "Apply Styles" ), m_objects, rectValue, m_doc, m_page, change );
120
121 if ( !macro )
122 {
123 macro = new KMacroCommand( i18n( "Apply Properties" ) );
124 }
125
126 macro->addCommand( cmd );
127 }
128 }
129
130 if ( m_polygonProperty )
131 {
132 int change = m_polygonProperty->getPolygonPropertyChange();
133
134 if ( change )
135 {
136 KPrPolygonSettingCmd::PolygonSettings polygonSettings( m_polygonProperty->getPolygonSettings() );
137
138 KPrPolygonSettingCmd *cmd = new KPrPolygonSettingCmd( i18n("Apply Styles"), polygonSettings,
139 m_objects, m_doc, m_page, change );
140
141 if ( !macro )
142 {
143 macro = new KMacroCommand( i18n( "Apply Properties" ) );
144 }
145
146 macro->addCommand( cmd );
147 }
148 }
149
150 if ( m_pieProperty )
151 {
152 int change = m_pieProperty->getPiePropertyChange();
153
154 if ( change )
155 {
156 KPrPieValueCmd *cmd = new KPrPieValueCmd( i18n("Apply Styles"), m_pieProperty->getPieValues(),
157 m_objects, m_doc, m_page, change );
158 if ( !macro )
159 {
160 macro = new KMacroCommand( i18n( "Apply Properties" ) );
161 }
162
163 macro->addCommand( cmd );
164 }
165 }
166
167 if ( m_pictureProperty )
168 {
169 int change = m_pictureProperty->getPicturePropertyChange();
170
171 if ( change )
172 {
173 KPrPictureSettingCmd *cmd = new KPrPictureSettingCmd( i18n("Apply Styles"), m_pictureProperty->getPictureSettings(),
174 m_objects, m_doc, m_page, change );
175 if ( !macro )
176 {
177 macro = new KMacroCommand( i18n( "Apply Properties" ) );
178 }
179
180 macro->addCommand( cmd );
181 }
182 }
183
184 if ( m_textProperty )
185 {
186 int change = m_textProperty->getTextPropertyChange();
187
188 if ( change )
189 {
190 if ( change & KPrTextProperty::ProtectContent )
191 {
192 KPrProtectContentCommand * cmd = new KPrProtectContentCommand( i18n( "Apply Styles" ), m_objects,
193 m_textProperty->getProtectContent(),
194 m_doc );
195 if ( !macro )
196 {
197 macro = new KMacroCommand( i18n( "Apply Properties" ) );
198 }
199
200 macro->addCommand( cmd );
201 }
202
203 if ( change & KPrTextProperty::Margins )
204 {
205 KPrChangeMarginCommand *cmd = new KPrChangeMarginCommand( i18n( "Apply Styles" ), m_objects,
206 m_textProperty->getMarginsStruct(),
207 m_doc, m_page );
208
209 if ( !macro )
210 {
211 macro = new KMacroCommand( i18n( "Apply Properties" ) );
212 }
213
214 macro->addCommand( cmd );
215 }
216 }
217 }
218
219 if ( m_generalProperty )
220 {
221 int change = m_generalProperty->getGeneralPropertyChange();
222
223 if ( change )
224 {
225 KPrGeneralProperty::GeneralValue generalValue( m_generalProperty->getGeneralValue() );
226
227 if ( change & KPrGeneralProperty::Name )
228 {
229 KCommand *cmd = new KPrNameObjectCommand( i18n( "Name Object" ), generalValue.m_name,
230 m_objects.at( 0 ), m_doc );
231
232 if ( !macro )
233 {
234 macro = new KMacroCommand( i18n( "Apply Properties" ) );
235 }
236
237 macro->addCommand( cmd );
238 }
239
240 if ( change & KPrGeneralProperty::Protect )
241 {
242 KCommand *cmd= new KPrGeometryPropertiesCommand( i18n( "Protect Object" ), m_objects,
243 generalValue.m_protect == STATE_ON,
244 KPrGeometryPropertiesCommand::ProtectSize,m_doc );
245
246 if ( !macro )
247 {
248 macro = new KMacroCommand( i18n( "Apply Properties" ) );
249 }
250
251 macro->addCommand( cmd );
252 }
253
254 if ( change & KPrGeneralProperty::KeepRatio )
255 {
256 KCommand *cmd= new KPrGeometryPropertiesCommand( i18n( "Keep Ratio" ), m_objects,
257 generalValue.m_keepRatio == STATE_ON,
258 KPrGeometryPropertiesCommand::KeepRatio,m_doc );
259 if ( !macro )
260 {
261 macro = new KMacroCommand( i18n( "Apply Properties" ) );
262 }
263
264 macro->addCommand( cmd );
265 }
266
267 if ( change & KPrGeneralProperty::Left
268 || change & KPrGeneralProperty::Top
269 || change & KPrGeneralProperty::Width
270 || change & KPrGeneralProperty::Height )
271 {
272 if ( !macro )
273 {
274 macro = new KMacroCommand( i18n( "Apply Properties" ) );
275 }
276
277 TQPtrListIterator<KPrObject> it( m_objects );
278 for ( ; it.current(); ++it )
279 {
280 KoRect oldRect = it.current()->getRect();
281 KoRect newRect = oldRect;
282 if ( change & KPrGeneralProperty::Left )
283 newRect.moveTopLeft( KoPoint( generalValue.m_rect.left(), newRect.top() ) );
284
285 if ( change & KPrGeneralProperty::Top )
286 newRect.moveTopLeft( KoPoint( newRect.left(), generalValue.m_rect.top() ) );
287
288 if ( change & KPrGeneralProperty::Width )
289 newRect.setWidth( generalValue.m_rect.width() );
290
291 if ( change & KPrGeneralProperty::Height )
292 newRect.setHeight( generalValue.m_rect.height() );
293
294 KCommand *cmd = new KPrResizeCmd( i18n( "Change Size" ),
295 newRect.topLeft() - oldRect.topLeft(),
296 newRect.size() - oldRect.size(),
297 it.current(), m_doc );
298
299 macro->addCommand( cmd );
300 }
301 }
302 }
303 }
304
305 return macro;
306}
307
308
309void KPrPropertyEditor::setupTabs()
310{
311 setupTabGeneral();
312
313 int flags = m_objectProperties->getPropertyFlags();
314
315 if ( flags & KPrObjectProperties::PtPen )
316 setupTabPen( flags & KPrObjectProperties::PtLineEnds );
317
318 if ( flags & KPrObjectProperties::PtBrush )
319 setupTabBrush();
320
321 if ( flags & KPrObjectProperties::PtRectangle )
322 setupTabRect();
323
324 if ( flags & KPrObjectProperties::PtPolygon )
325 setupTabPolygon();
326
327 if ( flags & KPrObjectProperties::PtPie )
328 setupTabPie();
329
330 if ( flags & KPrObjectProperties::PtPicture )
331 setupTabPicture();
332
333 if ( flags & KPrObjectProperties::PtText )
334 setupTabText();
335}
336
337
338void KPrPropertyEditor::setupTabPen( bool configureLineEnds )
339{
340 if ( m_penProperty == 0 )
341 {
342 KoPenCmd::Pen pen( m_objectProperties->getPen() );
343
344 m_penProperty = new KPrPenStyleWidget( this, 0, pen, configureLineEnds );
345 addTab( m_penProperty, i18n( "Outl&ine" ) );
346 }
347}
348
349
350void KPrPropertyEditor::setupTabBrush()
351{
352 if ( m_brushProperty == 0 )
353 {
354 KPrBrushCmd::Brush brush( m_objectProperties->getBrush() );
355
356 m_brushProperty = new KPrBrushProperty( this, 0, brush );
357 addTab( m_brushProperty, i18n( "&Fill" ) );
358 }
359}
360
361
362void KPrPropertyEditor::setupTabRect()
363{
364 if ( m_rectProperty == 0 )
365 {
366 KPrRectValueCmd::RectValues rectValues = m_objectProperties->getRectValues();
367 m_rectProperty = new KPrRectProperty( this, 0, rectValues );
368 addTab( m_rectProperty, i18n( "&Rectangle" ) );
369 }
370}
371
372
373void KPrPropertyEditor::setupTabPolygon()
374{
375 if ( m_polygonProperty == 0 )
376 {
377 KPrPolygonSettingCmd::PolygonSettings polygonSettings = m_objectProperties->getPolygonSettings();
378 m_polygonProperty = new KPrPolygonProperty( this, 0, polygonSettings );
379 addTab( m_polygonProperty, i18n("Polygo&n" ) );
380 }
381}
382
383
384void KPrPropertyEditor::setupTabPie()
385{
386 if ( m_pieProperty == 0 )
387 {
388 m_pieProperty = new KPrPieProperty( this, 0, m_objectProperties->getPieValues() );
389 addTab( m_pieProperty, i18n("&Pie" ) );
390 }
391}
392
393
394void KPrPropertyEditor::setupTabPicture()
395{
396 if ( m_pictureProperty == 0 )
397 {
398 m_pictureProperty = new KPrPictureProperty( this, 0, m_objectProperties->getPixmap(), m_objectProperties->getPictureSettings() );
399 addTab( m_pictureProperty, i18n("Pict&ure" ) );
400 }
401}
402
403
404void KPrPropertyEditor::setupTabText()
405{
406 if ( m_textProperty == 0 )
407 {
408 m_textProperty = new KPrTextProperty( this, 0, m_objectProperties->getMarginsStruct(),
409 m_doc->unit(), m_objectProperties->getProtectContent() );
410 addTab( m_textProperty, i18n("Te&xt" ) );
411 }
412}
413
414
415void KPrPropertyEditor::setupTabGeneral()
416{
417 if ( m_generalProperty == 0 )
418 {
419 KPrGeneralProperty::GeneralValue generalValue = getGeneralValue();
420 m_generalProperty = new KPrGeneralProperty( this, 0, generalValue, m_doc->unit() );
421 addTab( m_generalProperty, i18n( "&General" ) );
422 }
423}
424
425
426KPrGeneralProperty::GeneralValue KPrPropertyEditor::getGeneralValue()
427{
428 KPrGeneralProperty::GeneralValue generalValue;
429
430 if ( m_objects.count() == 1 )
431 {
432 generalValue.m_name = m_objects.at( 0 )->getObjectName();
433 }
434
435 bool protect = false;
436 generalValue.m_protect = STATE_OFF;
437 bool keepRatio = false;
438 generalValue.m_keepRatio = STATE_OFF;
439
440 TQPtrListIterator<KPrObject> it( m_objects );
441 if ( it.current() )
442 {
443 protect = it.current()->isProtect();
444 generalValue.m_protect = protect ? STATE_ON : STATE_OFF;
445 keepRatio = it.current()->isKeepRatio();
446 generalValue.m_keepRatio = keepRatio ? STATE_ON : STATE_OFF;
447 generalValue.m_rect = it.current()->getRect();
448 ++it;
449 }
450
451 for ( ; it.current(); ++it )
452 {
453 if ( protect != it.current()->isProtect() )
454 {
455 generalValue.m_protect = STATE_UNDEF;
456 if ( generalValue.m_keepRatio == STATE_UNDEF )
457 {
458 break;
459 }
460 }
461
462 if ( keepRatio != it.current()->isKeepRatio() )
463 {
464 generalValue.m_keepRatio = STATE_UNDEF;
465 if ( generalValue.m_protect == STATE_UNDEF )
466 {
467 break;
468 }
469 }
470 }
471
472 return generalValue;
473}
474
475
476void KPrPropertyEditor::slotDone()
477{
478 emit propertiesOk();
479
480 if ( m_penProperty )
481 m_penProperty->apply();
482 if ( m_brushProperty )
483 m_brushProperty->apply();
484 if ( m_rectProperty )
485 m_rectProperty->apply();
486 if ( m_polygonProperty )
487 m_polygonProperty->apply();
488 if ( m_pieProperty )
489 m_pieProperty->apply();
490 if ( m_pictureProperty )
491 m_pictureProperty->apply();
492 if ( m_textProperty )
493 m_textProperty->apply();
494 if ( m_generalProperty )
495 m_generalProperty->apply();
496}
497
498#include "KPrPropertyEditor.moc"