22#include <tqcheckbox.h>
23#include <tqgroupbox.h>
27#include <tqvgroupbox.h>
28#include <tqcombobox.h>
31#include <kiconloader.h>
33#include <kdialogbase.h>
36#include <kcolorbutton.h>
37#include <KoUnitWidgets.h>
39#include "karbon_view.h"
40#include "karbon_part.h"
41#include "karbon_factory.h"
43#include "vconfiguredlg.h"
46VConfigureDlg::VConfigureDlg( KarbonView* parent )
47 : KDialogBase( KDialogBase::IconList, i18n(
"Configure" ),
48 KDialogBase::Ok | KDialogBase::Apply | KDialogBase::Cancel | KDialogBase::Default,
49 KDialogBase::Ok, parent )
52 TQVBox * page = addVBoxPage(
53 i18n(
"Interface" ), i18n(
"Interface" ),
54 BarIcon(
"misc", TDEIcon::SizeMedium ) );
56 m_interfacePage =
new VConfigInterfacePage( parent, page );
59 i18n(
"Misc" ), i18n(
"Misc" ),
60 BarIcon(
"misc", TDEIcon::SizeMedium ) );
62 m_miscPage =
new VConfigMiscPage( parent, page );
65 i18n(
"Grid" ), i18n(
"Grid" ),
66 BarIcon(
"grid", TDEIcon::SizeMedium ) );
68 m_gridPage =
new VConfigGridPage( parent, page );
70 connect( m_miscPage, TQ_SIGNAL( unitChanged(
int ) ), m_gridPage, TQ_SLOT( slotUnitChanged(
int ) ) );
73 i18n(
"Document" ), i18n(
"Document Settings" ),
74 BarIcon(
"text-x-generic", TDEIcon::SizeMedium ) );
76 m_defaultDocPage =
new VConfigDefaultPage( parent, page );
77 connect(
this, TQ_SIGNAL( okClicked() ),
this, TQ_SLOT( slotApply() ) );
80void VConfigureDlg::slotApply()
82 m_interfacePage->apply();
84 m_defaultDocPage->apply();
88void VConfigureDlg::slotDefault()
90 switch( activePageIndex() )
92 case 0: m_interfacePage->slotDefault();
94 case 1: m_miscPage->slotDefault();
96 case 2: m_gridPage->slotDefault();
98 case 3: m_defaultDocPage->slotDefault();
106VConfigInterfacePage::VConfigInterfacePage( KarbonView* view,
107 TQVBox* box,
char* name )
108 : TQObject( box->parent(), name )
111 m_config = KarbonFactory::instance()->config();
113 m_oldRecentFiles = 10;
114 m_oldCopyOffset = 10;
115 m_oldDockerFontSize = 8;
116 bool oldShowStatusBar =
true;
118 TQVGroupBox* tmpTQGroupBox =
new TQVGroupBox( i18n(
"Interface" ), box );
120 m_config->setGroup(
"" );
122 m_oldDockerFontSize = m_config->readNumEntry(
"palettefontsize", m_oldDockerFontSize );
124 if( m_config->hasGroup(
"Interface" ) )
126 m_config->setGroup(
"Interface" );
128 m_oldRecentFiles = m_config->readNumEntry(
129 "NbRecentFile", m_oldRecentFiles );
131 oldShowStatusBar = m_config->readBoolEntry(
132 "ShowStatusBar" ,
true );
134 m_oldCopyOffset = m_config->readNumEntry(
135 "CopyOffset", m_oldCopyOffset );
138 m_showStatusBar =
new TQCheckBox( i18n(
"Show status bar" ), tmpTQGroupBox );
139 m_showStatusBar->setChecked( oldShowStatusBar );
141 m_recentFiles =
new KIntNumInput( m_oldRecentFiles, tmpTQGroupBox );
142 m_recentFiles->setRange( 1, 20, 1 );
143 m_recentFiles->setLabel( i18n(
"Number of recent files:" ) );
145 m_copyOffset =
new KIntNumInput( m_oldCopyOffset, tmpTQGroupBox );
146 m_copyOffset->setRange( 1, 50, 1 );
147 m_copyOffset->setLabel( i18n(
"Copy offset:" ) );
149 m_dockerFontSize =
new KIntNumInput( m_oldDockerFontSize, tmpTQGroupBox );
150 m_dockerFontSize->setRange( 5, 20, 1 );
151 m_dockerFontSize->setLabel( i18n(
"Palette font size:" ) );
154void VConfigInterfacePage::apply()
156 bool showStatusBar = m_showStatusBar->isChecked();
158 KarbonPart* part = m_view->part();
160 m_config->setGroup(
"Interface" );
162 int recent = m_recentFiles->value();
164 if( recent != m_oldRecentFiles )
166 m_config->writeEntry(
"NbRecentFile", recent );
167 m_view->setNumberOfRecentFiles( recent );
168 m_oldRecentFiles = recent;
171 int copyOffset = m_copyOffset->value();
173 if( copyOffset != m_oldCopyOffset )
175 m_config->writeEntry(
"CopyOffset", copyOffset );
176 m_oldCopyOffset = copyOffset;
179 bool refreshGUI =
false;
181 if( showStatusBar != part->showStatusBar() )
183 m_config->writeEntry(
"ShowStatusBar", showStatusBar );
184 part->setShowStatusBar( showStatusBar );
188 m_config->setGroup(
"" );
190 int dockerFontSize = m_dockerFontSize->value();
192 if( dockerFontSize != m_oldDockerFontSize )
194 m_config->writeEntry(
"palettefontsize", dockerFontSize );
195 m_oldDockerFontSize = dockerFontSize;
204void VConfigInterfacePage::slotDefault()
206 m_recentFiles->setValue( 10 );
207 m_dockerFontSize->setValue( 8 );
208 m_showStatusBar->setChecked(
true );
212VConfigMiscPage::VConfigMiscPage( KarbonView* view, TQVBox* box,
char* name )
213 : TQObject( box->parent(), name )
216 m_config = KarbonFactory::instance()->config();
218 KoUnit::Unit unit = view->part()->unit();
220 TQGroupBox* tmpTQGroupBox =
new TQGroupBox( 0, TQt::Vertical, i18n(
"Misc" ), box,
"GroupBox" );
221 tmpTQGroupBox->layout()->setSpacing(KDialog::spacingHint());
222 tmpTQGroupBox->layout()->setMargin(KDialog::marginHint());
224 TQGridLayout* grid =
new TQGridLayout(tmpTQGroupBox->layout(), 4, 2 );
228 TQString unitType = KoUnit::unitName( unit );
233 if( m_config->hasGroup(
"Misc" ) )
235 m_config->setGroup(
"Misc" );
236 m_oldUndoRedo = m_config->readNumEntry(
"UndoRedo", m_oldUndoRedo );
239 m_undoRedo =
new KIntNumInput( m_oldUndoRedo, tmpTQGroupBox );
240 m_undoRedo->setLabel( i18n(
"Undo/redo limit:" ) );
241 m_undoRedo->setRange( 10, 60, 1 );
243 grid->addMultiCellWidget( m_undoRedo, 0, 0, 0, 1 );
245 grid->addWidget(
new TQLabel( i18n(
"Units:" ), tmpTQGroupBox ), 1, 0 );
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 ) ) );
255void VConfigMiscPage::apply()
257 KarbonPart * part = m_view->part();
259 m_config->setGroup(
"Misc" );
261 if( m_oldUnit != m_unit->currentItem() )
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() ) );
269 int newUndo = m_undoRedo->value();
271 if( newUndo != m_oldUndoRedo )
273 m_config->writeEntry(
"UndoRedo", newUndo );
274 part->setUndoRedoLimit( newUndo );
275 m_oldUndoRedo = newUndo;
279void VConfigMiscPage::slotDefault()
281 m_undoRedo->setValue( 30 );
282 m_unit->setCurrentItem( 0 );
285VConfigGridPage::VConfigGridPage( KarbonView* view, TQVBox* page,
char* name )
286 : TQObject( page->parent(), name )
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();
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 );
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 );
331 connect( m_spaceHorizUSpin, TQ_SIGNAL( valueChanged(
double ) ), TQ_SLOT( setMaxHorizSnap(
double ) ) );
332 connect( m_spaceVertUSpin, TQ_SIGNAL( valueChanged(
double ) ), TQ_SLOT( setMaxVertSnap(
double ) ) ) ;
335void VConfigGridPage::setMaxHorizSnap(
double v )
337 m_snapHorizUSpin->setMaxValue( v );
340void VConfigGridPage::setMaxVertSnap(
double v )
342 m_snapVertUSpin->setMaxValue( v );
345void VConfigGridPage::slotUnitChanged(
int u )
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 );
354void VConfigGridPage::apply()
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();
367void VConfigGridPage::slotDefault()
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 ) );
379VConfigDefaultPage::VConfigDefaultPage( KarbonView* view,
380 TQVBox* box,
char* name )
381 : TQObject( box->parent(), name )
385 m_config = KarbonFactory::instance()->config();
387 TQVGroupBox* gbDocumentSettings =
new TQVGroupBox(
388 i18n(
"Document Settings" ), box );
389 gbDocumentSettings->setMargin( KDialog::marginHint() );
390 gbDocumentSettings->setInsideSpacing( KDialog::spacingHint() );
392 m_oldAutoSave = m_view->part()->defaultAutoSave() / 60;
394 m_oldBackupFile =
true;
396 m_oldSaveAsPath =
true;
398 if( m_config->hasGroup(
"Interface" ) )
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 );
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" ) );
412 m_createBackupFile =
new TQCheckBox( i18n(
"Create backup file" ), gbDocumentSettings );
413 m_createBackupFile->setChecked( m_oldBackupFile );
415 m_saveAsPath =
new TQCheckBox( i18n(
"Save as path" ), gbDocumentSettings );
416 m_saveAsPath->setChecked( m_oldSaveAsPath );
419void VConfigDefaultPage::apply()
421 m_config->setGroup(
"Document defaults" );
423 m_config->setGroup(
"Interface" );
425 int autoSave = m_autoSave->value();
427 if( autoSave != m_oldAutoSave )
429 m_config->writeEntry(
"AutoSave", autoSave );
430 m_view->part()->setAutoSave( autoSave * 60 );
431 m_oldAutoSave = autoSave;
434 bool state = m_createBackupFile->isChecked();
436 if( state != m_oldBackupFile )
438 m_config->writeEntry(
"BackupFile", state );
439 m_view->part()->setBackupFile( state );
440 m_oldBackupFile = state;
443 state = m_saveAsPath->isChecked();
447 m_config->writeEntry(
"SaveAsPath", state );
448 m_view->part()->document().saveAsPath( state );
449 m_oldSaveAsPath = state;
453void VConfigDefaultPage::slotDefault()
455 m_autoSave->setValue( m_view->part()->defaultAutoSave() / 60 );
456 m_createBackupFile->setChecked(
true );
457 m_saveAsPath->setChecked(
true );
460#include "vconfiguredlg.moc"
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.