src/hbinput/inputwidgets/hbinputsettingwidget.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    20 **
    20 **
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
       
    25 #include "hbinputsettingwidget.h"
    25 
    26 
    26 #include <hbdataform.h>
    27 #include <hbdataform.h>
    27 #include <hbdataformmodel.h>
    28 #include <hbdataformmodel.h>
    28 #include <hbinpututils.h>
    29 #include <hbinpututils.h>
    29 #include <hbinputsettingproxy.h>
    30 #include <hbinputsettingproxy.h>
    30 #include <hbinputpredictionfactory.h>
    31 #include <hbinputpredictionfactory.h>
    31 #include <QtAlgorithms>
    32 #include <QtAlgorithms>
    32 
    33 
    33 #include "hbinputsettingwidget.h"
       
    34 #include "hbinputcheckboxlist_p.h"
    34 #include "hbinputcheckboxlist_p.h"
    35 
    35 
    36 const QString statusOff = QObject::tr("Off");
    36 const QString statusOff = QObject::tr("Off");
    37 const QString statusOn = QObject::tr("On");
    37 const QString statusOn = QObject::tr("On");
    38 const QString bestPrediction = QObject::tr("Best prediction");
    38 const QString bestPrediction = QObject::tr("Best prediction");
    52     void createSettingItems();
    52     void createSettingItems();
    53     void fillLanguageList(QStringList &list, QList<HbInputLanguage> &languageList, const QString &replace = QString(" "));
    53     void fillLanguageList(QStringList &list, QList<HbInputLanguage> &languageList, const QString &replace = QString(" "));
    54     int languageToIndex(const HbInputLanguage &language, const QList<HbInputLanguage> &languageList);
    54     int languageToIndex(const HbInputLanguage &language, const QList<HbInputLanguage> &languageList);
    55     HbInputLanguage indexToLanguage(int index, const QList<HbInputLanguage> &languageList);
    55     HbInputLanguage indexToLanguage(int index, const QList<HbInputLanguage> &languageList);
    56     void createSecondaryLanguageList();
    56     void createSecondaryLanguageList();
    57 
    57     void updateContentWidgetData();
    58 public:
    58 public:
    59     HbDataForm *mForm;
    59     HbDataForm *mForm;
    60     HbDataFormModelItem *mPrimaryLanguageItem;
    60     HbDataFormModelItem *mPrimaryLanguageItem;
    61     HbDataFormModelItem *mSecondaryLanguageItem;
    61     HbDataFormModelItem *mSecondaryLanguageItem;
    62     HbDataFormModelItem *mKeypressTimeoutItem;
    62     HbDataFormModelItem *mKeypressTimeoutItem;
    76     bool mAutocompletionForITUT;
    76     bool mAutocompletionForITUT;
    77     bool mAutocompletionForQwerty;
    77     bool mAutocompletionForQwerty;
    78     HbTypingCorrectionLevel mTypingCorrectionLevel;
    78     HbTypingCorrectionLevel mTypingCorrectionLevel;
    79     HbPrimaryCandidateMode mPrimaryCandidateMode;
    79     HbPrimaryCandidateMode mPrimaryCandidateMode;
    80     HbInputSettingWidget *q_ptr;
    80     HbInputSettingWidget *q_ptr;
       
    81     HbDataFormModel *mModel;
    81 };
    82 };
    82 
    83 
    83 /*!
    84 /*!
    84 Constructs setting widget
    85 Constructs setting widget
    85 */
    86 */
    86 HbInputSettingWidgetPrivate::HbInputSettingWidgetPrivate(HbDataForm *dataForm)
    87 HbInputSettingWidgetPrivate::HbInputSettingWidgetPrivate(HbDataForm *dataForm)
    87  : mForm(dataForm), mPrimaryLanguageItem(NULL),
    88  : mForm(dataForm), mPrimaryLanguageItem(NULL),
    88    mSecondaryLanguageItem(NULL), mKeypressTimeoutItem(NULL),
    89    mSecondaryLanguageItem(NULL), mKeypressTimeoutItem(NULL),
    89    mCharacterPreviewItem(NULL), mPredictionItem(NULL),
    90    mCharacterPreviewItem(NULL), mPredictionItem(NULL),
    90    mAutoCompletionItem(NULL), mCorrectionLevelItem(NULL),
    91    mAutoCompletionItem(NULL), mCorrectionLevelItem(NULL),
    91    mPrimaryCandidateItem(NULL), q_ptr(NULL)
    92    mPrimaryCandidateItem(NULL), q_ptr(NULL), mModel(0)
    92 {
    93 {
    93 }
    94 }
    94 
    95 
    95 /*!
    96 /*!
    96 Initializes setting widget
    97 Initializes setting widget
   109     mPrimaryCandidateMode = settings->primaryCandidateMode();
   110     mPrimaryCandidateMode = settings->primaryCandidateMode();
   110     mTypingCorrectionLevel = settings->typingCorrectionLevel();
   111     mTypingCorrectionLevel = settings->typingCorrectionLevel();
   111 
   112 
   112     HbInputUtils::listSupportedInputLanguages(mPrimaryLanguages);
   113     HbInputUtils::listSupportedInputLanguages(mPrimaryLanguages);
   113     createSecondaryLanguageList();
   114     createSecondaryLanguageList();
   114 
   115     // if the model is already constructed we do not need to recreate the setting items
   115     createSettingItems();
   116     if (!mModel) {
       
   117         createSettingItems();
       
   118     } else {
       
   119         // simply update the settings dependant content widget data of all the items
       
   120         updateContentWidgetData();
       
   121         //make sure that the items are not expanded
       
   122         QModelIndex index = mModel->indexFromItem(mSecondaryLanguageItem->parent());
       
   123         mForm->setExpanded(index, false);
       
   124         index = mModel->indexFromItem(mKeypressTimeoutItem->parent());
       
   125         mForm->setExpanded(index, false);
       
   126         index = mModel->indexFromItem(mPredictionItem->parent());
       
   127         mForm->setExpanded(index, false);        
       
   128     }
       
   129 }
       
   130 
       
   131 void HbInputSettingWidgetPrivate::updateContentWidgetData() 
       
   132 {
       
   133     // current primary language
       
   134     mPrimaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mPrimaryInputLanguage, mPrimaryLanguages));
       
   135 
       
   136     mSecondaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mSecondaryInputLanguage, mSecondaryLanguages));
       
   137     // key press timeout
       
   138     mKeypressTimeoutItem->setContentWidgetData(QString("sliderPosition"), mKeypressTimeout);
       
   139     if (mCharacterPreviewEnabled) {
       
   140         mCharacterPreviewItem->setContentWidgetData(QString("text"), statusOn);
       
   141         mCharacterPreviewItem->setContentWidgetData(QString("additionalText"), statusOff);
       
   142     } else {
       
   143         mCharacterPreviewItem->setContentWidgetData(QString("text"), statusOff);
       
   144         mCharacterPreviewItem->setContentWidgetData(QString("additionalText"), statusOn);
       
   145     }
       
   146     QList<QVariant> predictionEnabled;
       
   147     predictionEnabled << mPredictionStatusForQwerty << mPredictionStatusForITUT;
       
   148     mPredictionItem->setContentWidgetData(QString("selectedItems"), predictionEnabled);
       
   149 
       
   150     QList<QVariant> autocompletionEnabled;
       
   151     autocompletionEnabled << mAutocompletionForQwerty << mAutocompletionForITUT;
       
   152     mAutoCompletionItem->setContentWidgetData(QString("selectedItems"), autocompletionEnabled);
       
   153     
       
   154     mCorrectionLevelItem->setContentWidgetData(QString("selected"), mTypingCorrectionLevel);
       
   155 
       
   156     if (mPrimaryCandidateMode == HbPrimaryCandidateModeBestPrediction) {
       
   157         mPrimaryCandidateItem->setContentWidgetData(QString("text"), bestPrediction);
       
   158         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), exactTyping);
       
   159     } else {
       
   160         mPrimaryCandidateItem->setContentWidgetData(QString("text"), exactTyping);
       
   161         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), bestPrediction);
       
   162     }
   116 }
   163 }
   117 
   164 
   118 /*!
   165 /*!
   119 Creates setting items to this widget
   166 Creates setting items to this widget
   120 */
   167 */
   121 void HbInputSettingWidgetPrivate::createSettingItems()
   168 void HbInputSettingWidgetPrivate::createSettingItems()
   122 {
   169 {
   123     Q_Q(HbInputSettingWidget);
   170     Q_Q(HbInputSettingWidget);
   124 
   171 
   125     HbDataFormModel *model = new HbDataFormModel();
   172     mModel = new HbDataFormModel();
   126 
   173 
   127     HbInputCheckBoxList *customPrototype = new HbInputCheckBoxList(mForm);
   174     HbInputCheckBoxList *customPrototype = new HbInputCheckBoxList(mForm);
   128     QList<HbAbstractViewItem*> prototypes = mForm->itemPrototypes();
   175     QList<HbAbstractViewItem*> prototypes = mForm->itemPrototypes();
   129     prototypes.append(customPrototype);
   176     prototypes.append(customPrototype);
   130     mForm->setItemPrototypes(prototypes);
   177     mForm->setItemPrototypes(prototypes);
   131 
   178 
   132     HbDataFormModelItem *languageGroup = model->appendDataFormGroup(QObject::tr("Language"));
   179     HbDataFormModelItem *languageGroup = mModel->appendDataFormGroup(QObject::tr("Language"));
   133 
   180 
   134     mPrimaryLanguageItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Primary Writing language"));
   181     mPrimaryLanguageItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, QObject::tr("Primary Writing language"));
   135     languageGroup->appendChild(mPrimaryLanguageItem);
   182     languageGroup->appendChild(mPrimaryLanguageItem);
   136     QStringList writingLanguageItems;
   183     QStringList writingLanguageItems;
   137     fillLanguageList(writingLanguageItems, mPrimaryLanguages);
   184     fillLanguageList(writingLanguageItems, mPrimaryLanguages);
   147     mSecondaryLanguageItem->setContentWidgetData(QString("items"), secondaryLanguageItems);
   194     mSecondaryLanguageItem->setContentWidgetData(QString("items"), secondaryLanguageItems);
   148     mSecondaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mSecondaryInputLanguage, mSecondaryLanguages));
   195     mSecondaryLanguageItem->setContentWidgetData(QString("currentIndex"), languageToIndex(mSecondaryInputLanguage, mSecondaryLanguages));
   149     mSecondaryLanguageItem->setContentWidgetData(QString("objectName"), QString("secondary_writing_language"));
   196     mSecondaryLanguageItem->setContentWidgetData(QString("objectName"), QString("secondary_writing_language"));
   150     mForm->addConnection(mSecondaryLanguageItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setSecondaryLanguage(int)));
   197     mForm->addConnection(mSecondaryLanguageItem, SIGNAL(currentIndexChanged(int)), q, SLOT(setSecondaryLanguage(int)));
   151 
   198 
   152     HbDataFormModelItem *keyboardGroup = model->appendDataFormGroup(QObject::tr("Keyboard"));
   199     HbDataFormModelItem *keyboardGroup = mModel->appendDataFormGroup(QObject::tr("Keyboard"));
   153 
   200 
   154     mKeypressTimeoutItem = new HbDataFormModelItem(HbDataFormModelItem::SliderItem, QObject::tr("Keypress Timeout"));
   201     mKeypressTimeoutItem = new HbDataFormModelItem(HbDataFormModelItem::SliderItem, QObject::tr("Keypress Timeout"));
   155     keyboardGroup->appendChild(mKeypressTimeoutItem);
   202     keyboardGroup->appendChild(mKeypressTimeoutItem);
   156     mKeypressTimeoutItem->setContentWidgetData(QString("minimum"), HbInputMinKeypressTimeout);
   203     mKeypressTimeoutItem->setContentWidgetData(QString("minimum"), HbInputMinKeypressTimeout);
   157     mKeypressTimeoutItem->setContentWidgetData(QString("maximum"), HbInputMaxKeypressTimeout);
   204     mKeypressTimeoutItem->setContentWidgetData(QString("maximum"), HbInputMaxKeypressTimeout);
   167     } else {
   214     } else {
   168         mCharacterPreviewItem->setContentWidgetData(QString("text"), statusOff);
   215         mCharacterPreviewItem->setContentWidgetData(QString("text"), statusOff);
   169         mCharacterPreviewItem->setContentWidgetData(QString("additionalText"), statusOn);
   216         mCharacterPreviewItem->setContentWidgetData(QString("additionalText"), statusOn);
   170     }
   217     }
   171     mCharacterPreviewItem->setContentWidgetData(QString("objectName"), QString("character_bubble"));
   218     mCharacterPreviewItem->setContentWidgetData(QString("objectName"), QString("character_bubble"));
   172     mForm->addConnection(mCharacterPreviewItem, SIGNAL(clicked(bool)), q, SLOT(setCharacterPreviewState()));
   219     
   173 
   220 
   174     HbDataFormModelItem *textInputGroup = model->appendDataFormGroup(QObject::tr("Intelligent Text Input"));
   221 
       
   222     HbDataFormModelItem *textInputGroup = mModel->appendDataFormGroup(QObject::tr("Intelligent Text Input"));
   175 
   223 
   176     HbDataFormModelItem::DataItemType checkboxList =
   224     HbDataFormModelItem::DataItemType checkboxList =
   177         static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase);
   225         static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase);
   178 
   226 
   179     mPredictionItem = new HbDataFormModelItem(checkboxList, QObject::tr("Prediction"));
   227     mPredictionItem = new HbDataFormModelItem(checkboxList, QObject::tr("Prediction"));
   215     } else {
   263     } else {
   216         mPrimaryCandidateItem->setContentWidgetData(QString("text"), exactTyping);
   264         mPrimaryCandidateItem->setContentWidgetData(QString("text"), exactTyping);
   217         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), bestPrediction);
   265         mPrimaryCandidateItem->setContentWidgetData(QString("additionalText"), bestPrediction);
   218     }
   266     }
   219     mPrimaryCandidateItem->setContentWidgetData(QString("objectName"), QString("primary_candidate"));
   267     mPrimaryCandidateItem->setContentWidgetData(QString("objectName"), QString("primary_candidate"));
   220     mForm->addConnection(mPrimaryCandidateItem, SIGNAL(clicked(bool)), q, SLOT(setPrimaryCandidateMode()));
   268     mForm->setModel(mModel);    
   221 
   269     QObject::connect(mModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), q, SLOT(dataChange(QModelIndex, QModelIndex)));
   222     mForm->setModel(model);
       
   223 }
   270 }
   224 
   271 
   225 /*!
   272 /*!
   226 Fills given list with language names in the language list
   273 Fills given list with language names in the language list
   227 */
   274 */
   582     } else {
   629     } else {
   583         d->mPrimaryCandidateMode = HbPrimaryCandidateModeBestPrediction;
   630         d->mPrimaryCandidateMode = HbPrimaryCandidateModeBestPrediction;
   584     }
   631     }
   585     HbInputSettingProxy::instance()->setPrimaryCandidateMode(d->mPrimaryCandidateMode);
   632     HbInputSettingProxy::instance()->setPrimaryCandidateMode(d->mPrimaryCandidateMode);
   586 }
   633 }
       
   634 /*
       
   635     This slot is called when ever data in the form model is changed
       
   636 */
       
   637 void HbInputSettingWidget::dataChange(const QModelIndex &startIn, const QModelIndex &endIn)
       
   638 {
       
   639     Q_D(HbInputSettingWidget);
       
   640     Q_UNUSED(endIn);
       
   641     HbDataFormModelItem *item = d->mModel->itemFromIndex(startIn);    
       
   642     if(item == d->mPrimaryCandidateItem) {
       
   643         setPrimaryCandidateMode();
       
   644     } else if(item == d->mCharacterPreviewItem) {
       
   645         setCharacterPreviewState();
       
   646     } 
       
   647 }
       
   648 
       
   649 /*
       
   650  Resets the widget and disconnects the signals connected to the settings proxy
       
   651 */
       
   652 
       
   653 void HbInputSettingWidget::resetWidget()
       
   654 {
       
   655     HbInputSettingProxy *settings = HbInputSettingProxy::instance();
       
   656     disconnect(settings, SIGNAL(globalInputLanguageChanged(const HbInputLanguage &)), this, SLOT(updateGlobalInputLanguage(const HbInputLanguage &)));
       
   657     disconnect(settings, SIGNAL(globalSecondaryInputLanguageChanged(const HbInputLanguage &)), this, SLOT(updateGlobalSecondaryInputLanguage(const HbInputLanguage &)));
       
   658     disconnect(settings, SIGNAL(predictiveInputStateChanged(HbKeyboardSettingFlags, bool)), this, SLOT(updatePredictiveInputState(HbKeyboardSettingFlags, bool)));
       
   659     disconnect(settings, SIGNAL(characterPreviewStateForQwertyChanged(bool)), this, SLOT(updateCharacterPreviewStateForQwerty(bool)));
       
   660     disconnect(settings, SIGNAL(keypressTimeoutChanged(int)), this, SLOT(updateKeypressTimeout(int)));
       
   661     disconnect(settings, SIGNAL(autocompletionStateChanged(HbKeyboardSettingFlags, bool)), this, SLOT(updateAutocompletionState(HbKeyboardSettingFlags, bool)));
       
   662     disconnect(settings, SIGNAL(typingCorrectionLevelChanged(HbTypingCorrectionLevel)), this, SLOT(updateTypingCorrectionLevel(HbTypingCorrectionLevel)));
       
   663     disconnect(settings, SIGNAL(primaryCandidateModeChanged(HbPrimaryCandidateMode)), this, SLOT(updatePrimaryCandidateMode(HbPrimaryCandidateMode)));    
       
   664 }
       
   665 
   587 
   666 
   588 // End of file
   667 // End of file