25 #include <hbaction.h> |
26 #include <hbaction.h> |
26 #include <hblabel.h> |
27 #include <hblabel.h> |
27 #include <hbiconitem.h> |
28 #include <hbiconitem.h> |
28 #include <hbmainwindow.h> |
29 #include <hbmainwindow.h> |
29 #include <HbParameterLengthLimiter> |
30 #include <HbParameterLengthLimiter> |
|
31 #include <HbDataForm> |
30 |
32 |
31 #include "cpthemepreview.h" |
33 #include "cpthemepreview.h" |
32 #include "cpthemeinfo.h" |
34 #include "cpthemeinfo.h" |
33 |
35 |
34 /*! |
36 /*! |
35 \class CpThemePreview |
37 \class CpThemePreview |
36 \brief CpThemePreview shows a preview of a selected theme with a heading displaying the name of the theme as well as |
38 \brief CpThemePreview shows a preview of a selected theme with a heading displaying the name of the theme as well as |
37 a toolbar with Select and Cancel buttons. This view is used for the user to either select the theme and apply |
39 a toolbar with Select and Cancel buttons. This view is used for the user to either select the theme and apply |
38 the theme change or press Cancel and go back to theme list view. |
40 the theme change or press Cancel and go back to theme list view. |
39 */ |
41 */ |
|
42 |
40 |
43 |
41 /*! |
44 /*! |
42 constructor. |
45 constructor. |
43 */ |
46 */ |
44 CpThemePreview::CpThemePreview(const CpThemeInfo& theme, QGraphicsItem *parent) : |
47 CpThemePreview::CpThemePreview(const CpThemeInfo& theme, QGraphicsItem *parent) : |
45 HbView(parent), |
48 HbView(parent), |
46 mTheme(theme), |
49 mTheme(theme), |
47 mSoftKeyBackAction(0), |
50 mSoftKeyBackAction(0), |
48 mPreviewIcon(0) |
51 mPreviewIcon(0) |
49 { |
52 { |
50 |
53 QGraphicsLinearLayout* containerLayout = new QGraphicsLinearLayout(Qt::Vertical); |
51 //Create the layout and add heading and and preview icon to the layout. |
54 QGraphicsLinearLayout* bottomLayout = new QGraphicsLinearLayout(Qt::Vertical); |
52 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical); |
55 |
53 |
56 //Preview icon margins. |
54 |
57 qreal leftMargin = 0.0; |
55 //setup the heading. |
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); |
56 QString themeHeading = HbParameterLengthLimiter("txt_cp_title_preview_1").arg(mTheme.name()); |
73 QString themeHeading = HbParameterLengthLimiter("txt_cp_title_preview_1").arg(mTheme.name()); |
57 HbLabel* label = new HbLabel(themeHeading, this); |
74 heading->setHeading(themeHeading); |
58 |
75 |
59 layout->addItem(label); |
76 containerLayout->addItem(heading); |
60 |
77 //Fixed vertical policy so that the heading doesn't expand. |
61 layout->setAlignment(layout->itemAt(0), Qt::AlignTop); |
78 heading->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,QSizePolicy::DefaultType); |
62 layout->itemAt(0)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,QSizePolicy::DefaultType); |
79 |
63 |
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 |
64 //Create the toolbar and "Select" and "Cancel" actions. |
99 //Create the toolbar and "Select" and "Cancel" actions. |
65 HbToolBar* mToolBar = new HbToolBar(this); |
100 HbToolBar* mToolBar = new HbToolBar(this); |
66 |
101 |
67 HbAction* selectAction = new HbAction(hbTrId("txt_common_button_select")); |
102 HbAction* selectAction = new HbAction(hbTrId("txt_common_button_select")); |
68 |
103 |
75 QObject::connect( selectAction, SIGNAL(triggered()), |
110 QObject::connect( selectAction, SIGNAL(triggered()), |
76 this, SLOT(themeSelected())); |
111 this, SLOT(themeSelected())); |
77 |
112 |
78 QObject::connect( cancelAction, SIGNAL(triggered()), |
113 QObject::connect( cancelAction, SIGNAL(triggered()), |
79 this, SIGNAL(aboutToClose())); |
114 this, SIGNAL(aboutToClose())); |
80 |
|
81 QObject::connect( mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
115 QObject::connect( mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
82 this, SLOT(previewOrientationChanged(Qt::Orientation))); |
116 this, SLOT(previewOrientationChanged(Qt::Orientation))); |
83 |
117 |
84 |
118 |
85 if(mainWindow()->orientation() == Qt::Horizontal) { |
|
86 mPreviewIcon = new HbIconItem(mTheme.landscapePreviewIcon(), this); |
|
87 } |
|
88 else { |
|
89 mPreviewIcon = new HbIconItem(mTheme.portraitPreviewIcon(), this); |
|
90 } |
|
91 layout->addItem(mPreviewIcon); |
|
92 layout->itemAt(1)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred,QSizePolicy::DefaultType); |
|
93 |
|
94 |
|
95 setToolBar(mToolBar); |
119 setToolBar(mToolBar); |
96 setLayout(layout); |
|
97 |
|
98 //Setup the Back button action and set softkey. Back button |
120 //Setup the Back button action and set softkey. Back button |
99 //takes the user to the theme list view. |
121 //takes the user to the theme list view. |
100 mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); |
122 mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this); |
101 QObject::connect(mSoftKeyBackAction, SIGNAL(triggered()), |
123 QObject::connect(mSoftKeyBackAction, SIGNAL(triggered()), |
102 this, SIGNAL(aboutToClose()) ); |
124 this, SIGNAL(aboutToClose()) ); |
103 |
125 |
104 setNavigationAction(mSoftKeyBackAction); |
126 setNavigationAction(mSoftKeyBackAction); |
|
127 |
105 } |
128 } |
106 |
129 |
107 /*! |
130 /*! |
108 destructor. |
131 destructor. |
109 */ |
132 */ |
120 } |
143 } |
121 |
144 |
122 /*! |
145 /*! |
123 returns the themeName. |
146 returns the themeName. |
124 */ |
147 */ |
125 const QString& CpThemePreview::themeName() const |
148 const QString CpThemePreview::themeName() const |
126 { |
149 { |
127 return mTheme.name(); |
150 return mTheme.name(); |
128 } |
151 } |
129 |
152 |
130 /*! |
153 /*! |
131 returns the repersentative themeIcon of the current theme. |
154 returns the repersentative themeIcon of the current theme. |
132 */ |
155 */ |
133 const HbIcon& CpThemePreview::themeIcon() const |
156 const HbIcon CpThemePreview::themeIcon() const |
134 { |
157 { |
135 return mTheme.icon(); |
158 return mTheme.icon(); |
136 } |
159 } |
137 |
160 |
138 /*! |
161 /*! |
139 Slot to handle when the user selects a theme. |
162 Slot to handle when the user selects a theme. |
140 */ |
163 */ |
141 void CpThemePreview::themeSelected() |
164 void CpThemePreview::themeSelected() |
142 { |
165 { |
143 emit applyTheme(mTheme.name()); |
166 emit applyTheme(mTheme); |
144 } |
167 } |
145 |
168 |
146 /*! |
169 /*! |
147 * Slot to handle landscape/portrait orientation change to use the |
170 * Slot to handle landscape/portrait orientation change to use the |
148 * right graphics. |
171 * right graphics. |
149 */ |
172 */ |
150 void CpThemePreview::previewOrientationChanged(Qt::Orientation orientation) |
173 void CpThemePreview::previewOrientationChanged(Qt::Orientation orientation) |
151 { |
174 { |
152 |
175 |
153 QGraphicsLinearLayout* previewLayout = dynamic_cast<QGraphicsLinearLayout*>(layout()); |
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 } |
154 |
182 |
155 if(mPreviewIcon && mPreviewIcon == dynamic_cast<HbIconItem*>(previewLayout->itemAt(1)) ) { |
183 if(previewLayout && mPreviewIcon && mPreviewIcon == dynamic_cast<HbIconItem*>(previewLayout->itemAt(0)) ) { |
156 previewLayout->removeAt(1); |
184 //Remove preview icon. |
|
185 previewLayout->removeAt(0); |
157 |
186 |
158 if(orientation == Qt::Horizontal) { |
187 if(orientation == Qt::Horizontal) { |
159 mPreviewIcon->setIcon(mTheme.landscapePreviewIcon()); |
188 mPreviewIcon->setIcon(mTheme.landscapePreviewIcon()); |
|
189 |
160 } |
190 } |
161 else { |
191 else { |
162 mPreviewIcon->setIcon(mTheme.portraitPreviewIcon()); |
192 mPreviewIcon->setIcon(mTheme.portraitPreviewIcon()); |
163 } |
193 } |
164 |
194 |
165 previewLayout->addItem(mPreviewIcon); |
195 previewLayout->addItem(mPreviewIcon); |
166 } |
196 } |
167 |
197 |
168 } |
198 } |
169 |
199 |
|
200 |
|
201 |