|
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 HbInput 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 #include <QGraphicsScene> |
|
26 #include <QGraphicsSceneMouseEvent> |
|
27 #include <hbcolorscheme.h> |
|
28 #include "hbinputpreviewlabel.h" |
|
29 #include "hbfontspec.h" |
|
30 |
|
31 /*! |
|
32 \fn void HbPreviewLabel::selected() |
|
33 |
|
34 This signal is emitted when there is a mouse press event. |
|
35 */ |
|
36 |
|
37 /*! |
|
38 Constructor. |
|
39 @param previewSymbols The string of the label and parent Graphics Item. |
|
40 */ |
|
41 HbPreviewLabel::HbPreviewLabel(QString previewSymbols, QGraphicsItem *parent) |
|
42 :HbWidget(parent), |
|
43 mTextItem(0) |
|
44 { |
|
45 mTextItem = static_cast<HbTextItem*>(this->style()->createPrimitive(HbStyle::P_Label_text, this)); |
|
46 mTextItem->setText(previewSymbols); |
|
47 mTextItem->setAlignment(Qt::AlignCenter); |
|
48 mTextItem->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
49 } |
|
50 |
|
51 /*! |
|
52 Destroy the object |
|
53 */ |
|
54 HbPreviewLabel::~HbPreviewLabel() |
|
55 { |
|
56 } |
|
57 |
|
58 /*! |
|
59 sets geometry of textItem |
|
60 @param itemsize the Geometry of Button. |
|
61 */ |
|
62 void HbPreviewLabel::setTextGeometry(qreal width, qreal height) |
|
63 { |
|
64 QColor color = HbColorScheme::color("qtc_editor_normal"); |
|
65 QRectF rect; |
|
66 rect.setWidth(width/2); |
|
67 rect.setHeight(height); |
|
68 if (color.isValid()) { |
|
69 mTextItem->setTextColor(color); |
|
70 } |
|
71 mTextItem->setGeometry(rect); |
|
72 } |
|
73 |
|
74 /*! |
|
75 This function handles the mouse press event. |
|
76 @param event The mouse events in the graphics view framework. |
|
77 */ |
|
78 void HbPreviewLabel::mousePressEvent(QGraphicsSceneMouseEvent * event) |
|
79 { |
|
80 Q_UNUSED(event); |
|
81 emit showAccentedPreview(mTextItem->text(),sceneBoundingRect()); |
|
82 } |
|
83 |
|
84 /*! |
|
85 This function handles the mouse move event. |
|
86 @param event The mouse events in the graphics view framework. |
|
87 |
|
88 In case of a key/touch movement will activate a mousePressEvent on another Label |
|
89 and the next Label is set as the grabber item. |
|
90 */ |
|
91 void HbPreviewLabel::mouseMoveEvent(QGraphicsSceneMouseEvent * event) |
|
92 { |
|
93 bool transfered = false; |
|
94 if (!isUnderMouse()) { |
|
95 // get the list of item's at current mouse position |
|
96 QList<QGraphicsItem *> list = scene()->items(event->scenePos()); |
|
97 for (int i =0; i < list.count(); i++) { |
|
98 // let's check if we have HbPreviewLabel |
|
99 HbPreviewLabel *label = hbpreviewlabel_cast(list.at(i)); |
|
100 if (label && label->isEnabled() && (label->parent() == parent())) { |
|
101 // release old label |
|
102 ungrabMouse(); |
|
103 event->setButton(Qt::LeftButton); |
|
104 // now call the mousepressEvent function of the Label under mouse |
|
105 QGraphicsSceneMouseEvent pressEvent; |
|
106 pressEvent.setButton(Qt::LeftButton); |
|
107 label->mousePressEvent(&pressEvent); |
|
108 // now to make label under cursor to get mouse events we have to manually make that Label |
|
109 // a mouse grabber item. after this Label will start recieving the press movements. |
|
110 label->grabMouse(); |
|
111 transfered = true; |
|
112 break; |
|
113 } |
|
114 } |
|
115 QRectF rect = boundingRect(); |
|
116 QPointF pos = event->pos(); |
|
117 if (!transfered && (pos.y() < 0 ||pos.y() > rect.height() || pos.x() > rect.width() || pos.x() < 0) ) { |
|
118 emit hideAccentedPreview(); |
|
119 } |
|
120 } |
|
121 if (!transfered) { |
|
122 if (isUnderMouse()) { |
|
123 QGraphicsSceneMouseEvent pressEvent; |
|
124 pressEvent.setButton(Qt::LeftButton); |
|
125 HbPreviewLabel::mousePressEvent(&pressEvent); |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 /*! |
|
131 This function handles the mouse release event. |
|
132 @param event The mouse events in the graphics view framework. |
|
133 |
|
134 emits the signal selected to input the corrosponding character mapped to the key whenever |
|
135 a key is released and afterwards hides the PreviewPopup by emiitting hidePreview |
|
136 */ |
|
137 void HbPreviewLabel::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) |
|
138 { |
|
139 Q_UNUSED(event); |
|
140 if (isUnderMouse()) { |
|
141 emit selected(); |
|
142 } |
|
143 emit hidePreview(); |
|
144 ungrabMouse(); |
|
145 } |
|
146 |
|
147 // End Of File |