kspread

kspread_propertyEditor.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 #include "kspread_propertyEditor.h"
00021 
00022 #include "kspread_object.h"
00023 #include "kspread_sheet.h"
00024 #include "kspread_doc.h"
00025 // #include "KPrUtils.h"
00026 #include "commands.h"
00027 // #include "KPrPenStyleWidget.h"
00028 // #include "KPrBrushProperty.h"
00029 // #include "KPrRectProperty.h"
00030 // #include "KPrPolygonProperty.h"
00031 // #include "KPrPieProperty.h"
00032 // #include "KPrPictureProperty.h"
00033 // #include "KPrTextProperty.h"
00034 // #include "KPrObjectProperties.h"
00035 
00036 #include <klocale.h>
00037 #include <kstdguiitem.h>
00038 
00039 using namespace KSpread;
00040 
00041 PropertyEditor::PropertyEditor( QWidget *parent, const char *name, Sheet *page, Doc *doc )
00042     : QTabDialog( parent, name, true )
00043     , m_page( page )
00044     , m_doc( doc )
00045     , m_objects( page->getSelectedObjects() )
00046 //     , m_penProperty( 0 )
00047 //     , m_brushProperty( 0 )
00048 //     , m_rectProperty( 0 )
00049 //     , m_polygonProperty( 0 )
00050 //     , m_pieProperty( 0 )
00051 //     , m_pictureProperty( 0 )
00052 //     , m_textProperty( 0 )
00053      , m_generalProperty( 0 )
00054 //     , m_objectProperties( 0 )
00055 {
00056     setCancelButton( KStdGuiItem::cancel().text() );
00057     setOkButton( KStdGuiItem::ok().text() );
00058     setApplyButton( KStdGuiItem::apply().text() );
00059 
00060     connect( this, SIGNAL( applyButtonPressed() ), this, SLOT( slotDone() ) );
00061 
00062     //m_objectProperties = new KPrObjectProperties( m_objects );
00063 
00064     setupTabs();
00065 }
00066 
00067 
00068 PropertyEditor::~PropertyEditor()
00069 {
00070     //delete m_objectProperties;
00071 }
00072 
00073 
00074 KCommand * PropertyEditor::getCommand()
00075 {
00076     KMacroCommand *macro = 0;
00077 
00078 //     if ( m_penProperty )
00079 //     {
00080 //         int change = m_penProperty->getPenConfigChange();
00081 //         if ( change )
00082 //         {
00083 //             KoPenCmd::Pen pen( m_penProperty->getPen() );
00084 // 
00085 //             KoPenCmd *cmd = new KoPenCmd( i18n( "Apply Styles" ), m_objects, pen, m_doc, m_page, change );
00086 // 
00087 //             if ( !macro )
00088 //             {
00089 //                 macro = new KMacroCommand( i18n( "Apply Properties" ) );
00090 //             }
00091 // 
00092 //             macro->addCommand( cmd );
00093 //         }
00094 //     }
00095 // 
00096 //     if ( m_brushProperty )
00097 //     {
00098 //         int change = m_brushProperty->getBrushPropertyChange();
00099 //         if ( change )
00100 //         {
00101 //             KPrBrushCmd::Brush brush( m_brushProperty->getBrush() );
00102 // 
00103 //             KPrBrushCmd *cmd = new KPrBrushCmd( i18n( "Apply Styles" ), m_objects, brush, m_doc, m_page, change );
00104 // 
00105 //             if ( !macro )
00106 //             {
00107 //                 macro = new KMacroCommand( i18n( "Apply Properties" ) );
00108 //             }
00109 // 
00110 //             macro->addCommand( cmd );
00111 //         }
00112 //     }
00113 // 
00114 //     if ( m_rectProperty )
00115 //     {
00116 //         int change = m_rectProperty->getRectPropertyChange();
00117 // 
00118 //         if ( change )
00119 //         {
00120 //             KPrRectValueCmd::RectValues rectValue( m_rectProperty->getRectValues() );
00121 // 
00122 //             KPrRectValueCmd *cmd = new KPrRectValueCmd( i18n( "Apply Styles" ), m_objects, rectValue, m_doc, m_page, change );
00123 // 
00124 //             if ( !macro )
00125 //             {
00126 //                 macro = new KMacroCommand( i18n( "Apply Properties" ) );
00127 //             }
00128 // 
00129 //             macro->addCommand( cmd );
00130 //         }
00131 //     }
00132 // 
00133 //     if ( m_polygonProperty )
00134 //     {
00135 //         int change = m_polygonProperty->getPolygonPropertyChange();
00136 // 
00137 //         if ( change )
00138 //         {
00139 //             KPrPolygonSettingCmd::PolygonSettings polygonSettings( m_polygonProperty->getPolygonSettings() );
00140 // 
00141 //             KPrPolygonSettingCmd *cmd = new KPrPolygonSettingCmd( i18n("Apply Styles"), polygonSettings,
00142 //                                                             m_objects, m_doc, m_page, change );
00143 // 
00144 //             if ( !macro )
00145 //             {
00146 //                 macro = new KMacroCommand( i18n( "Apply Properties" ) );
00147 //             }
00148 // 
00149 //             macro->addCommand( cmd );
00150 //         }
00151 //     }
00152 // 
00153 //     if ( m_pieProperty )
00154 //     {
00155 //         int change = m_pieProperty->getPiePropertyChange();
00156 // 
00157 //         if ( change )
00158 //         {
00159 //             KPrPieValueCmd *cmd = new KPrPieValueCmd( i18n("Apply Styles"), m_pieProperty->getPieValues(),
00160 //                                                 m_objects, m_doc, m_page, change );
00161 //             if ( !macro )
00162 //             {
00163 //                 macro = new KMacroCommand( i18n( "Apply Properties" ) );
00164 //             }
00165 // 
00166 //             macro->addCommand( cmd );
00167 //         }
00168 //     }
00169 // 
00170 //     if ( m_pictureProperty )
00171 //     {
00172 //         int change = m_pictureProperty->getPicturePropertyChange();
00173 // 
00174 //         if ( change )
00175 //         {
00176 //             KPrPictureSettingCmd *cmd = new KPrPictureSettingCmd( i18n("Apply Styles"), m_pictureProperty->getPictureSettings(),
00177 //                                                             m_objects, m_doc, m_page, change );
00178 //             if ( !macro )
00179 //             {
00180 //                 macro = new KMacroCommand( i18n( "Apply Properties" ) );
00181 //             }
00182 // 
00183 //             macro->addCommand( cmd );
00184 //         }
00185 //     }
00186 // 
00187 //     if ( m_textProperty )
00188 //     {
00189 //         int change = m_textProperty->getTextPropertyChange();
00190 // 
00191 //         if ( change )
00192 //         {
00193 //             if ( change & KPrTextProperty::ProtectContent )
00194 //             {
00195 //                 KPrProtectContentCommand * cmd = new KPrProtectContentCommand( i18n( "Apply Styles" ), m_objects,
00196 //                                                                                m_textProperty->getProtectContent(),
00197 //                                                                                m_doc );
00198 //                 if ( !macro )
00199 //                 {
00200 //                     macro = new KMacroCommand( i18n( "Apply Properties" ) );
00201 //                 }
00202 // 
00203 //                 macro->addCommand( cmd );
00204 //             }
00205 // 
00206 //             if ( change & KPrTextProperty::Margins )
00207 //             {
00208 //                 KPrChangeMarginCommand *cmd = new KPrChangeMarginCommand( i18n( "Apply Styles" ), m_objects,
00209 //                                                                           m_textProperty->getMarginsStruct(),
00210 //                                                                           m_doc, m_page );
00211 // 
00212 //                 if ( !macro )
00213 //                 {
00214 //                     macro = new KMacroCommand( i18n( "Apply Properties" ) );
00215 //                 }
00216 // 
00217 //                 macro->addCommand( cmd );
00218 //             }
00219 //         }
00220 //     }
00221 
00222     if ( m_generalProperty )
00223     {
00224         int change = m_generalProperty->getGeneralPropertyChange();
00225 
00226         if ( change )
00227         {
00228             GeneralProperty::GeneralValue generalValue( m_generalProperty->getGeneralValue() );
00229 
00230             if ( change & GeneralProperty::Name )
00231             {
00232                 KCommand *cmd = new RenameNameObjectCommand( i18n( "Name Object" ), generalValue.m_name,
00233                                                           m_objects.at( 0 ), m_doc );
00234 
00235                 if ( !macro )
00236                 {
00237                     macro = new KMacroCommand( i18n( "Apply Properties" ) );
00238                 }
00239 
00240                 macro->addCommand( cmd );
00241             }
00242 
00243             if ( change & GeneralProperty::Protect )
00244             {
00245                 KCommand *cmd= new GeometryPropertiesCommand( i18n( "Protect Object" ), m_objects,
00246                                                                  generalValue.m_protect == STATE_ON,
00247                                                                  GeometryPropertiesCommand::ProtectSize,m_doc );
00248 
00249                 if ( !macro )
00250                 {
00251                     macro = new KMacroCommand( i18n( "Apply Properties" ) );
00252                 }
00253 
00254                 macro->addCommand( cmd );
00255             }
00256 
00257             if ( change & GeneralProperty::KeepRatio )
00258             {
00259                 KCommand *cmd= new GeometryPropertiesCommand( i18n( "Keep Ratio" ), m_objects,
00260                                                                  generalValue.m_keepRatio == STATE_ON,
00261                                                                  GeometryPropertiesCommand::KeepRatio,m_doc );
00262                 if ( !macro )
00263                 {
00264                     macro = new KMacroCommand( i18n( "Apply Properties" ) );
00265                 }
00266 
00267                 macro->addCommand( cmd );
00268             }
00269 
00270             if ( change & GeneralProperty::Left
00271                  || change & GeneralProperty::Top
00272                  || change & GeneralProperty::Width
00273                  || change & GeneralProperty::Height )
00274             {
00275                 if ( !macro )
00276                 {
00277                     macro = new KMacroCommand( i18n( "Apply Properties" ) );
00278                 }
00279 
00280                 QPtrListIterator<EmbeddedObject> it( m_objects );
00281                 for ( ; it.current(); ++it )
00282                 {
00283                     KoRect oldRect = it.current()->geometry()/*getRect()*/;
00284                     KoRect newRect = oldRect;
00285 
00286                     if ( change & GeneralProperty::Left )
00287                         newRect.moveTopLeft( KoPoint( generalValue.m_rect.left(), newRect.top() ) );
00288 
00289                     if ( change & GeneralProperty::Top )
00290                         newRect.moveTopLeft( KoPoint( newRect.left(), generalValue.m_rect.top() ) );
00291 
00292                     if ( change & GeneralProperty::Width )
00293                         newRect.setWidth( generalValue.m_rect.width() );
00294 
00295                     if ( change & GeneralProperty::Height )
00296                         newRect.setHeight( generalValue.m_rect.height() );
00297 
00298                     KCommand *cmd = new ChangeObjectGeometryCommand(   it.current(),  newRect.topLeft() - oldRect.topLeft(),
00299                                                     newRect.size() - oldRect.size() );
00300 
00301                     macro->addCommand( cmd );
00302                 }
00303             }
00304         }
00305     }
00306 
00307     return macro;
00308 }
00309 
00310 
00311 void PropertyEditor::setupTabs()
00312 {
00313     setupTabGeneral();
00314 
00315 //     int flags = m_objectProperties->getPropertyFlags();
00316 // 
00317 //     if ( flags & KPrObjectProperties::PtPen )
00318 //         setupTabPen( flags & KPrObjectProperties::PtLineEnds );
00319 // 
00320 //     if ( flags & KPrObjectProperties::PtBrush )
00321 //         setupTabBrush();
00322 // 
00323 //     if ( flags & KPrObjectProperties::PtRectangle )
00324 //         setupTabRect();
00325 // 
00326 //     if ( flags & KPrObjectProperties::PtPolygon )
00327 //         setupTabPolygon();
00328 // 
00329 //     if ( flags & KPrObjectProperties::PtPie )
00330 //         setupTabPie();
00331 // 
00332 //     if ( flags & KPrObjectProperties::PtPicture )
00333 //         setupTabPicture();
00334 // 
00335 //     if ( flags & KPrObjectProperties::PtText )
00336 //         setupTabText();
00337 }
00338 
00339 /*
00340 void PropertyEditor::setupTabPen( bool configureLineEnds )
00341 {
00342     if ( m_penProperty == 0 )
00343     {
00344         KoPenCmd::Pen pen( m_objectProperties->getPen() );
00345 
00346         m_penProperty = new KPrPenStyleWidget( this, 0, pen, configureLineEnds );
00347         addTab( m_penProperty, i18n( "Outl&ine" ) );
00348     }
00349 }
00350 
00351 
00352 void PropertyEditor::setupTabBrush()
00353 {
00354     if ( m_brushProperty == 0 )
00355     {
00356         KPrBrushCmd::Brush brush( m_objectProperties->getBrush() );
00357 
00358         m_brushProperty = new KPrBrushProperty( this, 0, brush );
00359         addTab( m_brushProperty, i18n( "&Fill" ) );
00360     }
00361 }
00362 
00363 
00364 void PropertyEditor::setupTabRect()
00365 {
00366     if ( m_rectProperty == 0 )
00367     {
00368         KPrRectValueCmd::RectValues rectValues = m_objectProperties->getRectValues();
00369         m_rectProperty = new KPrRectProperty( this, 0, rectValues );
00370         addTab( m_rectProperty, i18n( "&Rectangle" ) );
00371     }
00372 }
00373 
00374 
00375 void PropertyEditor::setupTabPolygon()
00376 {
00377     if ( m_polygonProperty == 0 )
00378     {
00379         KPrPolygonSettingCmd::PolygonSettings polygonSettings = m_objectProperties->getPolygonSettings();
00380         m_polygonProperty = new KPrPolygonProperty( this, 0, polygonSettings );
00381         addTab( m_polygonProperty, i18n("Polygo&n" ) );
00382     }
00383 }
00384 
00385 
00386 void PropertyEditor::setupTabPie()
00387 {
00388     if ( m_pieProperty == 0 )
00389     {
00390         m_pieProperty = new KPrPieProperty( this, 0, m_objectProperties->getPieValues() );
00391         addTab( m_pieProperty, i18n("&Pie" ) );
00392     }
00393 }
00394 
00395 
00396 void PropertyEditor::setupTabPicture()
00397 {
00398     if ( m_pictureProperty == 0 )
00399     {
00400         m_pictureProperty = new KPrPictureProperty( this, 0, m_objectProperties->getPixmap(), m_objectProperties->getPictureSettings() );
00401         addTab( m_pictureProperty, i18n("Pict&ure" ) );
00402     }
00403 }
00404 
00405 
00406 void PropertyEditor::setupTabText()
00407 {
00408     if ( m_textProperty == 0 )
00409     {
00410         m_textProperty = new KPrTextProperty( this, 0, m_objectProperties->getMarginsStruct(),
00411                                            m_doc->unit(), m_objectProperties->getProtectContent() );
00412         addTab( m_textProperty, i18n("Te&xt" ) );
00413     }
00414 }*/
00415 
00416 
00417 void PropertyEditor::setupTabGeneral()
00418 {
00419     if ( m_generalProperty == 0 )
00420     {
00421         GeneralProperty::GeneralValue generalValue = getGeneralValue();
00422         m_generalProperty = new GeneralProperty( this, 0, generalValue, m_doc->unit() );
00423         addTab( m_generalProperty, i18n( "&General" ) );
00424     }
00425 }
00426 
00427 
00428 GeneralProperty::GeneralValue PropertyEditor::getGeneralValue()
00429 {
00430     GeneralProperty::GeneralValue generalValue;
00431 
00432     if ( m_objects.count() == 1 )
00433     {
00434         generalValue.m_name = m_objects.at( 0 )->getObjectName();
00435     }
00436 
00437     bool protect = false;
00438     generalValue.m_protect = STATE_OFF;
00439     bool keepRatio = false;
00440     generalValue.m_keepRatio = STATE_OFF;
00441 
00442     QPtrListIterator<EmbeddedObject> it( m_objects );
00443     if ( it.current() )
00444     {
00445         protect = it.current()->isProtect();
00446         generalValue.m_protect = protect ? STATE_ON : STATE_OFF;
00447         keepRatio = it.current()->isKeepRatio();
00448         generalValue.m_keepRatio = keepRatio ? STATE_ON : STATE_OFF;
00449         generalValue.m_rect = it.current()->geometry()/*getRect()*/;
00450         ++it;
00451     }
00452 
00453     for ( ; it.current(); ++it )
00454     {
00455         if ( protect != it.current()->isProtect() )
00456         {
00457             generalValue.m_protect = STATE_UNDEF;
00458             if ( generalValue.m_keepRatio == STATE_UNDEF )
00459             {
00460                 break;
00461             }
00462         }
00463 
00464         if ( keepRatio != it.current()->isKeepRatio() )
00465         {
00466             generalValue.m_keepRatio = STATE_UNDEF;
00467             if ( generalValue.m_protect == STATE_UNDEF )
00468             {
00469                 break;
00470             }
00471         }
00472     }
00473 
00474     return generalValue;
00475 }
00476 
00477 
00478 void PropertyEditor::slotDone()
00479 {
00480     emit propertiesOk();
00481 
00482 //     if ( m_penProperty )
00483 //         m_penProperty->apply();
00484 //     if ( m_brushProperty )
00485 //         m_brushProperty->apply();
00486 //     if ( m_rectProperty )
00487 //         m_rectProperty->apply();
00488 //     if ( m_polygonProperty )
00489 //         m_polygonProperty->apply();
00490 //     if ( m_pieProperty )
00491 //         m_pieProperty->apply();
00492 //     if ( m_pictureProperty )
00493 //         m_pictureProperty->apply();
00494 //     if ( m_textProperty )
00495 //         m_textProperty->apply();
00496     if ( m_generalProperty )
00497         m_generalProperty->apply();
00498 }
00499 
00500 #include "kspread_propertyEditor.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys