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 d->ui.m_checkerEnabledByDefaultCB->setChecked( d->loader->settings()->checkerEnabledByDefault() );
00076 QStringList ignoreList = d->loader->settings()->currentIgnoreList();
00077 ignoreList.sort();
00078 d->ui.m_ignoreListBox->insertStringList( ignoreList );
00079 d->ui.m_bgSpellCB->setChecked( d->loader->settings()->backgroundCheckerEnabled() );
00080 d->ui.m_bgSpellCB->hide();
00081 connect( d->ui.m_ignoreListBox, SIGNAL(changed()), SLOT(slotChanged()) );
00082
00083 layout->addWidget( d->wdg );
00084 connect(d->ui.m_langCombo, SIGNAL(dictionaryChanged(QString)), this, SIGNAL(configChanged()));
00085 connect(d->ui.m_bgSpellCB, SIGNAL(clicked(bool)),this,SIGNAL(configChanged()));
00086 connect(d->ui.m_skipUpperCB, SIGNAL(clicked(bool)), this, SIGNAL(configChanged()));
00087 connect(d->ui.m_skipRunTogetherCB, SIGNAL(clicked(bool)), this, SIGNAL(configChanged()));
00088 connect(d->ui.m_checkerEnabledByDefaultCB, SIGNAL(clicked(bool)), this, SIGNAL(configChanged()));
00089 connect(d->ui.m_ignoreListBox, SIGNAL(changed()), this, SIGNAL(configChanged()));
00090 }
00091
00092 void ConfigWidget::save()
00093 {
00094 setFromGui();
00095 d->loader->settings()->save(d->config);
00096 }
00097
00098 void ConfigWidget::setFromGui()
00099 {
00100 if (d->ui.m_langCombo->count() ) {
00101 d->loader->settings()->setDefaultLanguage( d->ui.m_langCombo->currentDictionary() );
00102 }
00103 d->loader->settings()->setCheckUppercase(
00104 !d->ui.m_skipUpperCB->isChecked() );
00105 d->loader->settings()->setSkipRunTogether(
00106 d->ui.m_skipRunTogetherCB->isChecked() );
00107 d->loader->settings()->setBackgroundCheckerEnabled(
00108 d->ui.m_bgSpellCB->isChecked() );
00109 d->loader->settings()->setCheckerEnabledByDefault(
00110 d->ui.m_checkerEnabledByDefaultCB->isChecked() );
00111 }
00112
00113 void ConfigWidget::slotChanged()
00114 {
00115 d->loader->settings()->setCurrentIgnoreList(
00116 d->ui.m_ignoreListBox->items() );
00117 }
00118
00119 void ConfigWidget::setCorrectLanguage( const QStringList& )
00120 {
00121
00122 }
00123
00124 void ConfigWidget::setBackgroundCheckingButtonShown( bool b )
00125 {
00126 d->ui.m_bgSpellCB->setVisible( b );
00127 }
00128
00129 bool ConfigWidget::backgroundCheckingButtonShown() const
00130 {
00131 return !d->ui.m_bgSpellCB->isHidden();
00132 }
00133
00134 void ConfigWidget::slotDefault()
00135 {
00136 d->ui.m_skipUpperCB->setChecked( false );
00137 d->ui.m_skipRunTogetherCB->setChecked( false );
00138 d->ui.m_checkerEnabledByDefaultCB->setChecked( false );
00139 d->ui.m_bgSpellCB->setChecked( true );
00140 d->ui.m_ignoreListBox->clear();
00141 }
00142
00143 void ConfigWidget::setLanguage( const QString &language )
00144 {
00145 d->ui.m_langCombo->setCurrentByDictionary( language );
00146 }
00147
00148 QString ConfigWidget::language() const
00149 {
00150 if ( d->ui.m_langCombo->count() ) {
00151 return d->ui.m_langCombo->currentDictionary();
00152 } else {
00153 return QString();
00154 }
00155 }
00156
00157 #include "configwidget.moc"