16 */ |
16 */ |
17 |
17 |
18 #include <QString> |
18 #include <QString> |
19 #include <QGraphicsPixmapItem> |
19 #include <QGraphicsPixmapItem> |
20 #include <QGraphicsLinearLayout> |
20 #include <QGraphicsLinearLayout> |
21 #include <QDebug> |
21 |
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> |
27 #include <hbiconitem.h> |
27 #include <hbiconitem.h> |
28 #include <hbmainwindow.h> |
28 #include <hbmainwindow.h> |
|
29 #include <HbParameterLengthLimiter> |
29 |
30 |
30 #include "cpthemepreview.h" |
31 #include "cpthemepreview.h" |
|
32 #include "cpthemeinfo.h" |
31 |
33 |
32 /*! |
34 /*! |
33 \class CpThemePreview |
35 \class CpThemePreview |
34 \brief CpThemePreview shows a preview of a selected theme with a heading displaying the name of the theme as well as |
36 \brief CpThemePreview shows a preview of a selected theme with a heading displaying the name of the theme as well as |
35 a toolbar with Select and Cancel buttons. This view is used for the user to either select the theme and apply |
37 a toolbar with Select and Cancel buttons. This view is used for the user to either select the theme and apply |
49 //Create the layout and add heading and and preview icon to the layout. |
51 //Create the layout and add heading and and preview icon to the layout. |
50 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical); |
52 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical); |
51 |
53 |
52 |
54 |
53 //setup the heading. |
55 //setup the heading. |
54 //TODO: translation of string hbTrId("txt_cp_title_preview_1") |
56 QString themeHeading = HbParameterLengthLimiter("txt_cp_title_preview_1").arg(mTheme.name()); |
55 |
|
56 QString themeHeading = tr("Preview: ") + mTheme.name; |
|
57 HbLabel* label = new HbLabel(themeHeading, this); |
57 HbLabel* label = new HbLabel(themeHeading, this); |
58 label->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
59 |
58 |
60 label->setPreferredHeight(5.0); |
|
61 layout->addItem(label); |
59 layout->addItem(label); |
62 |
60 |
63 layout->setAlignment(layout->itemAt(0), Qt::AlignTop); |
61 layout->setAlignment(layout->itemAt(0), Qt::AlignTop); |
|
62 layout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,QSizePolicy::DefaultType); |
64 |
63 |
65 //Create the toolbar and "Select" and "Cancel" actions. |
64 //Create the toolbar and "Select" and "Cancel" actions. |
66 HbToolBar* mToolBar = new HbToolBar(this); |
65 HbToolBar* mToolBar = new HbToolBar(this); |
67 |
66 |
68 HbAction* selectAction = new HbAction(tr("Select")); |
67 HbAction* selectAction = new HbAction(hbTrId("txt_common_button_select")); |
69 |
68 |
70 //Add Action to the toolbar and show toolbar |
69 //Add Action to the toolbar and show toolbar |
71 mToolBar->addAction( selectAction ); |
70 mToolBar->addAction( selectAction ); |
72 |
71 |
73 HbAction* cancelAction = new HbAction(tr("Cancel")); |
72 HbAction* cancelAction = new HbAction(hbTrId("txt_common_button_cancel")); |
74 mToolBar->addAction( cancelAction ); |
73 mToolBar->addAction( cancelAction ); |
75 |
74 |
76 QObject::connect( selectAction, SIGNAL(triggered()), |
75 QObject::connect( selectAction, SIGNAL(triggered()), |
77 this, SLOT(themeSelected())); |
76 this, SLOT(themeSelected())); |
78 |
77 |
82 QObject::connect( mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
81 QObject::connect( mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
83 this, SLOT(previewOrientationChanged(Qt::Orientation))); |
82 this, SLOT(previewOrientationChanged(Qt::Orientation))); |
84 |
83 |
85 |
84 |
86 if(mainWindow()->orientation() == Qt::Horizontal) { |
85 if(mainWindow()->orientation() == Qt::Horizontal) { |
87 mPreviewIcon = new HbIconItem(mTheme.landscapePreviewIcon, this); |
86 mPreviewIcon = new HbIconItem(mTheme.landscapePreviewIcon(), this); |
88 } |
87 } |
89 else { |
88 else { |
90 mPreviewIcon = new HbIconItem(mTheme.portraitPreviewIcon, this); |
89 mPreviewIcon = new HbIconItem(mTheme.portraitPreviewIcon(), this); |
91 } |
90 } |
92 layout->addItem(mPreviewIcon); |
91 layout->addItem(mPreviewIcon); |
93 layout->setAlignment(layout->itemAt(0), Qt::AlignTop); |
92 layout->itemAt(1)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred,QSizePolicy::DefaultType); |
94 |
93 |
|
94 |
95 setToolBar(mToolBar); |
95 setToolBar(mToolBar); |
96 setLayout(layout); |
96 setLayout(layout); |
97 |
97 |
98 //Setup the Back button action and set softkey. Back button |
98 //Setup the Back button action and set softkey. Back button |
99 //takes the user to the theme list view. |
99 //takes the user to the theme list view. |
100 mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); |
100 mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); |
101 QObject::connect(mSoftKeyBackAction, SIGNAL(triggered()), |
101 QObject::connect(mSoftKeyBackAction, SIGNAL(triggered()), |
102 this, SIGNAL(aboutToClose()) ); |
102 this, SIGNAL(aboutToClose()) ); |
103 |
103 |
104 this->setNavigationAction(mSoftKeyBackAction); |
104 setNavigationAction(mSoftKeyBackAction); |
105 } |
105 } |
106 |
106 |
107 /*! |
107 /*! |
108 destructor. |
108 destructor. |
109 */ |
109 */ |
112 } |
112 } |
113 |
113 |
114 /*! |
114 /*! |
115 sets the theme to \a theme. |
115 sets the theme to \a theme. |
116 */ |
116 */ |
117 void CpThemePreview::setThemeInfo(const CpThemeChanger::ThemeInfo& theme) |
117 void CpThemePreview::setThemeInfo(const CpThemeInfo& theme) |
118 { |
118 { |
119 mTheme = theme; |
119 mTheme = theme; |
120 } |
120 } |
121 |
121 |
122 /*! |
122 /*! |
123 returns the themeName. |
123 returns the themeName. |
124 */ |
124 */ |
125 const QString& CpThemePreview::themeName() const |
125 const QString& CpThemePreview::themeName() const |
126 { |
126 { |
127 return mTheme.name; |
127 return mTheme.name(); |
128 } |
128 } |
129 |
129 |
130 /*! |
130 /*! |
131 returns the repersentative themeIcon of the current theme. |
131 returns the repersentative themeIcon of the current theme. |
132 */ |
132 */ |
133 const HbIcon& CpThemePreview::themeIcon() const |
133 const HbIcon& CpThemePreview::themeIcon() const |
134 { |
134 { |
135 return mTheme.icon; |
135 return mTheme.icon(); |
136 } |
136 } |
137 |
137 |
138 /*! |
138 /*! |
139 Slot to handle when the user selects a theme. |
139 Slot to handle when the user selects a theme. |
140 */ |
140 */ |
141 void CpThemePreview::themeSelected() |
141 void CpThemePreview::themeSelected() |
142 { |
142 { |
143 emit applyTheme(mTheme.name); |
143 emit applyTheme(mTheme.name()); |
144 } |
144 } |
145 |
145 |
146 /*! |
146 /*! |
147 * Slot to handle landscape/portrait orientation change to use the |
147 * Slot to handle landscape/portrait orientation change to use the |
148 * right graphics. |
148 * right graphics. |
150 void CpThemePreview::previewOrientationChanged(Qt::Orientation orientation) |
150 void CpThemePreview::previewOrientationChanged(Qt::Orientation orientation) |
151 { |
151 { |
152 |
152 |
153 QGraphicsLinearLayout* previewLayout = dynamic_cast<QGraphicsLinearLayout*>(layout()); |
153 QGraphicsLinearLayout* previewLayout = dynamic_cast<QGraphicsLinearLayout*>(layout()); |
154 |
154 |
155 if(mPreviewIcon == dynamic_cast<HbIconItem*>(previewLayout->itemAt(1)) ) { |
155 if(mPreviewIcon && mPreviewIcon == dynamic_cast<HbIconItem*>(previewLayout->itemAt(1)) ) { |
156 previewLayout->removeAt(1); |
156 previewLayout->removeAt(1); |
157 delete mPreviewIcon; |
|
158 mPreviewIcon = 0; |
|
159 |
157 |
160 if(orientation == Qt::Horizontal) { |
158 if(orientation == Qt::Horizontal) { |
161 mPreviewIcon = new HbIconItem(mTheme.landscapePreviewIcon, this); |
159 mPreviewIcon->setIcon(mTheme.landscapePreviewIcon()); |
162 } |
160 } |
163 else { |
161 else { |
164 mPreviewIcon = new HbIconItem(mTheme.portraitPreviewIcon, this); |
162 mPreviewIcon->setIcon(mTheme.portraitPreviewIcon()); |
165 } |
163 } |
166 |
164 |
167 previewLayout->addItem(mPreviewIcon); |
165 previewLayout->addItem(mPreviewIcon); |
168 } |
166 } |
169 |
167 |