controlpanelplugins/themeplugin/src/cpthemepreview.cpp
changeset 40 593f946f4fec
parent 22 a5692c68d772
--- a/controlpanelplugins/themeplugin/src/cpthemepreview.cpp	Fri Jun 25 17:12:20 2010 +0800
+++ b/controlpanelplugins/themeplugin/src/cpthemepreview.cpp	Wed Sep 29 10:09:58 2010 +0800
@@ -15,6 +15,7 @@
  *   
  */
 
+#include <QObject>
 #include <QString>
 #include <QGraphicsPixmapItem>
 #include <QGraphicsLinearLayout>
@@ -27,6 +28,7 @@
 #include <hbiconitem.h>
 #include <hbmainwindow.h>
 #include <HbParameterLengthLimiter>
+#include <HbDataForm>
 
 #include "cpthemepreview.h"
 #include "cpthemeinfo.h"
@@ -38,6 +40,7 @@
            the theme change or press Cancel and go back to theme list view.
 */
 
+
 /*!
     constructor.
 */
@@ -47,20 +50,52 @@
      mSoftKeyBackAction(0),
      mPreviewIcon(0)
 {
+    QGraphicsLinearLayout* containerLayout = new QGraphicsLinearLayout(Qt::Vertical);
+    QGraphicsLinearLayout* bottomLayout = new QGraphicsLinearLayout(Qt::Vertical);
+        
+    //Preview icon margins.
+    qreal leftMargin = 0.0;
+    qreal rightMargin = 0.0;
+    qreal topMargin = 0.0;
+    qreal bottomMargin = 0.0;
+        
+    style()->parameter(QString("hb-param-margin-gene-left"), leftMargin);
+    style()->parameter("hb-param-margin-gene-right", rightMargin);
+    style()->parameter("hb-param-margin-gene-top", topMargin);
+    style()->parameter("hb-param-margin-gene-bottom", bottomMargin);
+
+    containerLayout->setContentsMargins(0,0,0,0);
+    bottomLayout->setContentsMargins(leftMargin, topMargin, rightMargin, bottomMargin);
+       
+    //Using an empty dataform as heading because the heading should
+    //look like an HbDataForm headiing.
+    HbDataForm* heading = new HbDataForm(this);
+    QString themeHeading = HbParameterLengthLimiter("txt_cp_title_preview_1").arg(mTheme.name());   
+    heading->setHeading(themeHeading);
+       
+    containerLayout->addItem(heading);
+    //Fixed vertical policy so that the heading doesn't expand.
+    heading->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,QSizePolicy::DefaultType);
     
-    //Create the layout and add heading and and preview icon to the layout.
-    QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
+    if(mainWindow()->orientation() == Qt::Horizontal) {
+        mPreviewIcon = new HbIconItem(mTheme.landscapePreviewIcon(), this);
+    }
+    else {
+        mPreviewIcon = new HbIconItem(mTheme.portraitPreviewIcon(), this);
+        //set to ignore aspect ratio so the layout would rezise the icon correctly.
+          
+    }
+    mPreviewIcon->setAspectRatioMode(Qt::IgnoreAspectRatio);
+  
+    // set an object name for preview icon to make it testable for automation testing
+    mPreviewIcon->setObjectName(QString("themePreviewIcon"));
 
     
-    //setup the heading.
-    QString themeHeading = HbParameterLengthLimiter("txt_cp_title_preview_1").arg(mTheme.name());   
-    HbLabel* label = new HbLabel(themeHeading, this);
-   
-    layout->addItem(label);
-    
-    layout->setAlignment(layout->itemAt(0), Qt::AlignTop);
-    layout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,QSizePolicy::DefaultType);
-    
+    bottomLayout->addItem(mPreviewIcon);
+    containerLayout->addItem(bottomLayout);
+
+    setLayout(containerLayout);
+        
     //Create the toolbar and "Select" and "Cancel" actions.
     HbToolBar* mToolBar = new HbToolBar(this);
 
@@ -77,24 +112,11 @@
 
     QObject::connect( cancelAction, SIGNAL(triggered()), 
                       this, SIGNAL(aboutToClose()));
-    
     QObject::connect( mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
                       this, SLOT(previewOrientationChanged(Qt::Orientation)));
        
-   
-    if(mainWindow()->orientation() == Qt::Horizontal) {
-        mPreviewIcon = new HbIconItem(mTheme.landscapePreviewIcon(), this);
-    }
-    else {
-        mPreviewIcon = new HbIconItem(mTheme.portraitPreviewIcon(), this);
-    }
-    layout->addItem(mPreviewIcon);
-    layout->itemAt(1)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred,QSizePolicy::DefaultType);
         
- 
     setToolBar(mToolBar);
-    setLayout(layout);
-
     //Setup the Back button action and set softkey. Back button 
     //takes the user to the theme list view.
     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
@@ -102,6 +124,7 @@
             this, SIGNAL(aboutToClose()) );
 
     setNavigationAction(mSoftKeyBackAction);
+    
 }
 
 /*!
@@ -122,7 +145,7 @@
 /*!
     returns the themeName.
 */
-const QString& CpThemePreview::themeName() const
+const QString CpThemePreview::themeName() const
 {
     return mTheme.name();
 }
@@ -130,7 +153,7 @@
 /*!
     returns the repersentative themeIcon of the current theme.
 */
-const HbIcon& CpThemePreview::themeIcon() const
+const HbIcon CpThemePreview::themeIcon() const
 {
     return mTheme.icon();
 }
@@ -140,7 +163,7 @@
 */
 void CpThemePreview::themeSelected()
 {
-    emit applyTheme(mTheme.name());
+    emit applyTheme(mTheme);
 }
 
 /*! 
@@ -150,13 +173,20 @@
 void CpThemePreview::previewOrientationChanged(Qt::Orientation orientation)
 {
    
-    QGraphicsLinearLayout* previewLayout = dynamic_cast<QGraphicsLinearLayout*>(layout());
+    QGraphicsLinearLayout* containerLayout = dynamic_cast<QGraphicsLinearLayout*>(layout());
+    QGraphicsLinearLayout* previewLayout = 0;
+    if(containerLayout) {
+        //get the layout that preview icon belongs to.
+        previewLayout = dynamic_cast<QGraphicsLinearLayout*>(containerLayout->itemAt(1));
+    }
    
-    if(mPreviewIcon && mPreviewIcon == dynamic_cast<HbIconItem*>(previewLayout->itemAt(1)) ) {
-        previewLayout->removeAt(1);
+    if(previewLayout && mPreviewIcon && mPreviewIcon == dynamic_cast<HbIconItem*>(previewLayout->itemAt(0)) ) {
+        //Remove preview icon.
+        previewLayout->removeAt(0);
         
         if(orientation == Qt::Horizontal) {
             mPreviewIcon->setIcon(mTheme.landscapePreviewIcon());
+                    
         }
         else {
             mPreviewIcon->setIcon(mTheme.portraitPreviewIcon());
@@ -166,4 +196,6 @@
     }
     
 }
+
+