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->setSpacing( 0 );
00067 layout->setObjectName( "SonnetConfigUILayout" );
00068 d->wdg = new QWidget( this );
00069 d->ui.setupUi( d->wdg );
00070
00071
00072 d->ui.m_langCombo->setCurrentByDictionary( d->loader->settings()->defaultLanguage() );
00073
00074 d->ui.m_skipUpperCB->setChecked( !d->loader->settings()->checkUppercase() );
00075 d->ui.m_skipRunTogetherCB->setChecked( d->loader->settings()->skipRunTogether() );
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_ignoreListBox, SIGNAL(changed()), this, SIGNAL(configChanged()));
00089 }
00090
00091 void ConfigWidget::save()
00092 {
00093 setFromGui();
00094 d->loader->settings()->save(d->config);
00095 }
00096
00097 void ConfigWidget::setFromGui()
00098 {
00099 if (d->ui.m_langCombo->count() ) {
00100 d->loader->settings()->setDefaultLanguage( d->ui.m_langCombo->currentDictionary() );
00101 }
00102 d->loader->settings()->setCheckUppercase(
00103 !d->ui.m_skipUpperCB->isChecked() );
00104 d->loader->settings()->setSkipRunTogether(
00105 d->ui.m_skipRunTogetherCB->isChecked() );
00106 d->loader->settings()->setBackgroundCheckerEnabled(
00107 d->ui.m_bgSpellCB->isChecked() );
00108 }
00109
00110 void ConfigWidget::slotChanged()
00111 {
00112 d->loader->settings()->setCurrentIgnoreList(
00113 d->ui.m_ignoreListBox->items() );
00114 }
00115
00116 void ConfigWidget::setCorrectLanguage( const QStringList& )
00117 {
00118
00119 }
00120
00121 void ConfigWidget::setBackgroundCheckingButtonShown( bool b )
00122 {
00123 d->ui.m_bgSpellCB->setVisible( b );
00124 }
00125
00126 bool ConfigWidget::backgroundCheckingButtonShown() const
00127 {
00128 return !d->ui.m_bgSpellCB->isHidden();
00129 }
00130
00131 void ConfigWidget::slotDefault()
00132 {
00133 d->ui.m_skipUpperCB->setChecked( false );
00134 d->ui.m_skipRunTogetherCB->setChecked( false );
00135 d->ui.m_bgSpellCB->setChecked( true );
00136 d->ui.m_ignoreListBox->clear();
00137 }
00138
00139 void ConfigWidget::setLanguage( const QString &language )
00140 {
00141 d->ui.m_langCombo->setCurrentByDictionary( language );
00142 }
00143
00144 QString ConfigWidget::language() const
00145 {
00146 if ( d->ui.m_langCombo->count() ) {
00147 return d->ui.m_langCombo->currentDictionary();
00148 } else {
00149 return QString();
00150 }
00151 }
00152
00153 #include "configwidget.moc"