|
1 /*! |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Custom button style |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbicon.h> |
|
19 #include <hbstyleoptionpushbutton.h> |
|
20 #include <hbframeitem.h> |
|
21 #include <hbframedrawer.h> |
|
22 #include <hbiconitem.h> |
|
23 #include <hbtextitem.h> |
|
24 #include <hbcolorscheme.h> |
|
25 #include "dialpadbuttonstyle.h" |
|
26 |
|
27 DialpadButtonStyle::DialpadButtonStyle() |
|
28 : mButtonStyle(NormalButtonStyle) |
|
29 { |
|
30 } |
|
31 |
|
32 DialpadButtonStyle::~DialpadButtonStyle() |
|
33 { |
|
34 } |
|
35 |
|
36 void DialpadButtonStyle::updatePrimitive( |
|
37 QGraphicsItem *item, |
|
38 HbStyle::Primitive primitive, |
|
39 const QStyleOption *option ) const |
|
40 { |
|
41 switch(primitive){ |
|
42 case P_PushButton_background:{ |
|
43 const HbStyleOptionPushButton *opt = |
|
44 qstyleoption_cast<const HbStyleOptionPushButton *>(option); |
|
45 HbFrameItem *frameItem = qgraphicsitem_cast<HbFrameItem*>( item ); |
|
46 if(!frameItem) |
|
47 return; |
|
48 |
|
49 frameItem->setZValue(-1.0); |
|
50 if(opt->backgroundFrameDrawer &&!(opt->backgroundFrameDrawer->isNull())) { |
|
51 frameItem->setFrameDrawer( (opt->backgroundFrameDrawer)); |
|
52 } else { |
|
53 QString frameGraphicsName; |
|
54 QIcon::Mode mode = QIcon::Disabled; |
|
55 QIcon::State state = QIcon::Off; |
|
56 if (opt->state & QStyle::State_Enabled) |
|
57 mode = QIcon::Normal; |
|
58 if (opt->state & QStyle::State_Active) |
|
59 mode = QIcon::Active; |
|
60 if (opt->state & QStyle::State_Selected) |
|
61 mode = QIcon::Selected; |
|
62 if (opt->state & QStyle::State_On) |
|
63 state = QIcon::On; |
|
64 |
|
65 if (mode == QIcon::Disabled && state == QIcon::Off) { |
|
66 frameGraphicsName = "qtg_fr_btn_disabled"; |
|
67 } else if (mode == QIcon::Normal && state == QIcon::On) { |
|
68 if (mButtonStyle==CallButtonStyle) { |
|
69 frameGraphicsName = ":/qtg_fr_btn_green_pressed"; |
|
70 } else if (mButtonStyle==NormalButtonStyle) { |
|
71 frameGraphicsName = "qtg_fr_button_keypad_pressed"; |
|
72 } else { |
|
73 frameGraphicsName = "qtg_fr_button_function_pressed"; |
|
74 } |
|
75 } else if (mode == QIcon::Selected && state == QIcon::Off) { |
|
76 frameGraphicsName = "qtg_fr_btn_highlight"; |
|
77 } else { |
|
78 if (mButtonStyle==CallButtonStyle) { |
|
79 frameGraphicsName = ":/qtg_fr_btn_green_normal"; |
|
80 } else if (mButtonStyle==NormalButtonStyle) { |
|
81 frameGraphicsName = "qtg_fr_button_keypad_normal"; |
|
82 } else { |
|
83 frameGraphicsName = "qtg_fr_button_function_normal"; |
|
84 } |
|
85 } |
|
86 |
|
87 frameItem->frameDrawer().setFrameGraphicsName(frameGraphicsName); |
|
88 if (!opt->background.isNull()) { |
|
89 QString customName = opt->background.iconName(mode, state); |
|
90 frameItem->frameDrawer().setFrameGraphicsName(customName); |
|
91 frameItem->setGeometry(opt->rect); |
|
92 frameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
93 break; |
|
94 } |
|
95 frameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
96 } |
|
97 |
|
98 frameItem->setGeometry(opt->rect); |
|
99 break; |
|
100 } |
|
101 |
|
102 case P_PushButton_icon: { |
|
103 HbStyle::updatePrimitive(item,primitive,option); |
|
104 |
|
105 // override color (todo: via css, when supported by fw) |
|
106 const HbStyleOptionPushButton *opt = |
|
107 qstyleoption_cast<const HbStyleOptionPushButton *>(option); |
|
108 QIcon::Mode mode = QIcon::Disabled; |
|
109 QIcon::State state = QIcon::Off; |
|
110 if (opt->state & QStyle::State_Enabled) |
|
111 mode = QIcon::Normal; |
|
112 if (opt->state & QStyle::State_On) |
|
113 state = QIcon::On; |
|
114 |
|
115 if (mButtonStyle==CallButtonStyle && |
|
116 mode == QIcon::Normal) { |
|
117 if (state==QIcon::On) { |
|
118 QColor color(HbColorScheme::color("answer_pressed")); |
|
119 setIconColor(item,color); |
|
120 } else { |
|
121 QColor color(HbColorScheme::color("answer_normal")); |
|
122 setIconColor(item,color); |
|
123 } |
|
124 } else if (mButtonStyle==NormalButtonStyle) { |
|
125 QColor color; |
|
126 color = HbColorScheme::color("input_button_normal"); |
|
127 setIconColor(item,color); |
|
128 } else { // function button |
|
129 QColor color; |
|
130 color = HbColorScheme::color("input_function_normal"); |
|
131 setIconColor(item,color); |
|
132 } |
|
133 break; |
|
134 } |
|
135 |
|
136 case P_PushButton_text: { |
|
137 HbStyle::updatePrimitive(item,primitive,option); |
|
138 // override color (todo: via css, when supported by fw) |
|
139 setTextColor(item); |
|
140 break; |
|
141 } |
|
142 |
|
143 case P_PushButton_additionaltext: { |
|
144 HbStyle::updatePrimitive(item,primitive,option); |
|
145 // override color (todo: via css, when supported by fw) |
|
146 setTextColor(item); |
|
147 break; |
|
148 } |
|
149 |
|
150 default: |
|
151 HbStyle::updatePrimitive(item,primitive,option); |
|
152 break; |
|
153 } // switch |
|
154 } |
|
155 |
|
156 void DialpadButtonStyle::setButtonStyle(ButtonStyle style) |
|
157 { |
|
158 mButtonStyle = style; |
|
159 } |
|
160 |
|
161 void DialpadButtonStyle::setTextColor(QGraphicsItem *item) const |
|
162 { |
|
163 HbTextItem *textPrim = qgraphicsitem_cast<HbTextItem*>(item); |
|
164 if (textPrim) { |
|
165 QColor color; |
|
166 color = HbColorScheme::color("input_button_normal"); |
|
167 if (color.isValid()) { |
|
168 textPrim->setTextColor(color); |
|
169 } else { |
|
170 textPrim->setTextColor(Qt::black); |
|
171 } |
|
172 } |
|
173 } |
|
174 |
|
175 void DialpadButtonStyle::setIconColor( |
|
176 QGraphicsItem *item, |
|
177 const QColor &color ) const |
|
178 { |
|
179 HbIconItem *iconItem = qgraphicsitem_cast<HbIconItem*>(item); |
|
180 |
|
181 if (iconItem) { |
|
182 if (color.isValid()) { |
|
183 iconItem->setColor(color); |
|
184 } else { |
|
185 iconItem->setColor(Qt::black); |
|
186 } |
|
187 } |
|
188 } |