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 };
00045
00046 ConfigWidget::ConfigWidget(KConfig *config, QWidget *parent)
00047 : QWidget(parent),
00048 d(new Private)
00049 {
00050 init(config);
00051 }
00052
00053 ConfigWidget::~ConfigWidget()
00054 {
00055 delete d;
00056 }
00057
00058 void ConfigWidget::init(KConfig *config)
00059 {
00060 d->loader = Loader::openLoader();
00061 d->loader->settings()->restore(config);
00062 d->config = config;
00063
00064 QVBoxLayout *layout = new QVBoxLayout( this );
00065 layout->setMargin( 0 );
00066 layout->setObjectName( "SonnetConfigUILayout" );
00067 d->wdg = new QWidget( this );
00068 d->ui.setupUi( d->wdg );
00069
00070
00071 d->ui.m_langCombo->setCurrentByDictionary( d->loader->settings()->defaultLanguage() );
00072
00073 d->ui.m_skipUpperCB->setChecked( !d->loader->settings()->checkUppercase() );
00074 d->ui.m_skipRunTogetherCB->setChecked( d->loader->settings()->skipRunTogether() );
00075 QStringList ignoreList = d->loader->settings()->currentIgnoreList();
00076 ignoreList.sort();
00077 d->ui.m_ignoreListBox->insertStringList( ignoreList );
00078 d->ui.m_bgSpellCB->setChecked( d->loader->settings()->backgroundCheckerEnabled() );
00079 d->ui.m_bgSpellCB->hide();
00080 connect( d->ui.m_ignoreListBox, SIGNAL(changed()), SLOT(slotChanged()) );
00081
00082 layout->addWidget( d->wdg );
00083 connect(d->ui.m_langCombo, SIGNAL(dictionaryChanged(QString)), this, SIGNAL(configChanged()));
00084 connect(d->ui.m_bgSpellCB, SIGNAL(clicked(bool)),this,SIGNAL(configChanged()));
00085 connect(d->ui.m_skipUpperCB, SIGNAL(clicked(bool)), this, SIGNAL(configChanged()));
00086 connect(d->ui.m_skipRunTogetherCB, SIGNAL(clicked(bool)), this, SIGNAL(configChanged()));
00087 connect(d->ui.m_ignoreListBox, SIGNAL(changed()), this, SIGNAL(configChanged()));
00088 }
00089
00090 void ConfigWidget::save()
00091 {
00092 setFromGui();
00093 d->loader->settings()->save(d->config);
00094 }
00095
00096 void ConfigWidget::setFromGui()
00097 {
00098 if (d->ui.m_langCombo->count() ) {
00099 d->loader->settings()->setDefaultLanguage( d->ui.m_langCombo->currentDictionary() );
00100 }
00101 d->loader->settings()->setCheckUppercase(
00102 !d->ui.m_skipUpperCB->isChecked() );
00103 d->loader->settings()->setSkipRunTogether(
00104 d->ui.m_skipRunTogetherCB->isChecked() );
00105 d->loader->settings()->setBackgroundCheckerEnabled(
00106 d->ui.m_bgSpellCB->isChecked() );
00107 }
00108
00109 void ConfigWidget::slotChanged()
00110 {
00111 d->loader->settings()->setCurrentIgnoreList(
00112 d->ui.m_ignoreListBox->items() );
00113 }
00114
00115 void ConfigWidget::setCorrectLanguage( const QStringList& )
00116 {
00117
00118 }
00119
00120 void ConfigWidget::setBackgroundCheckingButtonShown( bool b )
00121 {
00122 d->ui.m_bgSpellCB->setVisible( b );
00123 }
00124
00125 bool ConfigWidget::backgroundCheckingButtonShown() const
00126 {
00127 return !d->ui.m_bgSpellCB->isHidden();
00128 }
00129
00130 void ConfigWidget::slotDefault()
00131 {
00132 d->ui.m_skipUpperCB->setChecked( false );
00133 d->ui.m_skipRunTogetherCB->setChecked( false );
00134 d->ui.m_bgSpellCB->setChecked( true );
00135 d->ui.m_ignoreListBox->clear();
00136 }
00137
00138 void ConfigWidget::setLanguage( const QString &language )
00139 {
00140 d->ui.m_langCombo->setCurrentByDictionary( language );
00141 }
00142
00143 QString ConfigWidget::language() const
00144 {
00145 if ( d->ui.m_langCombo->count() ) {
00146 return d->ui.m_langCombo->currentDictionary();
00147 } else {
00148 return QString();
00149 }
00150 }
00151
00152 #include "configwidget.moc"