19#include "KPrPropertyEditor.h"
23#include "KPrDocument.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"
36#include <kstdguiitem.h>
38KPrPropertyEditor::KPrPropertyEditor( TQWidget *parent,
const char *name, KPrPage *page, KPrDocument *doc )
39 : TQTabDialog( parent, name, true )
42 , m_objects( page->getSelectedObjects() )
44 , m_brushProperty( 0 )
46 , m_polygonProperty( 0 )
48 , m_pictureProperty( 0 )
50 , m_generalProperty( 0 )
51 , m_objectProperties( 0 )
53 setCancelButton( KStdGuiItem::cancel().text() );
54 setOkButton( KStdGuiItem::ok().text() );
55 setApplyButton( KStdGuiItem::apply().text() );
57 connect(
this, TQ_SIGNAL( applyButtonPressed() ),
this, TQ_SLOT( slotDone() ) );
59 m_objectProperties =
new KPrObjectProperties( m_objects );
65KPrPropertyEditor::~KPrPropertyEditor()
67 delete m_objectProperties;
71KCommand * KPrPropertyEditor::getCommand()
73 KMacroCommand *macro = 0;
77 int change = m_penProperty->getPenConfigChange();
80 KoPenCmd::Pen pen( m_penProperty->getPen() );
82 KoPenCmd *cmd =
new KoPenCmd( i18n(
"Apply Styles" ), m_objects, pen, m_doc, m_page, change );
86 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
89 macro->addCommand( cmd );
93 if ( m_brushProperty )
95 int change = m_brushProperty->getBrushPropertyChange();
98 KPrBrushCmd::Brush brush( m_brushProperty->getBrush() );
100 KPrBrushCmd *cmd =
new KPrBrushCmd( i18n(
"Apply Styles" ), m_objects, brush, m_doc, m_page, change );
104 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
107 macro->addCommand( cmd );
111 if ( m_rectProperty )
113 int change = m_rectProperty->getRectPropertyChange();
117 KPrRectValueCmd::RectValues rectValue( m_rectProperty->getRectValues() );
119 KPrRectValueCmd *cmd =
new KPrRectValueCmd( i18n(
"Apply Styles" ), m_objects, rectValue, m_doc, m_page, change );
123 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
126 macro->addCommand( cmd );
130 if ( m_polygonProperty )
132 int change = m_polygonProperty->getPolygonPropertyChange();
136 KPrPolygonSettingCmd::PolygonSettings polygonSettings( m_polygonProperty->getPolygonSettings() );
138 KPrPolygonSettingCmd *cmd =
new KPrPolygonSettingCmd( i18n(
"Apply Styles"), polygonSettings,
139 m_objects, m_doc, m_page, change );
143 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
146 macro->addCommand( cmd );
152 int change = m_pieProperty->getPiePropertyChange();
156 KPrPieValueCmd *cmd =
new KPrPieValueCmd( i18n(
"Apply Styles"), m_pieProperty->getPieValues(),
157 m_objects, m_doc, m_page, change );
160 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
163 macro->addCommand( cmd );
167 if ( m_pictureProperty )
169 int change = m_pictureProperty->getPicturePropertyChange();
173 KPrPictureSettingCmd *cmd =
new KPrPictureSettingCmd( i18n(
"Apply Styles"), m_pictureProperty->getPictureSettings(),
174 m_objects, m_doc, m_page, change );
177 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
180 macro->addCommand( cmd );
184 if ( m_textProperty )
186 int change = m_textProperty->getTextPropertyChange();
190 if ( change & KPrTextProperty::ProtectContent )
192 KPrProtectContentCommand * cmd =
new KPrProtectContentCommand( i18n(
"Apply Styles" ), m_objects,
193 m_textProperty->getProtectContent(),
197 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
200 macro->addCommand( cmd );
203 if ( change & KPrTextProperty::Margins )
205 KPrChangeMarginCommand *cmd =
new KPrChangeMarginCommand( i18n(
"Apply Styles" ), m_objects,
206 m_textProperty->getMarginsStruct(),
211 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
214 macro->addCommand( cmd );
219 if ( m_generalProperty )
221 int change = m_generalProperty->getGeneralPropertyChange();
225 KPrGeneralProperty::GeneralValue generalValue( m_generalProperty->getGeneralValue() );
227 if ( change & KPrGeneralProperty::Name )
229 KCommand *cmd =
new KPrNameObjectCommand( i18n(
"Name Object" ), generalValue.m_name,
230 m_objects.at( 0 ), m_doc );
234 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
237 macro->addCommand( cmd );
240 if ( change & KPrGeneralProperty::Protect )
242 KCommand *cmd=
new KPrGeometryPropertiesCommand( i18n(
"Protect Object" ), m_objects,
243 generalValue.m_protect == STATE_ON,
244 KPrGeometryPropertiesCommand::ProtectSize,m_doc );
248 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
251 macro->addCommand( cmd );
254 if ( change & KPrGeneralProperty::KeepRatio )
256 KCommand *cmd=
new KPrGeometryPropertiesCommand( i18n(
"Keep Ratio" ), m_objects,
257 generalValue.m_keepRatio == STATE_ON,
258 KPrGeometryPropertiesCommand::KeepRatio,m_doc );
261 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
264 macro->addCommand( cmd );
267 if ( change & KPrGeneralProperty::Left
268 || change & KPrGeneralProperty::Top
269 || change & KPrGeneralProperty::Width
270 || change & KPrGeneralProperty::Height )
274 macro =
new KMacroCommand( i18n(
"Apply Properties" ) );
277 TQPtrListIterator<KPrObject> it( m_objects );
278 for ( ; it.current(); ++it )
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() ) );
285 if ( change & KPrGeneralProperty::Top )
286 newRect.moveTopLeft( KoPoint( newRect.left(), generalValue.m_rect.top() ) );
288 if ( change & KPrGeneralProperty::Width )
289 newRect.setWidth( generalValue.m_rect.width() );
291 if ( change & KPrGeneralProperty::Height )
292 newRect.setHeight( generalValue.m_rect.height() );
294 KCommand *cmd =
new KPrResizeCmd( i18n(
"Change Size" ),
295 newRect.topLeft() - oldRect.topLeft(),
296 newRect.size() - oldRect.size(),
297 it.current(), m_doc );
299 macro->addCommand( cmd );
309void KPrPropertyEditor::setupTabs()
313 int flags = m_objectProperties->getPropertyFlags();
315 if ( flags & KPrObjectProperties::PtPen )
316 setupTabPen( flags & KPrObjectProperties::PtLineEnds );
318 if ( flags & KPrObjectProperties::PtBrush )
321 if ( flags & KPrObjectProperties::PtRectangle )
324 if ( flags & KPrObjectProperties::PtPolygon )
327 if ( flags & KPrObjectProperties::PtPie )
330 if ( flags & KPrObjectProperties::PtPicture )
333 if ( flags & KPrObjectProperties::PtText )
338void KPrPropertyEditor::setupTabPen(
bool configureLineEnds )
340 if ( m_penProperty == 0 )
342 KoPenCmd::Pen pen( m_objectProperties->getPen() );
344 m_penProperty =
new KPrPenStyleWidget(
this, 0, pen, configureLineEnds );
345 addTab( m_penProperty, i18n(
"Outl&ine" ) );
350void KPrPropertyEditor::setupTabBrush()
352 if ( m_brushProperty == 0 )
354 KPrBrushCmd::Brush brush( m_objectProperties->getBrush() );
356 m_brushProperty =
new KPrBrushProperty(
this, 0, brush );
357 addTab( m_brushProperty, i18n(
"&Fill" ) );
362void KPrPropertyEditor::setupTabRect()
364 if ( m_rectProperty == 0 )
366 KPrRectValueCmd::RectValues rectValues = m_objectProperties->getRectValues();
367 m_rectProperty =
new KPrRectProperty(
this, 0, rectValues );
368 addTab( m_rectProperty, i18n(
"&Rectangle" ) );
373void KPrPropertyEditor::setupTabPolygon()
375 if ( m_polygonProperty == 0 )
377 KPrPolygonSettingCmd::PolygonSettings polygonSettings = m_objectProperties->getPolygonSettings();
378 m_polygonProperty =
new KPrPolygonProperty(
this, 0, polygonSettings );
379 addTab( m_polygonProperty, i18n(
"Polygo&n" ) );
384void KPrPropertyEditor::setupTabPie()
386 if ( m_pieProperty == 0 )
388 m_pieProperty =
new KPrPieProperty(
this, 0, m_objectProperties->getPieValues() );
389 addTab( m_pieProperty, i18n(
"&Pie" ) );
394void KPrPropertyEditor::setupTabPicture()
396 if ( m_pictureProperty == 0 )
398 m_pictureProperty =
new KPrPictureProperty(
this, 0, m_objectProperties->getPixmap(), m_objectProperties->getPictureSettings() );
399 addTab( m_pictureProperty, i18n(
"Pict&ure" ) );
404void KPrPropertyEditor::setupTabText()
406 if ( m_textProperty == 0 )
408 m_textProperty =
new KPrTextProperty(
this, 0, m_objectProperties->getMarginsStruct(),
409 m_doc->unit(), m_objectProperties->getProtectContent() );
410 addTab( m_textProperty, i18n(
"Te&xt" ) );
415void KPrPropertyEditor::setupTabGeneral()
417 if ( m_generalProperty == 0 )
419 KPrGeneralProperty::GeneralValue generalValue = getGeneralValue();
420 m_generalProperty =
new KPrGeneralProperty(
this, 0, generalValue, m_doc->unit() );
421 addTab( m_generalProperty, i18n(
"&General" ) );
426KPrGeneralProperty::GeneralValue KPrPropertyEditor::getGeneralValue()
428 KPrGeneralProperty::GeneralValue generalValue;
430 if ( m_objects.count() == 1 )
432 generalValue.m_name = m_objects.at( 0 )->getObjectName();
435 bool protect =
false;
436 generalValue.m_protect = STATE_OFF;
437 bool keepRatio =
false;
438 generalValue.m_keepRatio = STATE_OFF;
440 TQPtrListIterator<KPrObject> it( m_objects );
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();
451 for ( ; it.current(); ++it )
453 if ( protect != it.current()->isProtect() )
455 generalValue.m_protect = STATE_UNDEF;
456 if ( generalValue.m_keepRatio == STATE_UNDEF )
462 if ( keepRatio != it.current()->isKeepRatio() )
464 generalValue.m_keepRatio = STATE_UNDEF;
465 if ( generalValue.m_protect == STATE_UNDEF )
476void KPrPropertyEditor::slotDone()
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();
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();
498#include "KPrPropertyEditor.moc"