kspread

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