KOffice – TDE office suite
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

501 行
15KB

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