KDEUI
configwidget.cpp
Go to the documentation of this file.00001
00021 #include "configwidget.h"
00022 #include "ui_configui.h"
00023
00024 #include "loader_p.h"
00025 #include "settings_p.h"
00026
00027 #include <keditlistbox.h>
00028 #include <kcombobox.h>
00029 #include <kconfig.h>
00030 #include <klocale.h>
00031
00032 #include <QtGui/QCheckBox>
00033 #include <QtGui/QLayout>
00034
00035 using namespace Sonnet;
00036
00037 class ConfigWidget::Private
00038 {
00039 public:
00040 Loader *loader;
00041 Ui_SonnetConfigUI ui;
00042 QWidget *wdg;
00043 KConfig *config;
00044 void selectLanguage( const QStringList& langs, const QString &language );
00045 };
00046
00047 void ConfigWidget::Private::selectLanguage( const QStringList& langs,
00048 const QString &language )
00049 {
00050 int idx = 0;
00051 for ( QStringList::const_iterator itr = langs.begin();
00052 itr != langs.end(); ++itr, ++idx ) {
00053 if ( *itr == language )
00054 ui.m_langCombo->setCurrentIndex( idx );
00055 }
00056 }
00057
00058 ConfigWidget::ConfigWidget(KConfig *config, QWidget *parent)
00059 : QWidget(parent),
00060 d(new Private)
00061 {
00062 init(config);
00063 }
00064
00065 ConfigWidget::~ConfigWidget()
00066 {
00067 delete d;
00068 }
00069
00070 void ConfigWidget::init(KConfig *config)
00071 {
00072 d->loader = Loader::openLoader();
00073 d->loader->settings()->restore(config);
00074 d->config = config;
00075
00076 QVBoxLayout *layout = new QVBoxLayout( this );
00077 layout->setMargin( 0 );
00078 layout->setSpacing( 0 );
00079 layout->setObjectName( "SonnetConfigUILayout" );
00080 d->wdg = new QWidget( this );
00081 d->ui.setupUi( d->wdg );
00082
00083
00084 d->ui.m_langCombo->insertItems( 0, d->loader->languageNames() );
00085 setCorrectLanguage( d->loader->languages() );
00086
00087 d->ui.m_skipUpperCB->setChecked( !d->loader->settings()->checkUppercase() );
00088 d->ui.m_skipRunTogetherCB->setChecked( d->loader->settings()->skipRunTogether() );
00089 QStringList ignoreList = d->loader->settings()->currentIgnoreList();
00090 ignoreList.sort();
00091 d->ui.m_ignoreListBox->insertStringList( ignoreList );
00092 d->ui.m_bgSpellCB->setChecked( d->loader->settings()->backgroundCheckerEnabled() );
00093 d->ui.m_bgSpellCB->hide();
00094 connect( d->ui.m_ignoreListBox, SIGNAL(changed()), SLOT(slotChanged()) );
00095
00096 layout->addWidget( d->wdg );
00097 connect(d->ui.m_langCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(configChanged()));
00098 connect(d->ui.m_bgSpellCB, SIGNAL(clicked(bool)),this,SIGNAL(configChanged()));
00099 connect(d->ui.m_skipUpperCB, SIGNAL(clicked(bool)), this, SIGNAL(configChanged()));
00100 connect(d->ui.m_skipRunTogetherCB, SIGNAL(clicked(bool)), this, SIGNAL(configChanged()));
00101 connect(d->ui.m_ignoreListBox, SIGNAL(changed()), this, SIGNAL(configChanged()));
00102 }
00103
00104 void ConfigWidget::save()
00105 {
00106 setFromGui();
00107 d->loader->settings()->save(d->config);
00108 }
00109
00110 void ConfigWidget::setFromGui()
00111 {
00112 if (d->ui.m_langCombo->count() ) {
00113 d->loader->settings()->setDefaultLanguage(
00114 d->loader->languages()[
00115 d->loader->languageNames().indexOf(
00116 d->ui.m_langCombo->currentText() ) ] );
00117 }
00118 d->loader->settings()->setCheckUppercase(
00119 !d->ui.m_skipUpperCB->isChecked() );
00120 d->loader->settings()->setSkipRunTogether(
00121 d->ui.m_skipRunTogetherCB->isChecked() );
00122 d->loader->settings()->setBackgroundCheckerEnabled(
00123 d->ui.m_bgSpellCB->isChecked() );
00124 }
00125
00126 void ConfigWidget::slotChanged()
00127 {
00128 d->loader->settings()->setCurrentIgnoreList(
00129 d->ui.m_ignoreListBox->items() );
00130 }
00131
00132 void ConfigWidget::setCorrectLanguage( const QStringList& langs)
00133 {
00134 d->selectLanguage( langs, d->loader->settings()->defaultLanguage() );
00135 }
00136
00137 void ConfigWidget::setBackgroundCheckingButtonShown( bool b )
00138 {
00139 d->ui.m_bgSpellCB->setVisible( b );
00140 }
00141
00142 bool ConfigWidget::backgroundCheckingButtonShown() const
00143 {
00144 return !d->ui.m_bgSpellCB->isHidden();
00145 }
00146
00147 void ConfigWidget::slotDefault()
00148 {
00149 d->ui.m_skipUpperCB->setChecked( false );
00150 d->ui.m_skipRunTogetherCB->setChecked( false );
00151 d->ui.m_bgSpellCB->setChecked( true );
00152 d->ui.m_ignoreListBox->clear();
00153 }
00154
00155 void ConfigWidget::setLanguage( const QString &language )
00156 {
00157 d->selectLanguage( d->loader->languages(), language );
00158 }
00159
00160 QString ConfigWidget::language() const
00161 {
00162 if ( d->ui.m_langCombo->count() ) {
00163 return d->loader->languages()[ d->loader->languageNames().indexOf(
00164 d->ui.m_langCombo->currentText() ) ];
00165 } else {
00166 return QString();
00167 }
00168 }
00169
00170 #include "configwidget.moc"