configwidget.cpp00001
00021 #include "configwidget.h"
00022 #include "configui.h"
00023
00024 #include "broker.h"
00025 #include "settings.h"
00026
00027 #include <keditlistbox.h>
00028 #include <kcombobox.h>
00029 #include <klocale.h>
00030
00031 #include <qcheckbox.h>
00032 #include <qlayout.h>
00033
00034 using namespace KSpell2;
00035
00036 class ConfigWidget::Private
00037 {
00038 public:
00039 Broker::Ptr broker;
00040 KSpell2ConfigUI *ui;
00041 };
00042
00043 ConfigWidget::ConfigWidget( Broker *broker, QWidget *parent, const char *name )
00044 : QWidget( parent, name )
00045 {
00046 init( broker );
00047 }
00048
00049 ConfigWidget::~ConfigWidget()
00050 {
00051 delete d; d = 0;
00052 }
00053
00054 void ConfigWidget::init( Broker *broker )
00055 {
00056 d = new Private;
00057 d->broker = broker;
00058
00059 QVBoxLayout *layout = new QVBoxLayout( this, 0, 0, "KSpell2ConfigUILayout");
00060 d->ui = new KSpell2ConfigUI( this );
00061
00062 QStringList langs = d->broker->languages();
00063
00064 d->ui->m_langCombo->insertStringList( langs );
00065 setCorrectLanguage( langs );
00066
00067 d->ui->m_skipUpperCB->setChecked( !d->broker->settings()->checkUppercase() );
00068 d->ui->m_skipRunTogetherCB->setChecked( d->broker->settings()->skipRunTogether() );
00069 QStringList ignoreList = d->broker->settings()->currentIgnoreList();
00070 ignoreList.sort();
00071 d->ui->m_ignoreListBox->insertStringList( ignoreList );
00072 d->ui->m_bgSpellCB->setChecked( d->broker->settings()->backgroundCheckerEnabled() );
00073 d->ui->m_bgSpellCB->hide();
00074 connect( d->ui->m_ignoreListBox, SIGNAL(changed()), SLOT(slotChanged()) );
00075
00076 layout->addWidget( d->ui );
00077 }
00078
00079 void KSpell2::ConfigWidget::save()
00080 {
00081 setFromGUI();
00082 d->broker->settings()->save();
00083 }
00084
00085 void ConfigWidget::setFromGUI()
00086 {
00087 d->broker->settings()->setDefaultLanguage(
00088 d->ui->m_langCombo->currentText() );
00089 d->broker->settings()->setCheckUppercase(
00090 !d->ui->m_skipUpperCB->isChecked() );
00091 d->broker->settings()->setSkipRunTogether(
00092 d->ui->m_skipRunTogetherCB->isChecked() );
00093 d->broker->settings()->setBackgroundCheckerEnabled(
00094 d->ui->m_bgSpellCB->isChecked() );
00095 }
00096
00097 void ConfigWidget::slotChanged()
00098 {
00099 d->broker->settings()->setCurrentIgnoreList(
00100 d->ui->m_ignoreListBox->items() );
00101 }
00102
00103 void ConfigWidget::setCorrectLanguage( const QStringList& langs)
00104 {
00105 int idx = 0;
00106 for ( QStringList::const_iterator itr = langs.begin();
00107 itr != langs.end(); ++itr, ++idx ) {
00108 if ( *itr == d->broker->settings()->defaultLanguage() )
00109 d->ui->m_langCombo->setCurrentItem( idx );
00110 }
00111 }
00112
00113 void ConfigWidget::setBackgroundCheckingButtonShown( bool b )
00114 {
00115 d->ui->m_bgSpellCB->setShown( b );
00116 }
00117
00118 bool ConfigWidget::backgroundCheckingButtonShown() const
00119 {
00120 return d->ui->m_bgSpellCB->isShown();
00121 }
00122
00123 void ConfigWidget::slotDefault()
00124 {
00125 d->ui->m_skipUpperCB->setChecked( false );
00126 d->ui->m_skipRunTogetherCB->setChecked( false );
00127 d->ui->m_bgSpellCB->setChecked( true );
00128 d->ui->m_ignoreListBox->clear();
00129 }
00130
00131 #include "configwidget.moc"
|