src/hbapps/hbfeatureconfigapp/settingsview.cpp
changeset 21 4633027730f5
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbApps module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include <QStringListModel>
       
    27 
       
    28 #include <hbcombobox.h>
       
    29 #include <hbdeviceprofile.h>
       
    30 #include <hbdocumentloader.h>
       
    31 #include <hbmainwindow.h>
       
    32 #include <hbinstance.h>
       
    33 #include <hbapplication.h>
       
    34 #include <hbscrollarea.h>
       
    35 #include <hbmenu.h>
       
    36 #include <hbaction.h>
       
    37 #include <restricted/hbfeaturemanager_r.h>
       
    38 
       
    39 #include "settingsview.h"
       
    40 
       
    41 #if defined(Q_OS_SYMBIAN)
       
    42 #include <hbs60events.h>
       
    43 #include <w32std.h>
       
    44 #include <hbdeviceprofile.h>
       
    45 #endif
       
    46 
       
    47 SettingsView::SettingsView(HbDocumentLoader* loader, HbMainWindow *window, HbView *infoView) :
       
    48 	mWindow(window),
       
    49 	mLoader(loader),
       
    50     mResolutionComboBox(0),
       
    51 	mOrientationComboBox(0),
       
    52     mLayoutDirectionComboBox(0),
       
    53 	mTouchAreaComboBox(0),
       
    54     mTextItemComboBox(0),
       
    55     mIconItemComboBox(0),
       
    56 	mLocalizationComboBox(0),
       
    57     mTestUtilityComboBox(0),
       
    58     mFpsCounterComboBox(0),
       
    59     mInfoView(infoView)
       
    60 {
       
    61     setupMenu();
       
    62     setupLayout();
       
    63     updateSelections();
       
    64     connect(mWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(updateLayout()));
       
    65     connect(mWindow, SIGNAL(currentViewChanged(HbView*)), this, SLOT(updateSelections()));
       
    66     setTitle("Settings");
       
    67     HbAction *backAction = new HbAction(Hb::BackNaviAction, this);
       
    68     connect(backAction, SIGNAL(triggered()), SLOT(goBack()));
       
    69     setNavigationAction(backAction);
       
    70 }
       
    71 
       
    72 void SettingsView::goBack()
       
    73 {
       
    74     mWindow->setCurrentView(mInfoView);
       
    75 }
       
    76     
       
    77 void SettingsView::setupMenu()
       
    78 {
       
    79     HbMenu *menu = new HbMenu();
       
    80     HbAction *a;
       
    81     a = menu->addAction( "Change orientation" );
       
    82     connect(a, SIGNAL(triggered()), SLOT(changeOrientation()));
       
    83     setMenu(menu);
       
    84 }
       
    85 
       
    86 
       
    87 void SettingsView::setupLayout()
       
    88 {
       
    89     disconnectSignals();
       
    90 
       
    91     HbDeviceProfile currentProfile = HbDeviceProfile::profile(mWindow);
       
    92     QString section = currentProfile.orientation() == Qt::Horizontal ? "landscape" : "portrait";
       
    93     mLoader->load(QString(":/appxml/hbs60deviceconfigapp.docml"), section);
       
    94 
       
    95     QGraphicsWidget *settingsWidget = mLoader->findWidget("settingsView");
       
    96     if (settingsWidget) {
       
    97         QGraphicsWidget* oldWidget = takeWidget();
       
    98         if (oldWidget)
       
    99             oldWidget->setVisible(false);
       
   100         settingsWidget->setVisible(true);
       
   101         setWidget(settingsWidget);
       
   102     }
       
   103     
       
   104     if( !mResolutionComboBox ) {
       
   105         mResolutionComboBox = qobject_cast<HbComboBox *>(mLoader->findWidget("resolutionSettingCombo"));
       
   106         mResolutionComboBox->setModel(new QStringListModel(HbDeviceProfile::profileNames()));
       
   107     }
       
   108 
       
   109     if( !mOrientationComboBox ) {
       
   110         mOrientationComboBox = qobject_cast<HbComboBox *>(mLoader->findWidget("orientationSettingCombo"));
       
   111         mOrientationComboBox->setModel(new QStringListModel(QStringList() << "Portrait" << "Landscape"));
       
   112     }
       
   113 
       
   114     if( !mLayoutDirectionComboBox ) {
       
   115         mLayoutDirectionComboBox = qobject_cast<HbComboBox *>(mLoader->findWidget("directionSettingCombo"));
       
   116         mLayoutDirectionComboBox->setModel(new QStringListModel(QStringList() << "Left to Right" << "Right to Left"));
       
   117     }
       
   118 
       
   119     if( !mTouchAreaComboBox ) {
       
   120         mTouchAreaComboBox = qobject_cast<HbComboBox *>(mLoader->findWidget("touchareaSettingCombo"));
       
   121         mTouchAreaComboBox->setModel(new QStringListModel(QStringList() << tr("Invisible") << tr("Visible")));
       
   122     }
       
   123 
       
   124     if( !mTextItemComboBox ) {
       
   125         mTextItemComboBox = qobject_cast<HbComboBox *>(mLoader->findWidget("textitemSettingCombo"));
       
   126         mTextItemComboBox->setModel(new QStringListModel(QStringList() << tr("Invisible") << tr("Visible")));
       
   127     }
       
   128 
       
   129     if( !mIconItemComboBox ) {
       
   130         mIconItemComboBox = qobject_cast<HbComboBox *>(mLoader->findWidget("iconitemSettingCombo"));
       
   131         mIconItemComboBox->setModel(new QStringListModel(QStringList() << tr("Invisible") << tr("Visible")));
       
   132     }
       
   133 	
       
   134 	if (!mFpsCounterComboBox) {
       
   135 	    mFpsCounterComboBox = qobject_cast<HbComboBox *>(mLoader->findWidget("fpscounterSettingCombo"));
       
   136     	mFpsCounterComboBox->setModel(new QStringListModel(QStringList() << tr("Invisible") << tr("Visible")));
       
   137 	}
       
   138 
       
   139     if( !mLocalizationComboBox ) {
       
   140         mLocalizationComboBox = qobject_cast<HbComboBox *>(mLoader->findWidget("localizationSettingCombo"));
       
   141         mLocalizationComboBox->setModel(new QStringListModel(QStringList() << tr("Disabled") << tr("Enabled") << tr("Automatic")));
       
   142     }
       
   143 
       
   144     int textMeasurementValue = HbFeatureManager::instance()->featureStatus( HbFeatureManager::TextMeasurement );
       
   145     if ( textMeasurementValue > 2 ) {
       
   146         textMeasurementValue = 1;
       
   147     }
       
   148     mLocalizationComboBox->setCurrentIndex( textMeasurementValue );
       
   149 
       
   150     if( !mTestUtilityComboBox ) {
       
   151         mTestUtilityComboBox = qobject_cast<HbComboBox *>(mLoader->findWidget("testUtilitySettingCombo"));
       
   152         mTestUtilityComboBox->setModel(new QStringListModel(QStringList() << tr("Disabled") << tr("Enabled")));
       
   153     }
       
   154     mTestUtilityComboBox->setCurrentIndex( HbFeatureManager::instance()->featureStatus( HbFeatureManager::TheTestUtility ) ? 1 : 0 );
       
   155 
       
   156     connectSignals();
       
   157 }
       
   158 
       
   159 void SettingsView::changeLocMode(int index)
       
   160 {
       
   161     HbFeatureManager::instance()->setFeatureStatus( HbFeatureManager::TextMeasurement, index );
       
   162 }
       
   163 
       
   164 void SettingsView::changeTestUtilMode(int index)
       
   165 {
       
   166     HbFeatureManager::instance()->setFeatureStatus( HbFeatureManager::TheTestUtility, index );
       
   167 }
       
   168 
       
   169 void SettingsView::changeResolution(int index)
       
   170 {
       
   171 #if defined(Q_OS_SYMBIAN)
       
   172 	sendEvent(KChangeDeviceProfile, index);
       
   173 #else
       
   174 	Q_UNUSED(index);
       
   175 #endif
       
   176 }
       
   177 
       
   178 void SettingsView::changeOrientation(int index)
       
   179 {
       
   180 #if defined(Q_OS_SYMBIAN)
       
   181     sendEvent(KChangeOrientation, index);
       
   182 #else
       
   183     Q_UNUSED(index);
       
   184 #endif
       
   185 }
       
   186 
       
   187 void SettingsView::changeLayoutDirection(int index)
       
   188 {
       
   189 #if defined(Q_OS_SYMBIAN)
       
   190     sendEvent(KChangeDirection, index);
       
   191 #else
       
   192     Q_UNUSED(index);
       
   193 #endif
       
   194 }
       
   195 
       
   196 void SettingsView::changeTouchAreaVisibility(int index)
       
   197 {
       
   198 #if defined(Q_OS_SYMBIAN)
       
   199     sendEvent(KChangeTouchAreaVis, index);
       
   200 #else
       
   201     Q_UNUSED(index);
       
   202 #endif
       
   203 }
       
   204 
       
   205 void SettingsView::changeTextItemVisibility(int index)
       
   206 {
       
   207 #if defined(Q_OS_SYMBIAN)
       
   208     sendEvent(KChangeTextItemVis, index);
       
   209 #else
       
   210     Q_UNUSED(index);
       
   211 #endif
       
   212 }
       
   213 
       
   214 void SettingsView::changeIconItemVisibility(int index)
       
   215 {
       
   216 #if defined(Q_OS_SYMBIAN)
       
   217     sendEvent(KChangeIconItemVis, index);
       
   218 #else
       
   219     Q_UNUSED(index);
       
   220 #endif
       
   221 }
       
   222 
       
   223 void SettingsView::changeFpsCounterVisibility(int index)
       
   224 {
       
   225 #if defined(Q_OS_SYMBIAN)
       
   226 	sendEvent(KChangeFpsCounterVis, index);
       
   227 #else
       
   228 	Q_UNUSED(index);
       
   229 #endif
       
   230 }
       
   231 
       
   232 void SettingsView::sendEvent(const int eventID, const int data)
       
   233 {
       
   234 #if defined(Q_OS_SYMBIAN)
       
   235     RWsSession session;
       
   236     User::LeaveIfError( session.Connect() );
       
   237     TWsEvent event;
       
   238     event.SetType(eventID);
       
   239     TUint8* dataptr = event.EventData();
       
   240     *dataptr = data;
       
   241     session.SendEventToAllWindowGroups(event);
       
   242     session.Close();
       
   243 #else
       
   244     Q_UNUSED(eventID);
       
   245     Q_UNUSED(data);
       
   246 #endif
       
   247 }
       
   248 
       
   249 
       
   250 void SettingsView::updateLayout()
       
   251 {
       
   252     setupLayout();
       
   253     updateSelections();
       
   254 }
       
   255 
       
   256 void SettingsView::updateSelections()
       
   257 {
       
   258     disconnectSignals();
       
   259     HbDeviceProfile currentProfile = HbDeviceProfile::profile(mWindow);
       
   260     mIconItemComboBox->setCurrentIndex(0); // TODO: Can't currently get value from private code
       
   261     mTextItemComboBox->setCurrentIndex(0); // TODO: Can't currently get value from private code
       
   262     mTouchAreaComboBox->setCurrentIndex(0); // TODO: Can't currently get value from private code
       
   263     mLayoutDirectionComboBox->setCurrentIndex(HbApplication::layoutDirection() == Qt::LeftToRight ? 0 : 1);
       
   264     mOrientationComboBox->setCurrentIndex(currentProfile.orientation() == Qt::Vertical ? 0 : 1);
       
   265     mResolutionComboBox->setCurrentIndex(HbDeviceProfile::profileNames().indexOf(currentProfile.name()));
       
   266     mFpsCounterComboBox->setCurrentIndex(0); // off by default
       
   267     connectSignals();
       
   268 }
       
   269 
       
   270 void SettingsView::connectSignals()
       
   271 {
       
   272     connect(mIconItemComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeIconItemVisibility(int)));
       
   273     connect(mTextItemComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeTextItemVisibility(int)));
       
   274     connect(mTouchAreaComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeTouchAreaVisibility(int)));
       
   275     connect(mLayoutDirectionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeLayoutDirection(int)));
       
   276     connect(mOrientationComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeOrientation(int)));
       
   277     connect(mResolutionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeResolution(int)));
       
   278 	connect(mFpsCounterComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeFpsCounterVisibility(int)));
       
   279     connect(mLocalizationComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeLocMode(int)));
       
   280     connect(mTestUtilityComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeTestUtilMode(int)));
       
   281 }
       
   282 
       
   283 void SettingsView::disconnectSignals()
       
   284 {
       
   285     disconnect(mIconItemComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeIconItemVisibility(int)));
       
   286     disconnect(mTextItemComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeTextItemVisibility(int)));
       
   287     disconnect(mTouchAreaComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeTouchAreaVisibility(int)));
       
   288     disconnect(mLayoutDirectionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeLayoutDirection(int)));
       
   289     disconnect(mOrientationComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeOrientation(int)));
       
   290     disconnect(mResolutionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeResolution(int)));
       
   291 	disconnect(mFpsCounterComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeFpsCounterVisibility(int)));
       
   292     disconnect(mLocalizationComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeLocMode(int)));
       
   293     disconnect(mTestUtilityComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeTestUtilMode(int)));
       
   294 }
       
   295 
       
   296 void SettingsView::changeOrientation()
       
   297 {
       
   298     if (mWindow)
       
   299         mWindow->setOrientation(mWindow->orientation() == Qt::Vertical ? Qt::Horizontal : Qt::Vertical);
       
   300 }