controlpanelplugins/themeplugin/src/cpthemepreview.cpp
branchRCL_3
changeset 13 90fe62538f66
equal deleted inserted replaced
12:3fec62e6e7fc 13:90fe62538f66
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0""
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  
       
    15  *   
       
    16  */
       
    17 
       
    18 #include <QObject>
       
    19 #include <QString>
       
    20 #include <QGraphicsPixmapItem>
       
    21 #include <QGraphicsLinearLayout>
       
    22 
       
    23 #include <hbaction.h>
       
    24 #include <hbtoolbar.h>
       
    25 #include <hbicon.h>
       
    26 #include <hbaction.h>
       
    27 #include <hblabel.h>
       
    28 #include <hbiconitem.h>
       
    29 #include <hbmainwindow.h>
       
    30 #include <HbParameterLengthLimiter>
       
    31 #include <HbDataForm>
       
    32 
       
    33 #include "cpthemepreview.h"
       
    34 #include "cpthemeinfo.h"
       
    35 
       
    36 /*!
       
    37     \class CpThemePreview
       
    38     \brief CpThemePreview shows a preview of a selected theme with a heading displaying the name of the theme as well as
       
    39            a toolbar with Select and Cancel buttons.  This view is used for the user to either select the theme and apply
       
    40            the theme change or press Cancel and go back to theme list view.
       
    41 */
       
    42 
       
    43 
       
    44 /*!
       
    45     constructor.
       
    46 */
       
    47 CpThemePreview::CpThemePreview(const CpThemeInfo& theme, QGraphicsItem *parent) :
       
    48      HbView(parent), 
       
    49      mTheme(theme),
       
    50      mSoftKeyBackAction(0),
       
    51      mPreviewIcon(0)
       
    52 {
       
    53     QGraphicsLinearLayout* containerLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    54     QGraphicsLinearLayout* bottomLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    55         
       
    56     //Preview icon margins.
       
    57     qreal leftMargin = 0.0;
       
    58     qreal rightMargin = 0.0;
       
    59     qreal topMargin = 0.0;
       
    60     qreal bottomMargin = 0.0;
       
    61         
       
    62     style()->parameter(QString("hb-param-margin-gene-left"), leftMargin);
       
    63     style()->parameter("hb-param-margin-gene-right", rightMargin);
       
    64     style()->parameter("hb-param-margin-gene-top", topMargin);
       
    65     style()->parameter("hb-param-margin-gene-bottom", bottomMargin);
       
    66 
       
    67     containerLayout->setContentsMargins(0,0,0,0);
       
    68     bottomLayout->setContentsMargins(leftMargin, topMargin, rightMargin, bottomMargin);
       
    69        
       
    70     //Using an empty dataform as heading because the heading should
       
    71     //look like an HbDataForm headiing.
       
    72     HbDataForm* heading = new HbDataForm(this);
       
    73     QString themeHeading = HbParameterLengthLimiter("txt_cp_title_preview_1").arg(mTheme.name());   
       
    74     heading->setHeading(themeHeading);
       
    75        
       
    76     containerLayout->addItem(heading);
       
    77     //Fixed vertical policy so that the heading doesn't expand.
       
    78     heading->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,QSizePolicy::DefaultType);
       
    79     
       
    80     if(mainWindow()->orientation() == Qt::Horizontal) {
       
    81         mPreviewIcon = new HbIconItem(mTheme.landscapePreviewIcon(), this);
       
    82     }
       
    83     else {
       
    84         mPreviewIcon = new HbIconItem(mTheme.portraitPreviewIcon(), this);
       
    85         //set to ignore aspect ratio so the layout would rezise the icon correctly.
       
    86           
       
    87     }
       
    88     mPreviewIcon->setAspectRatioMode(Qt::IgnoreAspectRatio);
       
    89   
       
    90     // set an object name for preview icon to make it testable for automation testing
       
    91     mPreviewIcon->setObjectName(QString("themePreviewIcon"));
       
    92 
       
    93     
       
    94     bottomLayout->addItem(mPreviewIcon);
       
    95     containerLayout->addItem(bottomLayout);
       
    96 
       
    97     setLayout(containerLayout);
       
    98         
       
    99     //Create the toolbar and "Select" and "Cancel" actions.
       
   100     HbToolBar* mToolBar = new HbToolBar(this);
       
   101 
       
   102     HbAction* selectAction = new HbAction(hbTrId("txt_common_button_select"));
       
   103     
       
   104     //Add Action to the toolbar and show toolbar
       
   105     mToolBar->addAction( selectAction );
       
   106 
       
   107     HbAction* cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
       
   108     mToolBar->addAction( cancelAction );
       
   109 
       
   110     QObject::connect( selectAction, SIGNAL(triggered()), 
       
   111                       this, SLOT(themeSelected()));
       
   112 
       
   113     QObject::connect( cancelAction, SIGNAL(triggered()), 
       
   114                       this, SIGNAL(aboutToClose()));
       
   115     QObject::connect( mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
   116                       this, SLOT(previewOrientationChanged(Qt::Orientation)));
       
   117        
       
   118         
       
   119     setToolBar(mToolBar);
       
   120     //Setup the Back button action and set softkey. Back button 
       
   121     //takes the user to the theme list view.
       
   122     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
       
   123     QObject::connect(mSoftKeyBackAction, SIGNAL(triggered()), 
       
   124             this, SIGNAL(aboutToClose()) );
       
   125 
       
   126     setNavigationAction(mSoftKeyBackAction);
       
   127     
       
   128 }
       
   129 
       
   130 /*!
       
   131     destructor.
       
   132 */
       
   133 CpThemePreview::~CpThemePreview()
       
   134 {
       
   135 }
       
   136 
       
   137 /*!
       
   138   sets the theme to \a theme.
       
   139 */
       
   140 void CpThemePreview::setThemeInfo(const CpThemeInfo& theme)
       
   141 {
       
   142     mTheme = theme;
       
   143 }
       
   144 
       
   145 /*!
       
   146     returns the themeName.
       
   147 */
       
   148 const QString CpThemePreview::themeName() const
       
   149 {
       
   150     return mTheme.name();
       
   151 }
       
   152 
       
   153 /*!
       
   154     returns the repersentative themeIcon of the current theme.
       
   155 */
       
   156 const HbIcon CpThemePreview::themeIcon() const
       
   157 {
       
   158     return mTheme.icon();
       
   159 }
       
   160 
       
   161 /*!
       
   162     Slot to handle when the user selects a theme.  
       
   163 */
       
   164 void CpThemePreview::themeSelected()
       
   165 {
       
   166     emit applyTheme(mTheme);
       
   167 }
       
   168 
       
   169 /*! 
       
   170  *  Slot to handle landscape/portrait orientation change to use the
       
   171  *  right graphics.
       
   172  */
       
   173 void CpThemePreview::previewOrientationChanged(Qt::Orientation orientation)
       
   174 {
       
   175    
       
   176     QGraphicsLinearLayout* containerLayout = dynamic_cast<QGraphicsLinearLayout*>(layout());
       
   177     QGraphicsLinearLayout* previewLayout = 0;
       
   178     if(containerLayout) {
       
   179         //get the layout that preview icon belongs to.
       
   180         previewLayout = dynamic_cast<QGraphicsLinearLayout*>(containerLayout->itemAt(1));
       
   181     }
       
   182    
       
   183     if(previewLayout && mPreviewIcon && mPreviewIcon == dynamic_cast<HbIconItem*>(previewLayout->itemAt(0)) ) {
       
   184         //Remove preview icon.
       
   185         previewLayout->removeAt(0);
       
   186         
       
   187         if(orientation == Qt::Horizontal) {
       
   188             mPreviewIcon->setIcon(mTheme.landscapePreviewIcon());
       
   189                     
       
   190         }
       
   191         else {
       
   192             mPreviewIcon->setIcon(mTheme.portraitPreviewIcon());
       
   193         }
       
   194         
       
   195         previewLayout->addItem(mPreviewIcon);
       
   196     }
       
   197     
       
   198 }
       
   199 
       
   200 
       
   201