karbon

vconfiguredlg.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, 2003 Laurent Montel <lmontel@mandrakesoft.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <float.h>
00021 
00022 #include <qcheckbox.h>
00023 #include <qgroupbox.h>
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 #include <qvbox.h>
00027 #include <qvgroupbox.h>
00028 #include <qcombobox.h>
00029 #include <qgrid.h>
00030 
00031 #include <kiconloader.h>
00032 #include <kconfig.h>
00033 #include <kdialogbase.h>
00034 #include <klocale.h>
00035 #include <knuminput.h>
00036 #include <kcolorbutton.h>
00037 #include <KoUnitWidgets.h>
00038 
00039 #include "karbon_view.h"
00040 #include "karbon_part.h"
00041 #include "karbon_factory.h"
00042 
00043 #include "vconfiguredlg.h"
00044 
00045 
00046 VConfigureDlg::VConfigureDlg( KarbonView* parent )
00047         : KDialogBase( KDialogBase::IconList, i18n( "Configure" ),
00048                        KDialogBase::Ok | KDialogBase::Apply | KDialogBase::Cancel | KDialogBase::Default,
00049                        KDialogBase::Ok, parent )
00050 
00051 {
00052     QVBox * page = addVBoxPage(
00053                        i18n( "Interface" ), i18n( "Interface" ),
00054                        BarIcon( "misc", KIcon::SizeMedium ) );
00055 
00056     m_interfacePage = new VConfigInterfacePage( parent, page );
00057 
00058     page = addVBoxPage(
00059                i18n( "Misc" ), i18n( "Misc" ),
00060                BarIcon( "misc", KIcon::SizeMedium ) );
00061 
00062     m_miscPage = new VConfigMiscPage( parent, page );
00063 
00064     page = addVBoxPage(
00065                i18n( "Grid" ), i18n( "Grid" ),
00066                BarIcon( "grid", KIcon::SizeMedium ) );
00067 
00068     m_gridPage = new VConfigGridPage( parent, page );
00069 
00070     connect( m_miscPage, SIGNAL( unitChanged( int ) ), m_gridPage, SLOT( slotUnitChanged( int ) ) );
00071 
00072     page = addVBoxPage(
00073                i18n( "Document" ), i18n( "Document Settings" ),
00074                BarIcon( "document", KIcon::SizeMedium ) );
00075 
00076     m_defaultDocPage = new VConfigDefaultPage( parent, page );
00077     connect( this, SIGNAL( okClicked() ), this, SLOT( slotApply() ) );
00078 }
00079 
00080 void VConfigureDlg::slotApply()
00081 {
00082     m_interfacePage->apply();
00083     m_miscPage->apply();
00084     m_defaultDocPage->apply();
00085     m_gridPage->apply();
00086 }
00087 
00088 void VConfigureDlg::slotDefault()
00089 {
00090     switch( activePageIndex() )
00091     {
00092         case 0: m_interfacePage->slotDefault();
00093             break;
00094         case 1: m_miscPage->slotDefault();
00095             break;
00096         case 2: m_gridPage->slotDefault();
00097             break;
00098         case 3: m_defaultDocPage->slotDefault();
00099             break;
00100         default:
00101             break;
00102     }
00103 }
00104 
00105 
00106 VConfigInterfacePage::VConfigInterfacePage( KarbonView* view,
00107         QVBox* box, char* name )
00108         : QObject( box->parent(), name )
00109 {
00110     m_view = view;
00111     m_config = KarbonFactory::instance()->config();
00112 
00113     m_oldRecentFiles = 10;
00114     m_oldCopyOffset = 10;
00115     m_oldDockerFontSize = 8;
00116     bool oldShowStatusBar = true;
00117 
00118     QVGroupBox* tmpQGroupBox = new QVGroupBox( i18n( "Interface" ), box );
00119 
00120     m_config->setGroup( "" );
00121 
00122     m_oldDockerFontSize = m_config->readNumEntry( "palettefontsize", m_oldDockerFontSize );
00123 
00124     if( m_config->hasGroup( "Interface" ) )
00125     {
00126         m_config->setGroup( "Interface" );
00127 
00128         m_oldRecentFiles = m_config->readNumEntry(
00129                                "NbRecentFile", m_oldRecentFiles );
00130 
00131         oldShowStatusBar = m_config->readBoolEntry(
00132                                "ShowStatusBar" , true );
00133 
00134         m_oldCopyOffset = m_config->readNumEntry(
00135                                "CopyOffset", m_oldCopyOffset );
00136     }
00137 
00138     m_showStatusBar = new QCheckBox( i18n( "Show status bar" ), tmpQGroupBox );
00139     m_showStatusBar->setChecked( oldShowStatusBar );
00140 
00141     m_recentFiles = new KIntNumInput( m_oldRecentFiles, tmpQGroupBox );
00142     m_recentFiles->setRange( 1, 20, 1 );
00143     m_recentFiles->setLabel( i18n( "Number of recent files:" ) );
00144 
00145     m_copyOffset = new KIntNumInput( m_oldCopyOffset, tmpQGroupBox );
00146     m_copyOffset->setRange( 1, 50, 1 );
00147     m_copyOffset->setLabel( i18n( "Copy offset:" ) );
00148 
00149     m_dockerFontSize = new KIntNumInput( m_oldDockerFontSize, tmpQGroupBox );
00150     m_dockerFontSize->setRange( 5, 20, 1 );
00151     m_dockerFontSize->setLabel( i18n( "Palette font size:" ) );
00152 }
00153 
00154 void VConfigInterfacePage::apply()
00155 {
00156     bool showStatusBar = m_showStatusBar->isChecked();
00157 
00158     KarbonPart* part = m_view->part();
00159 
00160     m_config->setGroup( "Interface" );
00161 
00162     int recent = m_recentFiles->value();
00163 
00164     if( recent != m_oldRecentFiles )
00165     {
00166         m_config->writeEntry( "NbRecentFile", recent );
00167         m_view->setNumberOfRecentFiles( recent );
00168         m_oldRecentFiles = recent;
00169     }
00170 
00171     int copyOffset = m_copyOffset->value();
00172 
00173     if( copyOffset != m_oldCopyOffset )
00174     {
00175         m_config->writeEntry( "CopyOffset", copyOffset );
00176         m_oldCopyOffset = copyOffset;
00177     }
00178 
00179     bool refreshGUI = false;
00180 
00181     if( showStatusBar != part->showStatusBar() )
00182     {
00183         m_config->writeEntry( "ShowStatusBar", showStatusBar );
00184         part->setShowStatusBar( showStatusBar );
00185         refreshGUI = true;
00186     }
00187 
00188     m_config->setGroup( "" );
00189 
00190     int dockerFontSize = m_dockerFontSize->value();
00191 
00192     if( dockerFontSize != m_oldDockerFontSize )
00193     {
00194         m_config->writeEntry( "palettefontsize", dockerFontSize );
00195         m_oldDockerFontSize = dockerFontSize;
00196         refreshGUI = true;
00197     }
00198 
00199     if( refreshGUI )
00200         part->reorganizeGUI();
00201 
00202 }
00203 
00204 void VConfigInterfacePage::slotDefault()
00205 {
00206     m_recentFiles->setValue( 10 );
00207     m_dockerFontSize->setValue( 8 );
00208     m_showStatusBar->setChecked( true );
00209 }
00210 
00211 
00212 VConfigMiscPage::VConfigMiscPage( KarbonView* view, QVBox* box, char* name )
00213         : QObject( box->parent(), name )
00214 {
00215     m_view = view;
00216     m_config = KarbonFactory::instance()->config();
00217 
00218     KoUnit::Unit unit = view->part()->unit();
00219 
00220     QGroupBox* tmpQGroupBox = new QGroupBox( 0, Qt::Vertical, i18n( "Misc" ), box, "GroupBox" );
00221     tmpQGroupBox->layout()->setSpacing(KDialog::spacingHint());
00222     tmpQGroupBox->layout()->setMargin(KDialog::marginHint());
00223 
00224     QGridLayout* grid = new QGridLayout(tmpQGroupBox->layout(), 4, 2 );
00225 
00226     m_oldUndoRedo = 30;
00227 
00228     QString unitType = KoUnit::unitName( unit );
00229     //#################"laurent
00230     //don't load unitType from config file because unit is
00231     //depend from kword file => unit can be different from config file
00232 
00233     if( m_config->hasGroup( "Misc" ) )
00234     {
00235         m_config->setGroup( "Misc" );
00236         m_oldUndoRedo = m_config->readNumEntry( "UndoRedo", m_oldUndoRedo );
00237     }
00238 
00239     m_undoRedo = new KIntNumInput( m_oldUndoRedo, tmpQGroupBox );
00240     m_undoRedo->setLabel( i18n( "Undo/redo limit:" ) );
00241     m_undoRedo->setRange( 10, 60, 1 );
00242 
00243     grid->addMultiCellWidget( m_undoRedo, 0, 0, 0, 1 );
00244 
00245     grid->addWidget( new QLabel(  i18n(  "Units:" ), tmpQGroupBox ), 1, 0 );
00246 
00247     m_unit = new QComboBox( tmpQGroupBox );
00248     m_unit->insertStringList( KoUnit::listOfUnitName() );
00249     grid->addWidget( m_unit, 1, 1 );
00250     m_oldUnit = KoUnit::unit( unitType );
00251     m_unit->setCurrentItem( m_oldUnit );
00252     connect( m_unit, SIGNAL( activated( int ) ), SIGNAL( unitChanged( int ) ) );
00253 }
00254 
00255 void VConfigMiscPage::apply()
00256 {
00257     KarbonPart * part = m_view->part();
00258 
00259     m_config->setGroup( "Misc" );
00260 
00261     if( m_oldUnit != m_unit->currentItem() )
00262     {
00263         m_oldUnit = m_unit->currentItem();
00264     part->setUnit( static_cast<KoUnit::Unit>( m_oldUnit ) );
00265     part->document().setUnit(part->unit());
00266         m_config->writeEntry( "Units", KoUnit::unitName( part->unit() ) );
00267     }
00268 
00269     int newUndo = m_undoRedo->value();
00270 
00271     if( newUndo != m_oldUndoRedo )
00272     {
00273         m_config->writeEntry( "UndoRedo", newUndo );
00274         part->setUndoRedoLimit( newUndo );
00275         m_oldUndoRedo = newUndo;
00276     }
00277 }
00278 
00279 void VConfigMiscPage::slotDefault()
00280 {
00281     m_undoRedo->setValue( 30 );
00282     m_unit->setCurrentItem( 0 );
00283 }
00284 
00285 VConfigGridPage::VConfigGridPage( KarbonView* view, QVBox* page, char* name )
00286         : QObject( page->parent(), name )
00287 {
00288     m_view = view;
00289     KoUnit::Unit unit = view->part()->document().unit();
00290     KarbonGridData &gd = view->part()->document().grid();
00291     double pgw = view->part()->document().width();
00292     double pgh = view->part()->document().height();
00293     double fw = gd.freq.width();
00294     double fh = gd.freq.height();
00295     double sw = gd.snap.width();
00296     double sh = gd.snap.height();
00297 
00298     m_gridChBox = new QCheckBox( i18n( "Show &grid" ), page );
00299     m_gridChBox->setChecked( gd.isShow );
00300     m_snapChBox = new QCheckBox( i18n( "Snap to g&rid" ), page );
00301     m_snapChBox->setChecked( gd.isSnap );
00302     QLabel* gridColorLbl = new QLabel( i18n( "Grid &color:" ), page);
00303     m_gridColorBtn = new KColorButton( gd.color, page );
00304     gridColorLbl->setBuddy( m_gridColorBtn );
00305     QGroupBox* spacingGrp = new QGroupBox( 2, Qt::Horizontal, i18n( "Spacing" ), page );
00306     QLabel* spaceHorizLbl = new QLabel( i18n( "&Horizontal:" ), spacingGrp );
00307     m_spaceHorizUSpin = new KoUnitDoubleSpinBox( spacingGrp, 0.0, pgw, 0.1, fw, unit );
00308     spaceHorizLbl->setBuddy( m_spaceHorizUSpin );
00309     QLabel* spaceVertLbl = new QLabel( i18n( "&Vertical:" ), spacingGrp );
00310     m_spaceVertUSpin = new KoUnitDoubleSpinBox( spacingGrp, 0.0, pgh, 0.1, fh, unit );
00311     spaceVertLbl->setBuddy( m_spaceVertUSpin );
00312     QGroupBox* snapGrp = new QGroupBox( 2, Qt::Horizontal, i18n( "Snap Distance" ), page );
00313     QLabel* snapHorizLbl = new QLabel( i18n( "H&orizontal:" ), snapGrp );
00314     m_snapHorizUSpin = new KoUnitDoubleSpinBox( snapGrp, 0.0, fw, 0.1, sw, unit );
00315     snapHorizLbl->setBuddy( m_snapHorizUSpin );
00316     QLabel* snapVertLbl = new QLabel( i18n( "V&ertical:" ), snapGrp );
00317     m_snapVertUSpin = new KoUnitDoubleSpinBox( snapGrp, 0.0, fh, 0.1, sh, unit );
00318     snapVertLbl->setBuddy( m_snapVertUSpin );
00319 
00320     QGridLayout* gl = new QGridLayout();
00321     gl->setSpacing( KDialog::spacingHint() );
00322     gl->addMultiCellWidget( m_gridChBox, 0, 0, 0, 2 );
00323     gl->addMultiCellWidget( m_snapChBox, 1, 1, 0, 2 );
00324     gl->addWidget( gridColorLbl, 2, 0) ;
00325     gl->addWidget( m_gridColorBtn, 2, 1 );
00326     gl->addItem( new QSpacerItem( 0, 0 ), 2, 2 );
00327     gl->addMultiCellWidget( spacingGrp, 3, 3, 0, 2 );
00328     gl->addMultiCellWidget( snapGrp, 4, 4, 0, 2 );
00329     gl->addMultiCell( new QSpacerItem( 0, 0 ), 5, 5, 0, 2 );
00330 
00331     connect( m_spaceHorizUSpin, SIGNAL( valueChanged( double ) ), SLOT( setMaxHorizSnap( double ) ) );
00332     connect( m_spaceVertUSpin, SIGNAL( valueChanged( double ) ), SLOT( setMaxVertSnap( double ) ) ) ;
00333 }
00334 
00335 void VConfigGridPage::setMaxHorizSnap( double v )
00336 {
00337     m_snapHorizUSpin->setMaxValue( v );
00338 }
00339 
00340 void VConfigGridPage::setMaxVertSnap( double v )
00341 {
00342     m_snapVertUSpin->setMaxValue( v );
00343 }
00344 
00345 void VConfigGridPage::slotUnitChanged( int u )
00346 {
00347     KoUnit::Unit unit = static_cast<KoUnit::Unit>( u );
00348     m_snapHorizUSpin->setUnit( unit );
00349     m_snapVertUSpin->setUnit( unit );
00350     m_spaceHorizUSpin->setUnit( unit );
00351     m_spaceVertUSpin->setUnit( unit );
00352 }
00353 
00354 void VConfigGridPage::apply()
00355 {
00356     KarbonGridData &gd = m_view->part()->document().grid();
00357     gd.freq.setWidth( m_spaceHorizUSpin->value() );
00358     gd.freq.setHeight( m_spaceVertUSpin->value() );
00359     gd.snap.setWidth( m_snapHorizUSpin->value() );
00360     gd.snap.setHeight( m_snapVertUSpin->value() );
00361     gd.isShow = m_gridChBox->isChecked();
00362     gd.isSnap = m_snapChBox->isChecked();
00363     gd.color = m_gridColorBtn->color();
00364     m_view->repaintAll();
00365 }
00366 
00367 void VConfigGridPage::slotDefault()
00368 {
00369     KoUnit::Unit unit = m_view->part()->document().unit();
00370     m_spaceHorizUSpin->setValue( KoUnit::toUserValue( 20.0, unit ) );
00371     m_spaceVertUSpin->setValue( KoUnit::toUserValue( 20.0, unit ) );
00372     m_snapHorizUSpin->setValue( KoUnit::toUserValue( 20.0, unit ) );
00373     m_snapVertUSpin->setValue( KoUnit::toUserValue( 20.0, unit ) );
00374     m_gridChBox->setChecked( true );
00375     m_snapChBox->setChecked( true );
00376     m_gridColorBtn->setColor( QColor( 228, 228, 228 ) );
00377 }
00378 
00379 VConfigDefaultPage::VConfigDefaultPage( KarbonView* view,
00380                                         QVBox* box, char* name )
00381     : QObject( box->parent(), name )
00382 {
00383     m_view = view;
00384 
00385     m_config = KarbonFactory::instance()->config();
00386 
00387     QVGroupBox* gbDocumentSettings = new QVGroupBox(
00388         i18n( "Document Settings" ), box );
00389     gbDocumentSettings->setMargin( KDialog::marginHint() );
00390     gbDocumentSettings->setInsideSpacing( KDialog::spacingHint() );
00391 
00392     m_oldAutoSave = m_view->part()->defaultAutoSave() / 60;
00393 
00394     m_oldBackupFile = true;
00395 
00396     m_oldSaveAsPath = true;
00397 
00398     if( m_config->hasGroup( "Interface" ) )
00399     {
00400         m_config->setGroup( "Interface" );
00401         m_oldAutoSave = m_config->readNumEntry( "AutoSave", m_oldAutoSave );
00402         m_oldBackupFile = m_config->readBoolEntry( "BackupFile", m_oldBackupFile );
00403         m_oldSaveAsPath = m_config->readBoolEntry( "SaveAsPath", m_oldSaveAsPath );
00404     }
00405 
00406     m_autoSave = new KIntNumInput( m_oldAutoSave, gbDocumentSettings );
00407     m_autoSave->setRange( 0, 60, 1 );
00408     m_autoSave->setLabel( i18n( "Auto save (min):" ) );
00409     m_autoSave->setSpecialValueText( i18n( "No auto save" ) );
00410     m_autoSave->setSuffix( i18n( "min" ) );
00411 
00412     m_createBackupFile = new QCheckBox( i18n( "Create backup file" ), gbDocumentSettings );
00413     m_createBackupFile->setChecked( m_oldBackupFile );
00414 
00415     m_saveAsPath = new QCheckBox( i18n( "Save as path" ), gbDocumentSettings );
00416     m_saveAsPath->setChecked( m_oldSaveAsPath );
00417 }
00418 
00419 void VConfigDefaultPage::apply()
00420 {
00421     m_config->setGroup( "Document defaults" );
00422 
00423     m_config->setGroup( "Interface" );
00424 
00425     int autoSave = m_autoSave->value();
00426 
00427     if( autoSave != m_oldAutoSave )
00428     {
00429         m_config->writeEntry( "AutoSave", autoSave );
00430         m_view->part()->setAutoSave( autoSave * 60 );
00431         m_oldAutoSave = autoSave;
00432     }
00433 
00434     bool state = m_createBackupFile->isChecked();
00435 
00436     if( state != m_oldBackupFile )
00437     {
00438         m_config->writeEntry( "BackupFile", state );
00439         m_view->part()->setBackupFile( state );
00440         m_oldBackupFile = state;
00441     }
00442 
00443     state = m_saveAsPath->isChecked();
00444 
00445     //if( state != m_oldSaveAsPath )
00446     //{
00447         m_config->writeEntry( "SaveAsPath", state );
00448         m_view->part()->document().saveAsPath( state );
00449         m_oldSaveAsPath = state;
00450     //}
00451 }
00452 
00453 void VConfigDefaultPage::slotDefault()
00454 {
00455     m_autoSave->setValue( m_view->part()->defaultAutoSave() / 60 );
00456     m_createBackupFile->setChecked( true );
00457     m_saveAsPath->setChecked( true );
00458 }
00459 
00460 #include "vconfiguredlg.moc"
00461 
KDE Home | KDE Accessibility Home | Description of Access Keys