karbon

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