controlpanelplugins/themeplugin/src/cpthemepreview.cpp
changeset 19 36aa4756ee82
parent 12 624337f114fe
child 17 4a9568303383
child 21 2883a5458389
equal deleted inserted replaced
12:624337f114fe 19:36aa4756ee82
    16  */
    16  */
    17 
    17 
    18 #include <QString>
    18 #include <QString>
    19 #include <QGraphicsPixmapItem>
    19 #include <QGraphicsPixmapItem>
    20 #include <QGraphicsLinearLayout>
    20 #include <QGraphicsLinearLayout>
    21 
    21 #include <QDebug>
    22 #include <hbaction.h>
    22 #include <hbaction.h>
    23 #include <hbtoolbar.h>
    23 #include <hbtoolbar.h>
    24 #include <hbicon.h>
    24 #include <hbicon.h>
    25 #include <hbaction.h>
    25 #include <hbaction.h>
    26 #include <hblabel.h>
    26 #include <hblabel.h>
    40     constructor.
    40     constructor.
    41 */
    41 */
    42 CpThemePreview::CpThemePreview(const CpThemeChanger::ThemeInfo& theme, QGraphicsItem *parent) :
    42 CpThemePreview::CpThemePreview(const CpThemeChanger::ThemeInfo& theme, QGraphicsItem *parent) :
    43      HbView(parent), 
    43      HbView(parent), 
    44      mTheme(theme),
    44      mTheme(theme),
    45      mSoftKeyBackAction(0)
    45      mSoftKeyBackAction(0),
       
    46      mPreviewIcon(0)
    46 {
    47 {
    47     
    48     
    48     //Create the layout and add heading and and preview icon to the layout.
    49     //Create the layout and add heading and and preview icon to the layout.
    49     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
    50     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
    50 
    51 
    75     QObject::connect( selectAction, SIGNAL(triggered()), 
    76     QObject::connect( selectAction, SIGNAL(triggered()), 
    76                       this, SLOT(themeSelected()));
    77                       this, SLOT(themeSelected()));
    77 
    78 
    78     QObject::connect( cancelAction, SIGNAL(triggered()), 
    79     QObject::connect( cancelAction, SIGNAL(triggered()), 
    79                       this, SIGNAL(aboutToClose()));
    80                       this, SIGNAL(aboutToClose()));
    80 
    81     
    81     HbIconItem* layoutItem;
    82     QObject::connect( mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
    82     //layout->addItem(&HbIconItem(mTheme.icon, this ));
    83                       this, SLOT(previewOrientationChanged(Qt::Orientation)));
       
    84        
       
    85    
    83     if(mainWindow()->orientation() == Qt::Horizontal) {
    86     if(mainWindow()->orientation() == Qt::Horizontal) {
    84         layoutItem = new HbIconItem(mTheme.landscapePreviewIcon, this);
    87         mPreviewIcon = new HbIconItem(mTheme.landscapePreviewIcon, this);
    85     }
    88     }
    86     else {
    89     else {
    87         layoutItem = new HbIconItem(mTheme.portraitPreviewIcon, this);
    90         mPreviewIcon = new HbIconItem(mTheme.portraitPreviewIcon, this);
    88     }
    91     }
    89     layout->addItem(layoutItem);
    92     layout->addItem(mPreviewIcon);
    90     layout->setAlignment(layout->itemAt(0), Qt::AlignTop);
    93     layout->setAlignment(layout->itemAt(0), Qt::AlignTop);
    91     
    94     
    92     setToolBar(mToolBar);
    95     setToolBar(mToolBar);
    93     setLayout(layout);
    96     setLayout(layout);
    94 
    97 
    95     //Setup the Back button action and set softkey. Back button 
    98     //Setup the Back button action and set softkey. Back button 
    96     //takes the user to the theme list view.
    99     //takes the user to the theme list view.
    97     mSoftKeyBackAction = new HbAction(Hb::BackAction, this);
   100     mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
    98     QObject::connect(mSoftKeyBackAction, SIGNAL(triggered()), 
   101     QObject::connect(mSoftKeyBackAction, SIGNAL(triggered()), 
    99             this, SIGNAL(aboutToClose()) );
   102             this, SIGNAL(aboutToClose()) );
   100 
   103 
   101     this->setNavigationAction(mSoftKeyBackAction);
   104     this->setNavigationAction(mSoftKeyBackAction);
   102 }
   105 }
   138 void CpThemePreview::themeSelected()
   141 void CpThemePreview::themeSelected()
   139 {
   142 {
   140     emit applyTheme(mTheme.name);
   143     emit applyTheme(mTheme.name);
   141 }
   144 }
   142 
   145 
       
   146 /*! 
       
   147  *  Slot to handle landscape/portrait orientation change to use the
       
   148  *  right graphics.
       
   149  */
       
   150 void CpThemePreview::previewOrientationChanged(Qt::Orientation orientation)
       
   151 {
       
   152    
       
   153     QGraphicsLinearLayout* previewLayout = dynamic_cast<QGraphicsLinearLayout*>(layout());
       
   154    
       
   155     if(mPreviewIcon == dynamic_cast<HbIconItem*>(previewLayout->itemAt(1)) ) {
       
   156         previewLayout->removeAt(1);
       
   157         delete mPreviewIcon;
       
   158         mPreviewIcon = 0;
       
   159         
       
   160         if(orientation == Qt::Horizontal) {
       
   161             mPreviewIcon = new HbIconItem(mTheme.landscapePreviewIcon, this);
       
   162         }
       
   163         else {
       
   164             mPreviewIcon = new HbIconItem(mTheme.portraitPreviewIcon, this);
       
   165         }
       
   166         
       
   167         previewLayout->addItem(mPreviewIcon);
       
   168     }
       
   169     
       
   170 }
       
   171