KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

499 lines
15 KiB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. * Boston, MA 02110-1301, USA.
  15. */
  16. #include "kspread_propertyEditor.h"
  17. #include "kspread_object.h"
  18. #include "kspread_sheet.h"
  19. #include "kspread_doc.h"
  20. // #include "KPrUtils.h"
  21. #include "commands.h"
  22. // #include "KPrPenStyleWidget.h"
  23. // #include "KPrBrushProperty.h"
  24. // #include "KPrRectProperty.h"
  25. // #include "KPrPolygonProperty.h"
  26. // #include "KPrPieProperty.h"
  27. // #include "KPrPictureProperty.h"
  28. // #include "KPrTextProperty.h"
  29. // #include "KPrObjectProperties.h"
  30. #include <tdelocale.h>
  31. #include <kstdguiitem.h>
  32. using namespace KSpread;
  33. PropertyEditor::PropertyEditor( TQWidget *parent, const char *name, Sheet *page, Doc *doc )
  34. : TQTabDialog( parent, name, true )
  35. , m_page( page )
  36. , m_doc( doc )
  37. , m_objects( page->getSelectedObjects() )
  38. // , m_penProperty( 0 )
  39. // , m_brushProperty( 0 )
  40. // , m_rectProperty( 0 )
  41. // , m_polygonProperty( 0 )
  42. // , m_pieProperty( 0 )
  43. // , m_pictureProperty( 0 )
  44. // , m_textProperty( 0 )
  45. , m_generalProperty( 0 )
  46. // , m_objectProperties( 0 )
  47. {
  48. setCancelButton( KStdGuiItem::cancel().text() );
  49. setOkButton( KStdGuiItem::ok().text() );
  50. setApplyButton( KStdGuiItem::apply().text() );
  51. connect( this, TQT_SIGNAL( applyButtonPressed() ), this, TQT_SLOT( slotDone() ) );
  52. //m_objectProperties = new KPrObjectProperties( m_objects );
  53. setupTabs();
  54. }
  55. PropertyEditor::~PropertyEditor()
  56. {
  57. //delete m_objectProperties;
  58. }
  59. KCommand * PropertyEditor::getCommand()
  60. {
  61. KMacroCommand *macro = 0;
  62. // if ( m_penProperty )
  63. // {
  64. // int change = m_penProperty->getPenConfigChange();
  65. // if ( change )
  66. // {
  67. // KoPenCmd::Pen pen( m_penProperty->getPen() );
  68. //
  69. // KoPenCmd *cmd = new KoPenCmd( i18n( "Apply Styles" ), m_objects, pen, m_doc, m_page, change );
  70. //
  71. // if ( !macro )
  72. // {
  73. // macro = new KMacroCommand( i18n( "Apply Properties" ) );
  74. // }
  75. //
  76. // macro->addCommand( cmd );
  77. // }
  78. // }
  79. //
  80. // if ( m_brushProperty )
  81. // {
  82. // int change = m_brushProperty->getBrushPropertyChange();
  83. // if ( change )
  84. // {
  85. // KPrBrushCmd::Brush brush( m_brushProperty->getBrush() );
  86. //
  87. // KPrBrushCmd *cmd = new KPrBrushCmd( i18n( "Apply Styles" ), m_objects, brush, m_doc, m_page, change );
  88. //
  89. // if ( !macro )
  90. // {
  91. // macro = new KMacroCommand( i18n( "Apply Properties" ) );
  92. // }
  93. //
  94. // macro->addCommand( cmd );
  95. // }
  96. // }
  97. //
  98. // if ( m_rectProperty )
  99. // {
  100. // int change = m_rectProperty->getRectPropertyChange();
  101. //
  102. // if ( change )
  103. // {
  104. // KPrRectValueCmd::RectValues rectValue( m_rectProperty->getRectValues() );
  105. //
  106. // KPrRectValueCmd *cmd = new KPrRectValueCmd( i18n( "Apply Styles" ), m_objects, rectValue, m_doc, m_page, change );
  107. //
  108. // if ( !macro )
  109. // {
  110. // macro = new KMacroCommand( i18n( "Apply Properties" ) );
  111. // }
  112. //
  113. // macro->addCommand( cmd );
  114. // }
  115. // }
  116. //
  117. // if ( m_polygonProperty )
  118. // {
  119. // int change = m_polygonProperty->getPolygonPropertyChange();
  120. //
  121. // if ( change )
  122. // {
  123. // KPrPolygonSettingCmd::PolygonSettings polygonSettings( m_polygonProperty->getPolygonSettings() );
  124. //
  125. // KPrPolygonSettingCmd *cmd = new KPrPolygonSettingCmd( i18n("Apply Styles"), polygonSettings,
  126. // m_objects, m_doc, m_page, change );
  127. //
  128. // if ( !macro )
  129. // {
  130. // macro = new KMacroCommand( i18n( "Apply Properties" ) );
  131. // }
  132. //
  133. // macro->addCommand( cmd );
  134. // }
  135. // }
  136. //
  137. // if ( m_pieProperty )
  138. // {
  139. // int change = m_pieProperty->getPiePropertyChange();
  140. //
  141. // if ( change )
  142. // {
  143. // KPrPieValueCmd *cmd = new KPrPieValueCmd( i18n("Apply Styles"), m_pieProperty->getPieValues(),
  144. // m_objects, m_doc, m_page, change );
  145. // if ( !macro )
  146. // {
  147. // macro = new KMacroCommand( i18n( "Apply Properties" ) );
  148. // }
  149. //
  150. // macro->addCommand( cmd );
  151. // }
  152. // }
  153. //
  154. // if ( m_pictureProperty )
  155. // {
  156. // int change = m_pictureProperty->getPicturePropertyChange();
  157. //
  158. // if ( change )
  159. // {
  160. // KPrPictureSettingCmd *cmd = new KPrPictureSettingCmd( i18n("Apply Styles"), m_pictureProperty->getPictureSettings(),
  161. // m_objects, m_doc, m_page, change );
  162. // if ( !macro )
  163. // {
  164. // macro = new KMacroCommand( i18n( "Apply Properties" ) );
  165. // }
  166. //
  167. // macro->addCommand( cmd );
  168. // }
  169. // }
  170. //
  171. // if ( m_textProperty )
  172. // {
  173. // int change = m_textProperty->getTextPropertyChange();
  174. //
  175. // if ( change )
  176. // {
  177. // if ( change & KPrTextProperty::ProtectContent )
  178. // {
  179. // KPrProtectContentCommand * cmd = new KPrProtectContentCommand( i18n( "Apply Styles" ), m_objects,
  180. // m_textProperty->getProtectContent(),
  181. // m_doc );
  182. // if ( !macro )
  183. // {
  184. // macro = new KMacroCommand( i18n( "Apply Properties" ) );
  185. // }
  186. //
  187. // macro->addCommand( cmd );
  188. // }
  189. //
  190. // if ( change & KPrTextProperty::Margins )
  191. // {
  192. // KPrChangeMarginCommand *cmd = new KPrChangeMarginCommand( i18n( "Apply Styles" ), m_objects,
  193. // m_textProperty->getMarginsStruct(),
  194. // m_doc, m_page );
  195. //
  196. // if ( !macro )
  197. // {
  198. // macro = new KMacroCommand( i18n( "Apply Properties" ) );
  199. // }
  200. //
  201. // macro->addCommand( cmd );
  202. // }
  203. // }
  204. // }
  205. if ( m_generalProperty )
  206. {
  207. int change = m_generalProperty->getGeneralPropertyChange();
  208. if ( change )
  209. {
  210. GeneralProperty::GeneralValue generalValue( m_generalProperty->getGeneralValue() );
  211. if ( change & GeneralProperty::Name )
  212. {
  213. KCommand *cmd = new RenameNameObjectCommand( i18n( "Name Object" ), generalValue.m_name,
  214. m_objects.at( 0 ), m_doc );
  215. if ( !macro )
  216. {
  217. macro = new KMacroCommand( i18n( "Apply Properties" ) );
  218. }
  219. macro->addCommand( cmd );
  220. }
  221. if ( change & GeneralProperty::Protect )
  222. {
  223. KCommand *cmd= new GeometryPropertiesCommand( i18n( "Protect Object" ), m_objects,
  224. generalValue.m_protect == STATE_ON,
  225. GeometryPropertiesCommand::ProtectSize,m_doc );
  226. if ( !macro )
  227. {
  228. macro = new KMacroCommand( i18n( "Apply Properties" ) );
  229. }
  230. macro->addCommand( cmd );
  231. }
  232. if ( change & GeneralProperty::KeepRatio )
  233. {
  234. KCommand *cmd= new GeometryPropertiesCommand( i18n( "Keep Ratio" ), m_objects,
  235. generalValue.m_keepRatio == STATE_ON,
  236. GeometryPropertiesCommand::KeepRatio,m_doc );
  237. if ( !macro )
  238. {
  239. macro = new KMacroCommand( i18n( "Apply Properties" ) );
  240. }
  241. macro->addCommand( cmd );
  242. }
  243. if ( change & GeneralProperty::Left
  244. || change & GeneralProperty::Top
  245. || change & GeneralProperty::Width
  246. || change & GeneralProperty::Height )
  247. {
  248. if ( !macro )
  249. {
  250. macro = new KMacroCommand( i18n( "Apply Properties" ) );
  251. }
  252. TQPtrListIterator<EmbeddedObject> it( m_objects );
  253. for ( ; it.current(); ++it )
  254. {
  255. KoRect oldRect = it.current()->geometry()/*getRect()*/;
  256. KoRect newRect = oldRect;
  257. if ( change & GeneralProperty::Left )
  258. newRect.moveTopLeft( KoPoint( generalValue.m_rect.left(), newRect.top() ) );
  259. if ( change & GeneralProperty::Top )
  260. newRect.moveTopLeft( KoPoint( newRect.left(), generalValue.m_rect.top() ) );
  261. if ( change & GeneralProperty::Width )
  262. newRect.setWidth( generalValue.m_rect.width() );
  263. if ( change & GeneralProperty::Height )
  264. newRect.setHeight( generalValue.m_rect.height() );
  265. KCommand *cmd = new ChangeObjectGeometryCommand( it.current(), newRect.topLeft() - oldRect.topLeft(),
  266. newRect.size() - oldRect.size() );
  267. macro->addCommand( cmd );
  268. }
  269. }
  270. }
  271. }
  272. return macro;
  273. }
  274. void PropertyEditor::setupTabs()
  275. {
  276. setupTabGeneral();
  277. // int flags = m_objectProperties->getPropertyFlags();
  278. //
  279. // if ( flags & KPrObjectProperties::PtPen )
  280. // setupTabPen( flags & KPrObjectProperties::PtLineEnds );
  281. //
  282. // if ( flags & KPrObjectProperties::PtBrush )
  283. // setupTabBrush();
  284. //
  285. // if ( flags & KPrObjectProperties::PtRectangle )
  286. // setupTabRect();
  287. //
  288. // if ( flags & KPrObjectProperties::PtPolygon )
  289. // setupTabPolygon();
  290. //
  291. // if ( flags & KPrObjectProperties::PtPie )
  292. // setupTabPie();
  293. //
  294. // if ( flags & KPrObjectProperties::PtPicture )
  295. // setupTabPicture();
  296. //
  297. // if ( flags & KPrObjectProperties::PtText )
  298. // setupTabText();
  299. }
  300. /*
  301. void PropertyEditor::setupTabPen( bool configureLineEnds )
  302. {
  303. if ( m_penProperty == 0 )
  304. {
  305. KoPenCmd::Pen pen( m_objectProperties->getPen() );
  306. m_penProperty = new KPrPenStyleWidget( this, 0, pen, configureLineEnds );
  307. addTab( m_penProperty, i18n( "Outl&ine" ) );
  308. }
  309. }
  310. void PropertyEditor::setupTabBrush()
  311. {
  312. if ( m_brushProperty == 0 )
  313. {
  314. KPrBrushCmd::Brush brush( m_objectProperties->getBrush() );
  315. m_brushProperty = new KPrBrushProperty( this, 0, brush );
  316. addTab( m_brushProperty, i18n( "&Fill" ) );
  317. }
  318. }
  319. void PropertyEditor::setupTabRect()
  320. {
  321. if ( m_rectProperty == 0 )
  322. {
  323. KPrRectValueCmd::RectValues rectValues = m_objectProperties->getRectValues();
  324. m_rectProperty = new KPrRectProperty( this, 0, rectValues );
  325. addTab( m_rectProperty, i18n( "&Rectangle" ) );
  326. }
  327. }
  328. void PropertyEditor::setupTabPolygon()
  329. {
  330. if ( m_polygonProperty == 0 )
  331. {
  332. KPrPolygonSettingCmd::PolygonSettings polygonSettings = m_objectProperties->getPolygonSettings();
  333. m_polygonProperty = new KPrPolygonProperty( this, 0, polygonSettings );
  334. addTab( m_polygonProperty, i18n("Polygo&n" ) );
  335. }
  336. }
  337. void PropertyEditor::setupTabPie()
  338. {
  339. if ( m_pieProperty == 0 )
  340. {
  341. m_pieProperty = new KPrPieProperty( this, 0, m_objectProperties->getPieValues() );
  342. addTab( m_pieProperty, i18n("&Pie" ) );
  343. }
  344. }
  345. void PropertyEditor::setupTabPicture()
  346. {
  347. if ( m_pictureProperty == 0 )
  348. {
  349. m_pictureProperty = new KPrPictureProperty( this, 0, m_objectProperties->getPixmap(), m_objectProperties->getPictureSettings() );
  350. addTab( m_pictureProperty, i18n("Pict&ure" ) );
  351. }
  352. }
  353. void PropertyEditor::setupTabText()
  354. {
  355. if ( m_textProperty == 0 )
  356. {
  357. m_textProperty = new KPrTextProperty( this, 0, m_objectProperties->getMarginsStruct(),
  358. m_doc->unit(), m_objectProperties->getProtectContent() );
  359. addTab( m_textProperty, i18n("Te&xt" ) );
  360. }
  361. }*/
  362. void PropertyEditor::setupTabGeneral()
  363. {
  364. if ( m_generalProperty == 0 )
  365. {
  366. GeneralProperty::GeneralValue generalValue = getGeneralValue();
  367. m_generalProperty = new GeneralProperty( this, 0, generalValue, m_doc->unit() );
  368. addTab( m_generalProperty, i18n( "&General" ) );
  369. }
  370. }
  371. GeneralProperty::GeneralValue PropertyEditor::getGeneralValue()
  372. {
  373. GeneralProperty::GeneralValue generalValue;
  374. if ( m_objects.count() == 1 )
  375. {
  376. generalValue.m_name = m_objects.at( 0 )->getObjectName();
  377. }
  378. bool protect = false;
  379. generalValue.m_protect = STATE_OFF;
  380. bool keepRatio = false;
  381. generalValue.m_keepRatio = STATE_OFF;
  382. TQPtrListIterator<EmbeddedObject> it( m_objects );
  383. if ( it.current() )
  384. {
  385. protect = it.current()->isProtect();
  386. generalValue.m_protect = protect ? STATE_ON : STATE_OFF;
  387. keepRatio = it.current()->isKeepRatio();
  388. generalValue.m_keepRatio = keepRatio ? STATE_ON : STATE_OFF;
  389. generalValue.m_rect = it.current()->geometry()/*getRect()*/;
  390. ++it;
  391. }
  392. for ( ; it.current(); ++it )
  393. {
  394. if ( protect != it.current()->isProtect() )
  395. {
  396. generalValue.m_protect = STATE_UNDEF;
  397. if ( generalValue.m_keepRatio == STATE_UNDEF )
  398. {
  399. break;
  400. }
  401. }
  402. if ( keepRatio != it.current()->isKeepRatio() )
  403. {
  404. generalValue.m_keepRatio = STATE_UNDEF;
  405. if ( generalValue.m_protect == STATE_UNDEF )
  406. {
  407. break;
  408. }
  409. }
  410. }
  411. return generalValue;
  412. }
  413. void PropertyEditor::slotDone()
  414. {
  415. emit propertiesOk();
  416. // if ( m_penProperty )
  417. // m_penProperty->apply();
  418. // if ( m_brushProperty )
  419. // m_brushProperty->apply();
  420. // if ( m_rectProperty )
  421. // m_rectProperty->apply();
  422. // if ( m_polygonProperty )
  423. // m_polygonProperty->apply();
  424. // if ( m_pieProperty )
  425. // m_pieProperty->apply();
  426. // if ( m_pictureProperty )
  427. // m_pictureProperty->apply();
  428. // if ( m_textProperty )
  429. // m_textProperty->apply();
  430. if ( m_generalProperty )
  431. m_generalProperty->apply();
  432. }
  433. #include "kspread_propertyEditor.moc"