19#include "KoCompletionDia.h"
20#include "KoAutoFormat.h"
23#include <tdemessagebox.h>
24#include <kinputdialog.h>
25#include <kcompletion.h>
30#include <tqcheckbox.h>
31#include <tqpushbutton.h>
33#include <tqcombobox.h>
34#include <tqgroupbox.h>
35#include <tqwhatsthis.h>
37KoCompletionDia::KoCompletionDia( TQWidget *parent,
const char *name, KoAutoFormat * autoFormat )
38 :
KDialogBase( parent,
name , true, i18n(
"Completion" ), Ok|Cancel|User1,
39 Ok, true,
KGuiItem( i18n(
"&Reset" ),
"edit-undo" ) )
41 TQVBox *page = makeVBoxMainWidget();
43 m_widget->layout()->setMargin(0);
44 connect(
this, TQ_SIGNAL( user1Clicked() ), m_widget, TQ_SLOT(slotResetConf()));
45 setButtonWhatsThis(Ok,i18n(
"This will save your options."));
46 setButtonWhatsThis(Cancel,i18n(
"This will abort all changes."));
47 setButtonWhatsThis(User1,i18n(
"This will reset to the state after you clicked on the Make Default button."));
50void KoCompletionDia::slotOk()
52 m_widget->saveSettings();
56KoCompletion::KoCompletion(TQWidget *parent, KoAutoFormat *autoFormat) : KoCompletionBase(parent),
57 m_autoFormat( *autoFormat ),
58 m_docAutoFormat( autoFormat )
60 connect(cbAllowCompletion, TQ_SIGNAL(toggled (
bool )),
this, TQ_SLOT( changeButtonStatus()));
62 lst << i18n(
"Enter" );
64 lst << i18n(
"Space" );
66 lst << i18n(
"Right" );
67 m_completionKeyAction->insertStringList( lst );
69 connect( m_lbListCompletion, TQ_SIGNAL( selected (
const TQString & ) ),
this, TQ_SLOT( slotCompletionWordSelected(
const TQString & )));
70 connect( m_lbListCompletion, TQ_SIGNAL( highlighted (
const TQString & ) ),
this, TQ_SLOT( slotCompletionWordSelected(
const TQString & )));
72 connect( pbAddCompletionEntry, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotAddCompletionEntry()));
73 connect( pbRemoveCompletionEntry, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotRemoveCompletionEntry()));
74 connect( pbSaveCompletionEntry, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( slotSaveCompletionEntry()));
80void KoCompletion::changeButtonStatus() {
81 bool state = cbAllowCompletion->isChecked();
83 completionBox->setEnabled( state);
84 cbAddCompletionWord->setEnabled( state );
85 pbAddCompletionEntry->setEnabled( state );
86 m_lbListCompletion->setEnabled( state );
87 state = state && (m_lbListCompletion->count()!=0 && !m_lbListCompletion->currentText().isEmpty());
88 pbRemoveCompletionEntry->setEnabled( state );
91void KoCompletion::slotResetConf() {
92 cbAllowCompletion->setChecked( m_autoFormat.getConfigCompletion());
93 cbShowToolTip->setChecked( m_autoFormat.getConfigToolTipCompletion());
94 cbAddCompletionWord->setChecked( m_autoFormat.getConfigAddCompletionWord());
95 m_lbListCompletion->clear();
96 m_listCompletion = m_docAutoFormat->listCompletion();
97 m_lbListCompletion->insertStringList( m_listCompletion );
98 m_lbListCompletion->sort();
99 if( m_listCompletion.isEmpty() || m_lbListCompletion->currentText().isEmpty())
100 pbRemoveCompletionEntry->setEnabled(
false );
101 m_minWordLength->setValue ( m_docAutoFormat->getConfigMinWordLength() );
102 m_maxNbWordCompletion->setValue ( m_docAutoFormat->getConfigNbMaxCompletionWord() );
103 cbAppendSpace->setChecked( m_autoFormat.getConfigAppendSpace() );
105 switch( m_docAutoFormat->getConfigKeyAction() )
107 case KoAutoFormat::Enter:
108 m_completionKeyAction->setCurrentItem( 0 );
110 case KoAutoFormat::Tab:
111 m_completionKeyAction->setCurrentItem( 1 );
113 case KoAutoFormat::Space:
114 m_completionKeyAction->setCurrentItem( 2 );
116 case KoAutoFormat::End:
117 m_completionKeyAction->setCurrentItem( 3 );
119 case KoAutoFormat::Right:
120 m_completionKeyAction->setCurrentItem( 4 );
123 m_completionKeyAction->setCurrentItem( 0 );
125 changeButtonStatus();
128void KoCompletion::slotAddCompletionEntry() {
130 TQString
const newWord =
KInputDialog::getText( i18n(
"Add Completion Entry"), i18n(
"Enter entry:"), TQString(), &ok,
this ).lower();
133 if ( !m_listCompletion.contains( newWord ))
135 m_listCompletion.append( newWord );
136 m_lbListCompletion->insertItem( newWord );
137 pbRemoveCompletionEntry->setEnabled( !m_lbListCompletion->currentText().isEmpty() );
138 m_lbListCompletion->sort();
144void KoCompletion::slotRemoveCompletionEntry() {
145 TQString text = m_lbListCompletion->currentText();
146 if( !text.isEmpty() )
148 m_listCompletion.remove( text );
149 m_lbListCompletion->removeItem( m_lbListCompletion->currentItem () );
150 if( m_lbListCompletion->count()==0 )
151 pbRemoveCompletionEntry->setEnabled(
false );
155void KoCompletion::slotCompletionWordSelected(
const TQString & word) {
156 pbRemoveCompletionEntry->setEnabled( !word.isEmpty() );
159void KoCompletion::saveSettings() {
160 m_docAutoFormat->configCompletion( cbAllowCompletion->isChecked());
161 m_docAutoFormat->configToolTipCompletion( cbShowToolTip->isChecked());
162 m_docAutoFormat->configAppendSpace( cbAppendSpace->isChecked() );
163 m_docAutoFormat->configMinWordLength( m_minWordLength->value() );
164 m_docAutoFormat->configNbMaxCompletionWord( m_maxNbWordCompletion->value () );
165 m_docAutoFormat->configAddCompletionWord( cbAddCompletionWord->isChecked());
167 m_docAutoFormat->getCompletion()->setItems( m_listCompletion );
168 m_docAutoFormat->updateMaxWords();
169 switch( m_completionKeyAction->currentItem() ) {
171 m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Tab );
174 m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Space );
177 m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::End );
180 m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Right );
184 m_docAutoFormat->configKeyCompletionAction( KoAutoFormat::Enter );
188 m_docAutoFormat->saveConfig();
191void KoCompletion::slotSaveCompletionEntry() {
192 TDEConfig config(
"kofficerc");
193 TDEConfigGroupSaver cgs( &config,
"Completion Word" );
194 config.writeEntry(
"list", m_listCompletion );
197 "Completion list saved.\nIt will be used for all documents "
198 "from now on."), i18n(
"Completion List Saved") );
201#include "KoCompletionDia.moc"
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
Completion configuration widget.
const char * name(StdAction id)