|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include <hbstyleoptionnotificationdialog.h> |
|
27 #include <hbdeviceprofile.h> |
|
28 |
|
29 #include "hbnotificationdialogcontent_p.h" |
|
30 |
|
31 HbNotificationDialogContent::HbNotificationDialogContent(QGraphicsWidget *parent) : |
|
32 HbWidget(parent), mTitleWrapping(Hb::TextNoWrap), |
|
33 mIsTouchActivating(false), mTextItem(0), mTitleItem(0), mIconItem(0) |
|
34 { |
|
35 } |
|
36 |
|
37 void HbNotificationDialogContent::setIcon(const HbIcon &icon) |
|
38 { |
|
39 if(!mIconItem) { |
|
40 mIconItem = style()->createPrimitive( |
|
41 HbStyle::P_NotificationDialog_icon, this); |
|
42 Q_CHECK_PTR(mIconItem); |
|
43 } |
|
44 mIcon = icon; |
|
45 updatePrimitives(); |
|
46 polishEvent(); |
|
47 } |
|
48 |
|
49 void HbNotificationDialogContent::setText(const QString &text) |
|
50 { |
|
51 if(!mTextItem) { |
|
52 mTextItem = style()->createPrimitive( |
|
53 HbStyle::P_NotificationDialog_text, this); |
|
54 Q_CHECK_PTR(mTextItem); |
|
55 } |
|
56 mText = text; |
|
57 updatePrimitives(); |
|
58 polishEvent(); |
|
59 } |
|
60 |
|
61 void HbNotificationDialogContent::setTitle(const QString &title) |
|
62 { |
|
63 if(!mTitleItem) { |
|
64 mTitleItem = style()->createPrimitive( |
|
65 HbStyle::P_NotificationDialog_title, this); |
|
66 Q_CHECK_PTR(mTitleItem); |
|
67 } |
|
68 |
|
69 mTitle = title; |
|
70 updatePrimitives(); |
|
71 polishEvent(); |
|
72 } |
|
73 |
|
74 void HbNotificationDialogContent::setTitleTextWrapping(Hb::TextWrapping wrapping) |
|
75 { |
|
76 if (mTitleWrapping != wrapping) { |
|
77 mTitleWrapping = wrapping; |
|
78 updatePrimitives(); |
|
79 polishEvent(); |
|
80 } |
|
81 } |
|
82 |
|
83 Hb::TextWrapping HbNotificationDialogContent::titleTextWrapping() const |
|
84 { |
|
85 return mTitleWrapping; |
|
86 } |
|
87 |
|
88 void HbNotificationDialogContent::enableTouchActivation(bool enabled) |
|
89 { |
|
90 if (mIsTouchActivating != enabled) { |
|
91 mIsTouchActivating = enabled; |
|
92 updatePrimitives(); |
|
93 } |
|
94 } |
|
95 |
|
96 bool HbNotificationDialogContent::isTouchActivating() const |
|
97 { |
|
98 return mIsTouchActivating; |
|
99 } |
|
100 |
|
101 void HbNotificationDialogContent::polish( HbStyleParameters& params ) |
|
102 { |
|
103 HbStyleOptionNotificationDialog option; |
|
104 initStyleOption(&option); |
|
105 int textFields(0); |
|
106 bool iconSet(!option.icon.isNull()); |
|
107 |
|
108 // Check that content is filled properly |
|
109 if (!mTitleItem) { |
|
110 qWarning("HbNotificationDialog Warning: Title not set"); |
|
111 setTitle(QString("")); |
|
112 } |
|
113 |
|
114 if (option.title.isEmpty()) { |
|
115 if (!option.text.isEmpty()) { |
|
116 textFields = 2; //secondary text (uses: primary + secondary text.) |
|
117 } else if (iconSet) { |
|
118 textFields = 1; |
|
119 } |
|
120 } else if (option.text.isEmpty()) { |
|
121 textFields = 1; // primary text |
|
122 } else { |
|
123 textFields = 2; // primary + secondary text |
|
124 } |
|
125 setProperty("icon", iconSet); |
|
126 setProperty("textFields", textFields); |
|
127 setProperty("link", option.isLink); |
|
128 setProperty("titleWrapping", option.titleWrapping); |
|
129 HbWidget::polish(params); |
|
130 } |
|
131 |
|
132 void HbNotificationDialogContent::initStyleOption(HbStyleOptionNotificationDialog *option) const |
|
133 { |
|
134 HbWidget::initStyleOption(option); |
|
135 option->title = mTitle; |
|
136 option->text = mText; |
|
137 option->icon = mIcon; |
|
138 option->textWrapping = Hb::TextNoWrap; |
|
139 option->titleWrapping = mTitleWrapping; |
|
140 option->wrappingText = Hb::TextNoWrap; |
|
141 option->wrappingTitle = mTitleWrapping; |
|
142 option->isLink = mIsTouchActivating; |
|
143 } |
|
144 |
|
145 QSizeF HbNotificationDialogContent::sizeHint( |
|
146 Qt::SizeHint which, const QSizeF & constraint) const |
|
147 { |
|
148 switch(which) { |
|
149 case Qt::PreferredSize: { |
|
150 QSizeF preferred = HbWidget::sizeHint(which, constraint); |
|
151 HbDeviceProfile dp(HbDeviceProfile::profile(this)); |
|
152 int widthInPixels = (dp.orientation() == Qt::Vertical) |
|
153 ? dp.logicalSize().width() |
|
154 : dp.logicalSize().height(); |
|
155 |
|
156 //width is always portrait screen width - 9un. |
|
157 preferred.setWidth(widthInPixels - dp.unitValue() * 9 ); |
|
158 return preferred; |
|
159 } |
|
160 default: |
|
161 break; |
|
162 } |
|
163 return HbWidget::sizeHint(which, constraint); |
|
164 } |
|
165 |
|
166 void HbNotificationDialogContent::updatePrimitives() |
|
167 { |
|
168 HbStyleOptionNotificationDialog option; |
|
169 initStyleOption(&option); |
|
170 |
|
171 if(mTextItem) { |
|
172 style()->updatePrimitive(mTextItem, |
|
173 HbStyle::P_NotificationDialog_text, &option); |
|
174 } |
|
175 if(mTitleItem) { |
|
176 style()->updatePrimitive(mTitleItem, |
|
177 HbStyle::P_NotificationDialog_title, &option); |
|
178 } |
|
179 if (!mIcon.isNull()) { |
|
180 style()->updatePrimitive(mIconItem, |
|
181 HbStyle::P_NotificationDialog_icon, &option); |
|
182 } |
|
183 } |