camerauis/cameraxui/cxui/src/cxuisettingradiobuttonlist.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
child 45 24fd82631616
equal deleted inserted replaced
28:3075d9b614e6 43:0e652f8f1fbd
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    36 
    36 
    37     // connect the signals again
    37     // connect the signals again
    38     connect(this, SIGNAL(itemSelected(int)), this, SLOT(handleItemSelected(int)));
    38     connect(this, SIGNAL(itemSelected(int)), this, SLOT(handleItemSelected(int)));
    39 }
    39 }
    40 
    40 
    41 
    41 /*!
       
    42 * Init contents of the listbox and select current setting value.
       
    43 */
    42 void CxuiSettingRadioButtonList::init(CxUiSettings::RadioButtonListParams *data)
    44 void CxuiSettingRadioButtonList::init(CxUiSettings::RadioButtonListParams *data)
    43 {
    45 {
    44     // first we reset the model and clear any previous data
    46     // first we reset the model and clear any previous data
    45     mSettingValues.clear();
    47     mSettingValues.clear();
    46     mListModel->resetModel();
    48     mListModel->resetModel();
    65         setPreviewMode(HbRadioButtonList::NoPreview);
    67         setPreviewMode(HbRadioButtonList::NoPreview);
    66         mPreview = data->mPreview;
    68         mPreview = data->mPreview;
    67 
    69 
    68         setSettingId(data->mSettingId);
    70         setSettingId(data->mSettingId);
    69         setListBoxType(data->mListboxType);
    71         setListBoxType(data->mListboxType);
    70     }
    72 
    71 
    73         // Store the original setting value and focus matching item.
    72 }
    74         QString value;
    73 
    75         mEngine->settings().get(mSettingId, value);
       
    76         CX_DEBUG(("CxuiSettingRadioButtonList - original value: [%s]", qPrintable(value)));
       
    77         setOriginalSelectedItemByValue(QVariant(value));
       
    78     }
       
    79 }
       
    80 
       
    81 /*!
       
    82  * Sets the original selection of list by value. Can be used to override value read from
       
    83  * CxeSettings or used to remember previously selected value in case of setting that is
       
    84  * not read from CxeSettings (e.g. selftimer)
       
    85  */
       
    86 void CxuiSettingRadioButtonList::setOriginalSelectedItemByValue(const QVariant &value)
       
    87 {
       
    88     CX_DEBUG_ENTER_FUNCTION();
       
    89 
       
    90     // Find the index of given value among setting values.
       
    91     // Default to first item, if given value is not found.
       
    92     int index = mSettingValues.indexOf(QVariant(value));
       
    93     if (index < 0) {
       
    94         CX_DEBUG(("[WARNING] Value [%s] not found, selecting first item", qPrintable(value.toString())));
       
    95         index = 0;
       
    96     }
       
    97 
       
    98     // Store the original value.
       
    99     mOriginalIndex = index;
       
   100     // Select the index with current value item.
       
   101     setSelected(index);
       
   102     // Ensure that currently selected item is visible.
       
   103     scrollTo(currentIndex());
       
   104 
       
   105     CX_DEBUG_EXIT_FUNCTION();
       
   106 }
       
   107 
       
   108 /*!
       
   109 * Set list texts.
       
   110 * @param values List of the texts.
       
   111 */
    74 void CxuiSettingRadioButtonList::setItems(const QStringList &values)
   112 void CxuiSettingRadioButtonList::setItems(const QStringList &values)
    75 {
   113 {
    76     mListModel->setItems(values);
   114     mListModel->setItems(values);
    77 }
   115 }
    78 
   116 
       
   117 /*!
       
   118 * Set the type of this list.
       
   119 * @param type Type identifier, SingleLine or TwoLine.
       
   120 */
    79 void CxuiSettingRadioButtonList::setListBoxType(int type)
   121 void CxuiSettingRadioButtonList::setListBoxType(int type)
    80 {
   122 {
    81     mListModel->setListBoxType(type);
   123     mListModel->setListBoxType(type);
    82 }
   124 }
    83 
   125 
    84 
   126 /*!
       
   127 * Set id of the setting this list represents.
       
   128 * @param id Id of the setting.
       
   129 */
    85 void CxuiSettingRadioButtonList::setSettingId(const QString &id)
   130 void CxuiSettingRadioButtonList::setSettingId(const QString &id)
    86 {
   131 {
    87     // Selected item is updated, when this list is shown.
   132     // Selected item is updated, when this list is shown.
    88     mSettingId = id;
   133     mSettingId = id;
    89 }
   134 }
    90 
   135 
    91 
   136 /*!
    92 
   137 * Handle selecting an item.
       
   138 * @param index Index of the selected item in list.
       
   139 */
    93 void CxuiSettingRadioButtonList::handleItemSelected(int index)
   140 void CxuiSettingRadioButtonList::handleItemSelected(int index)
    94 {
   141 {
    95     CX_DEBUG_ENTER_FUNCTION();
   142     CX_DEBUG_ENTER_FUNCTION();
    96 
   143 
    97     if (mPreview) {
   144     if (mPreview) {
   100         // no action needed
   147         // no action needed
   101     }
   148     }
   102     CX_DEBUG_EXIT_FUNCTION();
   149     CX_DEBUG_EXIT_FUNCTION();
   103 }
   150 }
   104 
   151 
   105 void CxuiSettingRadioButtonList::showEvent(QShowEvent *event)
       
   106 {
       
   107     CX_DEBUG_ENTER_FUNCTION();
       
   108 
       
   109     initOriginalSelectedItem();
       
   110     QGraphicsWidget::showEvent(event);
       
   111 
       
   112     CX_DEBUG_EXIT_FUNCTION();
       
   113 }
       
   114 
       
   115 
       
   116 /*!
       
   117 *  Get the value currently active in settings.
       
   118 */
       
   119 void CxuiSettingRadioButtonList::initOriginalSelectedItem()
       
   120 {
       
   121     CX_DEBUG_ENTER_FUNCTION();
       
   122 
       
   123     QString value;
       
   124     int err = mEngine->settings().get(mSettingId, value);
       
   125     CX_DEBUG(("CxuiSettingRadioButtonList - original value: [%s]", value.toAscii().data()));
       
   126 
       
   127     int index = 0;
       
   128 
       
   129     if (err == CxeError::None) {
       
   130         index = mSettingValues.indexOf(QVariant(value));
       
   131         CX_DEBUG(("CxuiSettingRadioButtonList - got original index of: %d", index));
       
   132     }
       
   133 
       
   134     mOriginalIndex = index;
       
   135     setSelected(mOriginalIndex);
       
   136 
       
   137     CX_DEBUG_EXIT_FUNCTION();
       
   138 }
       
   139 
       
   140 /*!
   152 /*!
   141     This slot can be used to set the selection accepted.
   153     This slot can be used to set the selection accepted.
   142 */
   154 */
   143 void CxuiSettingRadioButtonList::handleSelectionAccepted()
   155 void CxuiSettingRadioButtonList::handleSelectionAccepted()
   144 {
   156 {
   151     emit selectionCommitted();
   163     emit selectionCommitted();
   152 
   164 
   153     CX_DEBUG_EXIT_FUNCTION();
   165     CX_DEBUG_EXIT_FUNCTION();
   154 }
   166 }
   155 
   167 
       
   168 /*!
       
   169 * Handle closing the listbox. If the current selection was accepted,
       
   170 * we commit the new value here. If current selection has been cancelled,
       
   171 * we commit the original value.
       
   172 */
   156 void CxuiSettingRadioButtonList::handleClose()
   173 void CxuiSettingRadioButtonList::handleClose()
   157 {
   174 {
   158     CX_DEBUG_ENTER_FUNCTION();
   175     CX_DEBUG_ENTER_FUNCTION();
   159 
   176 
   160     if (!mSettingId.isEmpty()) {
   177     if (!mSettingId.isEmpty()) {
   171 }
   188 }
   172 
   189 
   173 
   190 
   174 
   191 
   175 /*!
   192 /*!
   176   Commits value to the cenrep store.
   193   Commits value to settings.
   177 */
   194 */
   178 void CxuiSettingRadioButtonList::commit(int index)
   195 void CxuiSettingRadioButtonList::commit(int index)
   179 {
   196 {
   180     CX_DEBUG_ENTER_FUNCTION();
   197     CX_DEBUG_ENTER_FUNCTION();
   181 
   198 
   182     CX_DEBUG(("id: %s", mSettingId.toAscii().data()));
   199     CX_DEBUG(("CxuiSettingRadioButtonList - id: %s", qPrintable(mSettingId)));
   183 
   200 
   184     if (!mSettingId.isEmpty() && !mSettingValues.isEmpty()) {
   201     if (!mSettingId.isEmpty() && !mSettingValues.isEmpty()) {
   185         QVariant value = mSettingValues.at(index);
   202         QVariant value = mSettingValues.at(index);
   186         if (value.type() == QVariant::Int) {
   203         if (value.type() == QVariant::Int) {
   187             CX_DEBUG(("index:%d value:%d", index, value.toInt()));
   204             CX_DEBUG(("CxuiSettingRadioButtonList - index:%d value:%d", index, value.toInt()));
   188 
   205 
   189             // Don't set the value again, if it is the current value.
   206             // Don't set the value again, if it is the current value.
   190             // For e.g. video quality it would result in re-preparation etc.
   207             // For e.g. video quality it would result in re-preparation etc.
   191             int current(0);
   208             int current(0);
   192             CxeError::Id status(mEngine->settings().get(mSettingId, current));
   209             CxeError::Id status(mEngine->settings().get(mSettingId, current));
   196             }
   213             }
   197             // inform interested clients about value changed event
   214             // inform interested clients about value changed event
   198             emit valueSelected(value.toInt());
   215             emit valueSelected(value.toInt());
   199 
   216 
   200         } else if (value.type() == QVariant::String) {
   217         } else if (value.type() == QVariant::String) {
   201             CX_DEBUG(("index:%d value:[%s]", index, value.toString().toAscii().constData()));
   218             CX_DEBUG(("CxuiSettingRadioButtonList - index:%d value:[%s]", index, qPrintable(value.toString())));
   202 
   219 
   203             QString current;
   220             QString current;
   204             CxeError::Id status(mEngine->settings().get(mSettingId, current));
   221             CxeError::Id status(mEngine->settings().get(mSettingId, current));
   205             CX_DEBUG(("settings model value:[%s]", current.toAscii().constData()));
   222             CX_DEBUG(("CxuiSettingRadioButtonList - settings model value:[%s]", qPrintable(current)));
   206 
   223 
   207             if (status != CxeError::None || current != value.toString()) {
   224             if (status != CxeError::None || current != value.toString()) {
   208                 mEngine->settings().set(mSettingId, value.toString());
   225                 mEngine->settings().set(mSettingId, value.toString());
   209             }
   226             }
   210         }
   227         }