F:/KPlato/koffice/libs/kotext/KoCompletionDia.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Thomas Zander <zander@kde.org>
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 version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  * Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "KoCompletionDia.h"
00020 #include "KoAutoFormat.h"
00021 #include <kvbox.h>
00022 #include <klocale.h>
00023 #include <kmessagebox.h>
00024 #include <kinputdialog.h>
00025 #include <kcompletion.h>
00026 #include <kconfig.h>
00027 #include <kdebug.h>
00028 #include <QLayout>
00029 #include <q3vbox.h>
00030 #include <QCheckBox>
00031 #include <QPushButton>
00032 #include <QSpinBox>
00033 #include <QComboBox>
00034 #include <q3groupbox.h>
00035 #include <q3whatsthis.h>
00036 
00037 KoCompletionDia::KoCompletionDia( QWidget *parent, const char *name, KoAutoFormat * autoFormat )
00038     : KDialog( parent )
00039 {
00040     setCaption( i18n( "Completion" ) );
00041     setModal( true );
00042     setObjectName( name );
00043     setButtons( Ok|Cancel|User1 );
00044     setDefaultButton( Ok );
00045     showButtonSeparator( true );
00046     setButtonGuiItem( User1, KGuiItem( i18n( "&Reset" ), "undo" )  );
00047 
00048     KVBox *page = new KVBox();
00049     setMainWidget(page);
00050     m_widget = new KoCompletion( page, autoFormat);
00051     m_widget->layout()->setMargin(0);
00052     connect( this, SIGNAL( user1Clicked() ), m_widget, SLOT(slotResetConf()));
00053     setButtonWhatsThis(Ok,i18n("This will save your options."));
00054     setButtonWhatsThis(Cancel,i18n("This will abort all changes."));
00055     setButtonWhatsThis(User1,i18n("This will reset to the state after you clicked on the Make Default button."));
00056 }
00057 
00058 void KoCompletionDia::slotOk()
00059 {
00060     m_widget->saveSettings();
00061     slotButtonClicked( Ok );
00062 }
00063 
00064 KoCompletion::KoCompletion(QWidget *parent, KoAutoFormat *autoFormat) : KoCompletionBase(parent),
00065       m_autoFormat( *autoFormat ),
00066       m_docAutoFormat( autoFormat )
00067 {
00068     connect(cbAllowCompletion, SIGNAL(toggled ( bool )), this, SLOT( changeButtonStatus()));
00069     QStringList lst;
00070     lst << i18n( "Enter" );
00071     lst << i18n( "Tab" );
00072     lst << i18n( "Space" );
00073     lst << i18n( "End" );
00074     lst << i18n( "Right" );
00075     m_completionKeyAction->addItems( lst );
00076 
00077     connect( m_lbListCompletion, SIGNAL( selected ( const QString & ) ), this, SLOT( slotCompletionWordSelected( const QString & )));
00078     connect( m_lbListCompletion, SIGNAL( highlighted ( const QString & ) ), this, SLOT( slotCompletionWordSelected( const QString & )));
00079 
00080     connect( pbAddCompletionEntry, SIGNAL( clicked() ), this, SLOT( slotAddCompletionEntry()));
00081     connect( pbRemoveCompletionEntry, SIGNAL( clicked() ), this, SLOT( slotRemoveCompletionEntry()));
00082     connect( pbSaveCompletionEntry, SIGNAL( clicked() ), this, SLOT( slotSaveCompletionEntry()));
00083 
00084     slotResetConf(); // aka load config
00085     changeButtonStatus();
00086 }
00087 
00088 void KoCompletion::changeButtonStatus() {
00089     bool state = cbAllowCompletion->isChecked();
00090 
00091     completionBox->setEnabled( state);
00092     cbAddCompletionWord->setEnabled( state );
00093     pbAddCompletionEntry->setEnabled( state );
00094     m_lbListCompletion->setEnabled( state );
00095     state = state && (m_lbListCompletion->count()!=0 && !m_lbListCompletion->currentText().isEmpty());
00096     pbRemoveCompletionEntry->setEnabled( state );
00097 }
00098 
00099 void KoCompletion::slotResetConf() {
00100     cbAllowCompletion->setChecked( m_autoFormat.getConfigCompletion());
00101     cbShowToolTip->setChecked( m_autoFormat.getConfigToolTipCompletion());
00102     cbAddCompletionWord->setChecked( m_autoFormat.getConfigAddCompletionWord());
00103     m_lbListCompletion->clear();
00104     m_listCompletion = m_docAutoFormat->listCompletion();
00105     m_lbListCompletion->insertStringList( m_listCompletion );
00106     m_lbListCompletion->sort();
00107     if( m_listCompletion.isEmpty() || m_lbListCompletion->currentText().isEmpty())
00108         pbRemoveCompletionEntry->setEnabled( false );
00109     m_minWordLength->setValue ( m_docAutoFormat->getConfigMinWordLength() );
00110     m_maxNbWordCompletion->setValue ( m_docAutoFormat->getConfigNbMaxCompletionWord() );
00111     cbAppendSpace->setChecked( m_autoFormat.getConfigAppendSpace() );
00112 
00113     switch( m_docAutoFormat->getConfigKeyAction() )
00114     {
00115     case KoAutoFormat::Enter:
00116         m_completionKeyAction->setCurrentIndex( 0 );
00117         break;
00118     case KoAutoFormat::Tab:
00119         m_completionKeyAction->setCurrentIndex( 1 );
00120         break;
00121     case KoAutoFormat::Space:
00122         m_completionKeyAction->setCurrentIndex( 2 );
00123         break;
00124     case KoAutoFormat::End:
00125         m_completionKeyAction->setCurrentIndex( 3 );
00126         break;
00127     case KoAutoFormat::Right:
00128         m_completionKeyAction->setCurrentIndex( 4 );
00129         break;
00130     default:
00131         m_completionKeyAction->setCurrentIndex( 0 );
00132     }
00133     changeButtonStatus();
00134 }
00135 
00136 void KoCompletion::slotAddCompletionEntry() {
00137     bool ok;
00138     QString const newWord = KInputDialog::getText( i18n("Add Completion Entry"), i18n("Enter entry:"), QString::null, &ok, this ).toLower();
00139     if ( ok )
00140     {
00141         if ( !m_listCompletion.contains( newWord ))
00142         {
00143             m_listCompletion.append( newWord );
00144             m_lbListCompletion->insertItem( newWord );
00145             pbRemoveCompletionEntry->setEnabled( !m_lbListCompletion->currentText().isEmpty() );
00146             m_lbListCompletion->sort();
00147         }
00148 
00149     }
00150 }
00151 
00152 void KoCompletion::slotRemoveCompletionEntry() {
00153     QString text = m_lbListCompletion->currentText();
00154     if( !text.isEmpty() )
00155     {
00156         m_listCompletion.removeAll( text );
00157         m_lbListCompletion->removeItem( m_lbListCompletion->currentItem () );
00158         if( m_lbListCompletion->count()==0 )
00159             pbRemoveCompletionEntry->setEnabled( false );
00160     }
00161 }
00162 
00163 void KoCompletion::slotCompletionWordSelected( const QString & word) {
00164     pbRemoveCompletionEntry->setEnabled( !word.isEmpty() );
00165 }
00166 
00167 void KoCompletion::saveSettings() {
00168     m_docAutoFormat->configCompletion( cbAllowCompletion->isChecked());
00169     m_docAutoFormat->configToolTipCompletion( cbShowToolTip->isChecked());
00170     m_docAutoFormat->configAppendSpace( cbAppendSpace->isChecked() );
00171     m_docAutoFormat->configMinWordLength( m_minWordLength->value() );
00172     m_docAutoFormat->configNbMaxCompletionWord( m_maxNbWordCompletion->value () );
00173     m_docAutoFormat->configAddCompletionWord( cbAddCompletionWord->isChecked());
00174 
00175     m_docAutoFormat->getCompletion()->setItems( m_listCompletion );
00176     m_docAutoFormat->updateMaxWords();
00177     switch( m_completionKeyAction->currentIndex() ) {
00178         case 1:
00179             m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Tab );
00180             break;
00181         case 2:
00182             m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Space );
00183             break;
00184         case 3:
00185             m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::End );
00186             break;
00187         case 4:
00188             m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Right );
00189             break;
00190         case 0:
00191         default:
00192             m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Enter );
00193     }
00194 
00195     // Save to config file
00196     m_docAutoFormat->saveConfig();
00197 }
00198 
00199 void KoCompletion::slotSaveCompletionEntry() {
00200     KConfig config("kofficerc");
00201     KConfigGroup configGroup( &config, "Completion Word" );
00202     configGroup.writeEntry( "list", m_listCompletion );
00203     config.sync();
00204     KMessageBox::information( this, i18n(
00205             "Completion list saved.\nIt will be used for all documents "
00206             "from now on."), i18n("Completion List Saved") );
00207 }
00208 
00209 #include "KoCompletionDia.moc"

Généré le Wed Nov 22 23:41:07 2006 pour KPlato par  doxygen 1.5.1-p1