14 * Description: Message editor header widget |
14 * Description: Message editor header widget |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "nmailuiwidgetsheaders.h" |
18 #include "nmailuiwidgetsheaders.h" |
|
19 |
|
20 static const int NmLabelIndentUsePreviousValue = 0; |
|
21 |
19 /* |
22 /* |
20 #include "nmhtmllineedit.h" |
23 #include "nmhtmllineedit.h" |
21 */ |
24 */ |
22 /*! |
25 /*! |
23 Constructor |
26 Constructor |
24 */ |
27 */ |
25 NmHtmlLineEdit::NmHtmlLineEdit(QGraphicsItem *parent) : |
28 NmHtmlLineEdit::NmHtmlLineEdit(QGraphicsItem *parent) : |
26 HbLineEdit(parent) |
29 HbLineEdit(parent), |
|
30 mIndent(0) |
27 { |
31 { |
28 NM_FUNCTION; |
32 NM_FUNCTION; |
29 |
33 |
30 // Disable scrolling so that baunch effect works correctly |
34 // Disable scrolling so that baunch effect works correctly |
31 HbAbstractEdit::setScrollable(false); |
35 HbAbstractEdit::setScrollable(false); |
122 return ret; |
130 return ret; |
123 } |
131 } |
124 |
132 |
125 |
133 |
126 /*! |
134 /*! |
127 * Returns the rectangle for the cursor. |
135 * Returns the rectangle for the cursor including the predictive text area. |
|
136 * HbAbstractEditPrivate::ensurePositionVisible() uses the same algorithm. |
128 */ |
137 */ |
129 QRectF NmHtmlLineEdit::rectForCursorPosition() const |
138 QRectF NmHtmlLineEdit::rectForCursorPosition() const |
130 { |
139 { |
131 NM_FUNCTION; |
140 NM_FUNCTION; |
132 |
141 |
133 return HbLineEdit::rectForPosition(cursorPosition()); |
142 int cursorPos = cursorPosition(); |
|
143 QRectF rect = rectForPosition(cursorPos); |
|
144 QTextDocument *doc = document(); |
|
145 if (doc) { |
|
146 rect.adjust(0, -doc->documentMargin(), 0, doc->documentMargin()); |
|
147 const QTextBlock block = doc->findBlock(cursorPos); |
|
148 QTextLayout *blockLayout = block.layout(); |
|
149 if (block.isValid() && blockLayout) { |
|
150 if (blockLayout->preeditAreaText().length()) { |
|
151 // Adjust cursor rect so that predictive text will be also visible |
|
152 rect.adjust(0, 0, boundingRect().width() / 2, 0); |
|
153 } |
|
154 } |
|
155 } |
|
156 |
|
157 return rect; |
134 } |
158 } |
|
159 |
|
160 /*! |
|
161 Set margin for the first line. This will create empty space |
|
162 into begining of the edit field to reserve enough space for the |
|
163 label text e.g. 'To:'. |
|
164 */ |
|
165 void NmHtmlLineEdit::setIndentForLabel(const qreal indent) |
|
166 { |
|
167 NM_FUNCTION; |
|
168 |
|
169 // Check that should we use previous value or set new value. |
|
170 // Previous value is used when edit field content is changed. |
|
171 if (indent != NmLabelIndentUsePreviousValue) { |
|
172 mIndent = indent; |
|
173 } |
|
174 QTextCursor cursor(this->document()); |
|
175 cursor.select(QTextCursor::BlockUnderCursor); |
|
176 QTextBlockFormat format; |
|
177 format.setTextIndent(mIndent); |
|
178 cursor.mergeBlockFormat(format); |
|
179 } |
|
180 |