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.

vconfiguredlg.cc 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /* This file is part of the KDE project
  2. Copyright (C) 2002, 2003 Laurent Montel <lmontel@mandrakesoft.com>
  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 <float.h>
  17. #include <tqcheckbox.h>
  18. #include <tqgroupbox.h>
  19. #include <tqlabel.h>
  20. #include <tqlayout.h>
  21. #include <tqvbox.h>
  22. #include <tqvgroupbox.h>
  23. #include <tqcombobox.h>
  24. #include <tqgrid.h>
  25. #include <kiconloader.h>
  26. #include <tdeconfig.h>
  27. #include <kdialogbase.h>
  28. #include <klocale.h>
  29. #include <knuminput.h>
  30. #include <kcolorbutton.h>
  31. #include <KoUnitWidgets.h>
  32. #include "karbon_view.h"
  33. #include "karbon_part.h"
  34. #include "karbon_factory.h"
  35. #include "vconfiguredlg.h"
  36. VConfigureDlg::VConfigureDlg( KarbonView* parent )
  37. : KDialogBase( KDialogBase::IconList, i18n( "Configure" ),
  38. KDialogBase::Ok | KDialogBase::Apply | KDialogBase::Cancel | KDialogBase::Default,
  39. KDialogBase::Ok, parent )
  40. {
  41. TQVBox * page = addVBoxPage(
  42. i18n( "Interface" ), i18n( "Interface" ),
  43. BarIcon( "misc", KIcon::SizeMedium ) );
  44. m_interfacePage = new VConfigInterfacePage( parent, page );
  45. page = addVBoxPage(
  46. i18n( "Misc" ), i18n( "Misc" ),
  47. BarIcon( "misc", KIcon::SizeMedium ) );
  48. m_miscPage = new VConfigMiscPage( parent, page );
  49. page = addVBoxPage(
  50. i18n( "Grid" ), i18n( "Grid" ),
  51. BarIcon( "grid", KIcon::SizeMedium ) );
  52. m_gridPage = new VConfigGridPage( parent, page );
  53. connect( m_miscPage, TQT_SIGNAL( unitChanged( int ) ), m_gridPage, TQT_SLOT( slotUnitChanged( int ) ) );
  54. page = addVBoxPage(
  55. i18n( "Document" ), i18n( "Document Settings" ),
  56. BarIcon( "document", KIcon::SizeMedium ) );
  57. m_defaultDocPage = new VConfigDefaultPage( parent, page );
  58. connect( this, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( slotApply() ) );
  59. }
  60. void VConfigureDlg::slotApply()
  61. {
  62. m_interfacePage->apply();
  63. m_miscPage->apply();
  64. m_defaultDocPage->apply();
  65. m_gridPage->apply();
  66. }
  67. void VConfigureDlg::slotDefault()
  68. {
  69. switch( activePageIndex() )
  70. {
  71. case 0: m_interfacePage->slotDefault();
  72. break;
  73. case 1: m_miscPage->slotDefault();
  74. break;
  75. case 2: m_gridPage->slotDefault();
  76. break;
  77. case 3: m_defaultDocPage->slotDefault();
  78. break;
  79. default:
  80. break;
  81. }
  82. }
  83. VConfigInterfacePage::VConfigInterfacePage( KarbonView* view,
  84. TQVBox* box, char* name )
  85. : TQObject( box->parent(), name )
  86. {
  87. m_view = view;
  88. m_config = KarbonFactory::instance()->config();
  89. m_oldRecentFiles = 10;
  90. m_oldCopyOffset = 10;
  91. m_oldDockerFontSize = 8;
  92. bool oldShowStatusBar = true;
  93. TQVGroupBox* tmpTQGroupBox = new TQVGroupBox( i18n( "Interface" ), box );
  94. m_config->setGroup( "" );
  95. m_oldDockerFontSize = m_config->readNumEntry( "palettefontsize", m_oldDockerFontSize );
  96. if( m_config->hasGroup( "Interface" ) )
  97. {
  98. m_config->setGroup( "Interface" );
  99. m_oldRecentFiles = m_config->readNumEntry(
  100. "NbRecentFile", m_oldRecentFiles );
  101. oldShowStatusBar = m_config->readBoolEntry(
  102. "ShowStatusBar" , true );
  103. m_oldCopyOffset = m_config->readNumEntry(
  104. "CopyOffset", m_oldCopyOffset );
  105. }
  106. m_showStatusBar = new TQCheckBox( i18n( "Show status bar" ), tmpTQGroupBox );
  107. m_showStatusBar->setChecked( oldShowStatusBar );
  108. m_recentFiles = new KIntNumInput( m_oldRecentFiles, tmpTQGroupBox );
  109. m_recentFiles->setRange( 1, 20, 1 );
  110. m_recentFiles->setLabel( i18n( "Number of recent files:" ) );
  111. m_copyOffset = new KIntNumInput( m_oldCopyOffset, tmpTQGroupBox );
  112. m_copyOffset->setRange( 1, 50, 1 );
  113. m_copyOffset->setLabel( i18n( "Copy offset:" ) );
  114. m_dockerFontSize = new KIntNumInput( m_oldDockerFontSize, tmpTQGroupBox );
  115. m_dockerFontSize->setRange( 5, 20, 1 );
  116. m_dockerFontSize->setLabel( i18n( "Palette font size:" ) );
  117. }
  118. void VConfigInterfacePage::apply()
  119. {
  120. bool showStatusBar = m_showStatusBar->isChecked();
  121. KarbonPart* part = m_view->part();
  122. m_config->setGroup( "Interface" );
  123. int recent = m_recentFiles->value();
  124. if( recent != m_oldRecentFiles )
  125. {
  126. m_config->writeEntry( "NbRecentFile", recent );
  127. m_view->setNumberOfRecentFiles( recent );
  128. m_oldRecentFiles = recent;
  129. }
  130. int copyOffset = m_copyOffset->value();
  131. if( copyOffset != m_oldCopyOffset )
  132. {
  133. m_config->writeEntry( "CopyOffset", copyOffset );
  134. m_oldCopyOffset = copyOffset;
  135. }
  136. bool refreshGUI = false;
  137. if( showStatusBar != part->showStatusBar() )
  138. {
  139. m_config->writeEntry( "ShowStatusBar", showStatusBar );
  140. part->setShowStatusBar( showStatusBar );
  141. refreshGUI = true;
  142. }
  143. m_config->setGroup( "" );
  144. int dockerFontSize = m_dockerFontSize->value();
  145. if( dockerFontSize != m_oldDockerFontSize )
  146. {
  147. m_config->writeEntry( "palettefontsize", dockerFontSize );
  148. m_oldDockerFontSize = dockerFontSize;
  149. refreshGUI = true;
  150. }
  151. if( refreshGUI )
  152. part->reorganizeGUI();
  153. }
  154. void VConfigInterfacePage::slotDefault()
  155. {
  156. m_recentFiles->setValue( 10 );
  157. m_dockerFontSize->setValue( 8 );
  158. m_showStatusBar->setChecked( true );
  159. }
  160. VConfigMiscPage::VConfigMiscPage( KarbonView* view, TQVBox* box, char* name )
  161. : TQObject( box->parent(), name )
  162. {
  163. m_view = view;
  164. m_config = KarbonFactory::instance()->config();
  165. KoUnit::Unit unit = view->part()->unit();
  166. TQGroupBox* tmpTQGroupBox = new TQGroupBox( 0, Qt::Vertical, i18n( "Misc" ), box, "GroupBox" );
  167. tmpTQGroupBox->layout()->setSpacing(KDialog::spacingHint());
  168. tmpTQGroupBox->layout()->setMargin(KDialog::marginHint());
  169. TQGridLayout* grid = new TQGridLayout(tmpTQGroupBox->layout(), 4, 2 );
  170. m_oldUndoRedo = 30;
  171. TQString unitType = KoUnit::unitName( unit );
  172. //#################"laurent
  173. //don't load unitType from config file because unit is
  174. //depend from kword file => unit can be different from config file
  175. if( m_config->hasGroup( "Misc" ) )
  176. {
  177. m_config->setGroup( "Misc" );
  178. m_oldUndoRedo = m_config->readNumEntry( "UndoRedo", m_oldUndoRedo );
  179. }
  180. m_undoRedo = new KIntNumInput( m_oldUndoRedo, tmpTQGroupBox );
  181. m_undoRedo->setLabel( i18n( "Undo/redo limit:" ) );
  182. m_undoRedo->setRange( 10, 60, 1 );
  183. grid->addMultiCellWidget( m_undoRedo, 0, 0, 0, 1 );
  184. grid->addWidget( new TQLabel( i18n( "Units:" ), tmpTQGroupBox ), 1, 0 );
  185. m_unit = new TQComboBox( tmpTQGroupBox );
  186. m_unit->insertStringList( KoUnit::listOfUnitName() );
  187. grid->addWidget( m_unit, 1, 1 );
  188. m_oldUnit = KoUnit::unit( unitType );
  189. m_unit->setCurrentItem( m_oldUnit );
  190. connect( m_unit, TQT_SIGNAL( activated( int ) ), TQT_SIGNAL( unitChanged( int ) ) );
  191. }
  192. void VConfigMiscPage::apply()
  193. {
  194. KarbonPart * part = m_view->part();
  195. m_config->setGroup( "Misc" );
  196. if( m_oldUnit != m_unit->currentItem() )
  197. {
  198. m_oldUnit = m_unit->currentItem();
  199. part->setUnit( static_cast<KoUnit::Unit>( m_oldUnit ) );
  200. part->document().setUnit(part->unit());
  201. m_config->writeEntry( "Units", KoUnit::unitName( part->unit() ) );
  202. }
  203. int newUndo = m_undoRedo->value();
  204. if( newUndo != m_oldUndoRedo )
  205. {
  206. m_config->writeEntry( "UndoRedo", newUndo );
  207. part->setUndoRedoLimit( newUndo );
  208. m_oldUndoRedo = newUndo;
  209. }
  210. }
  211. void VConfigMiscPage::slotDefault()
  212. {
  213. m_undoRedo->setValue( 30 );
  214. m_unit->setCurrentItem( 0 );
  215. }
  216. VConfigGridPage::VConfigGridPage( KarbonView* view, TQVBox* page, char* name )
  217. : TQObject( page->parent(), name )
  218. {
  219. m_view = view;
  220. KoUnit::Unit unit = view->part()->document().unit();
  221. KarbonGridData &gd = view->part()->document().grid();
  222. double pgw = view->part()->document().width();
  223. double pgh = view->part()->document().height();
  224. double fw = gd.freq.width();
  225. double fh = gd.freq.height();
  226. double sw = gd.snap.width();
  227. double sh = gd.snap.height();
  228. m_gridChBox = new TQCheckBox( i18n( "Show &grid" ), page );
  229. m_gridChBox->setChecked( gd.isShow );
  230. m_snapChBox = new TQCheckBox( i18n( "Snap to g&rid" ), page );
  231. m_snapChBox->setChecked( gd.isSnap );
  232. TQLabel* gridColorLbl = new TQLabel( i18n( "Grid &color:" ), page);
  233. m_gridColorBtn = new KColorButton( gd.color, page );
  234. gridColorLbl->setBuddy( m_gridColorBtn );
  235. TQGroupBox* spacingGrp = new TQGroupBox( 2, Qt::Horizontal, i18n( "Spacing" ), page );
  236. TQLabel* spaceHorizLbl = new TQLabel( i18n( "&Horizontal:" ), spacingGrp );
  237. m_spaceHorizUSpin = new KoUnitDoubleSpinBox( spacingGrp, 0.0, pgw, 0.1, fw, unit );
  238. spaceHorizLbl->setBuddy( m_spaceHorizUSpin );
  239. TQLabel* spaceVertLbl = new TQLabel( i18n( "&Vertical:" ), spacingGrp );
  240. m_spaceVertUSpin = new KoUnitDoubleSpinBox( spacingGrp, 0.0, pgh, 0.1, fh, unit );
  241. spaceVertLbl->setBuddy( m_spaceVertUSpin );
  242. TQGroupBox* snapGrp = new TQGroupBox( 2, Qt::Horizontal, i18n( "Snap Distance" ), page );
  243. TQLabel* snapHorizLbl = new TQLabel( i18n( "H&orizontal:" ), snapGrp );
  244. m_snapHorizUSpin = new KoUnitDoubleSpinBox( snapGrp, 0.0, fw, 0.1, sw, unit );
  245. snapHorizLbl->setBuddy( m_snapHorizUSpin );
  246. TQLabel* snapVertLbl = new TQLabel( i18n( "V&ertical:" ), snapGrp );
  247. m_snapVertUSpin = new KoUnitDoubleSpinBox( snapGrp, 0.0, fh, 0.1, sh, unit );
  248. snapVertLbl->setBuddy( m_snapVertUSpin );
  249. TQGridLayout* gl = new TQGridLayout();
  250. gl->setSpacing( KDialog::spacingHint() );
  251. gl->addMultiCellWidget( m_gridChBox, 0, 0, 0, 2 );
  252. gl->addMultiCellWidget( m_snapChBox, 1, 1, 0, 2 );
  253. gl->addWidget( gridColorLbl, 2, 0) ;
  254. gl->addWidget( m_gridColorBtn, 2, 1 );
  255. gl->addItem( new TQSpacerItem( 0, 0 ), 2, 2 );
  256. gl->addMultiCellWidget( spacingGrp, 3, 3, 0, 2 );
  257. gl->addMultiCellWidget( snapGrp, 4, 4, 0, 2 );
  258. gl->addMultiCell( new TQSpacerItem( 0, 0 ), 5, 5, 0, 2 );
  259. connect( m_spaceHorizUSpin, TQT_SIGNAL( valueChanged( double ) ), TQT_SLOT( setMaxHorizSnap( double ) ) );
  260. connect( m_spaceVertUSpin, TQT_SIGNAL( valueChanged( double ) ), TQT_SLOT( setMaxVertSnap( double ) ) ) ;
  261. }
  262. void VConfigGridPage::setMaxHorizSnap( double v )
  263. {
  264. m_snapHorizUSpin->setMaxValue( v );
  265. }
  266. void VConfigGridPage::setMaxVertSnap( double v )
  267. {
  268. m_snapVertUSpin->setMaxValue( v );
  269. }
  270. void VConfigGridPage::slotUnitChanged( int u )
  271. {
  272. KoUnit::Unit unit = static_cast<KoUnit::Unit>( u );
  273. m_snapHorizUSpin->setUnit( unit );
  274. m_snapVertUSpin->setUnit( unit );
  275. m_spaceHorizUSpin->setUnit( unit );
  276. m_spaceVertUSpin->setUnit( unit );
  277. }
  278. void VConfigGridPage::apply()
  279. {
  280. KarbonGridData &gd = m_view->part()->document().grid();
  281. gd.freq.setWidth( m_spaceHorizUSpin->value() );
  282. gd.freq.setHeight( m_spaceVertUSpin->value() );
  283. gd.snap.setWidth( m_snapHorizUSpin->value() );
  284. gd.snap.setHeight( m_snapVertUSpin->value() );
  285. gd.isShow = m_gridChBox->isChecked();
  286. gd.isSnap = m_snapChBox->isChecked();
  287. gd.color = m_gridColorBtn->color();
  288. m_view->repaintAll();
  289. }
  290. void VConfigGridPage::slotDefault()
  291. {
  292. KoUnit::Unit unit = m_view->part()->document().unit();
  293. m_spaceHorizUSpin->setValue( KoUnit::toUserValue( 20.0, unit ) );
  294. m_spaceVertUSpin->setValue( KoUnit::toUserValue( 20.0, unit ) );
  295. m_snapHorizUSpin->setValue( KoUnit::toUserValue( 20.0, unit ) );
  296. m_snapVertUSpin->setValue( KoUnit::toUserValue( 20.0, unit ) );
  297. m_gridChBox->setChecked( true );
  298. m_snapChBox->setChecked( true );
  299. m_gridColorBtn->setColor( TQColor( 228, 228, 228 ) );
  300. }
  301. VConfigDefaultPage::VConfigDefaultPage( KarbonView* view,
  302. TQVBox* box, char* name )
  303. : TQObject( box->parent(), name )
  304. {
  305. m_view = view;
  306. m_config = KarbonFactory::instance()->config();
  307. TQVGroupBox* gbDocumentSettings = new TQVGroupBox(
  308. i18n( "Document Settings" ), box );
  309. gbDocumentSettings->setMargin( KDialog::marginHint() );
  310. gbDocumentSettings->setInsideSpacing( KDialog::spacingHint() );
  311. m_oldAutoSave = m_view->part()->defaultAutoSave() / 60;
  312. m_oldBackupFile = true;
  313. m_oldSaveAsPath = true;
  314. if( m_config->hasGroup( "Interface" ) )
  315. {
  316. m_config->setGroup( "Interface" );
  317. m_oldAutoSave = m_config->readNumEntry( "AutoSave", m_oldAutoSave );
  318. m_oldBackupFile = m_config->readBoolEntry( "BackupFile", m_oldBackupFile );
  319. m_oldSaveAsPath = m_config->readBoolEntry( "SaveAsPath", m_oldSaveAsPath );
  320. }
  321. m_autoSave = new KIntNumInput( m_oldAutoSave, gbDocumentSettings );
  322. m_autoSave->setRange( 0, 60, 1 );
  323. m_autoSave->setLabel( i18n( "Auto save (min):" ) );
  324. m_autoSave->setSpecialValueText( i18n( "No auto save" ) );
  325. m_autoSave->setSuffix( i18n( "min" ) );
  326. m_createBackupFile = new TQCheckBox( i18n( "Create backup file" ), gbDocumentSettings );
  327. m_createBackupFile->setChecked( m_oldBackupFile );
  328. m_saveAsPath = new TQCheckBox( i18n( "Save as path" ), gbDocumentSettings );
  329. m_saveAsPath->setChecked( m_oldSaveAsPath );
  330. }
  331. void VConfigDefaultPage::apply()
  332. {
  333. m_config->setGroup( "Document defaults" );
  334. m_config->setGroup( "Interface" );
  335. int autoSave = m_autoSave->value();
  336. if( autoSave != m_oldAutoSave )
  337. {
  338. m_config->writeEntry( "AutoSave", autoSave );
  339. m_view->part()->setAutoSave( autoSave * 60 );
  340. m_oldAutoSave = autoSave;
  341. }
  342. bool state = m_createBackupFile->isChecked();
  343. if( state != m_oldBackupFile )
  344. {
  345. m_config->writeEntry( "BackupFile", state );
  346. m_view->part()->setBackupFile( state );
  347. m_oldBackupFile = state;
  348. }
  349. state = m_saveAsPath->isChecked();
  350. //if( state != m_oldSaveAsPath )
  351. //{
  352. m_config->writeEntry( "SaveAsPath", state );
  353. m_view->part()->document().saveAsPath( state );
  354. m_oldSaveAsPath = state;
  355. //}
  356. }
  357. void VConfigDefaultPage::slotDefault()
  358. {
  359. m_autoSave->setValue( m_view->part()->defaultAutoSave() / 60 );
  360. m_createBackupFile->setChecked( true );
  361. m_saveAsPath->setChecked( true );
  362. }
  363. #include "vconfiguredlg.moc"