29 #endif |
29 #endif |
30 |
30 |
31 #include "EditorWidget.h" |
31 #include "EditorWidget.h" |
32 #include "Utilities.h" |
32 #include "Utilities.h" |
33 #include "ChromeEffect.h" |
33 #include "ChromeEffect.h" |
|
34 #include "qstmgestureevent.h" |
|
35 |
|
36 |
34 |
37 |
35 // FIXME ;;; Must address the following issues: |
38 // FIXME ;;; Must address the following issues: |
36 // |
39 // |
37 // * Clean ORBIT_UI flag by creating new class for orbit ui |
40 // * Clean ORBIT_UI flag by creating new class for orbit ui |
38 // * Replace QGraphicsTextItem with HbTextItem for orbit ui |
41 // * Replace QGraphicsTextItem with HbTextItem for orbit ui |
48 GTextLineItem::GTextLineItem(QGraphicsItem * parent) |
51 GTextLineItem::GTextLineItem(QGraphicsItem * parent) |
49 : QGraphicsTextItem(parent) |
52 : QGraphicsTextItem(parent) |
50 , m_maxTextLength(0) |
53 , m_maxTextLength(0) |
51 , m_hints(Qt::ImhNoPredictiveText) // disable the predictive text |
54 , m_hints(Qt::ImhNoPredictiveText) // disable the predictive text |
52 , m_setSpecificBtn(false) |
55 , m_setSpecificBtn(false) |
|
56 , m_isContextMenuOn(false) |
53 { |
57 { |
54 // Disable wrapping, force text to be stored and displayed |
58 // Disable wrapping, force text to be stored and displayed |
55 // as a single line. |
59 // as a single line. |
56 QTextOption textOption = document()->defaultTextOption(); |
60 QTextOption textOption = document()->defaultTextOption(); |
57 textOption.setWrapMode(QTextOption::NoWrap); |
61 textOption.setWrapMode(QTextOption::NoWrap); |
58 document()->setDefaultTextOption(textOption); |
62 document()->setDefaultTextOption(textOption); |
|
63 // Set default font size |
|
64 QFont textFont = font(); |
|
65 textFont.setPointSize(11); |
|
66 setFont(textFont); |
59 // Enable cursor keys. |
67 // Enable cursor keys. |
60 setTextInteractionFlags(Qt::TextEditorInteraction); |
68 setTextInteractionFlags(Qt::TextEditorInteraction); |
61 // This is needed to initialize m_textLine. |
69 // This is needed to initialize m_textLine. |
62 setText(""); |
70 setText(""); |
63 setAcceptDrops(false); |
71 setAcceptDrops(false); |
64 m_defaultStartDragDistance = QApplication::startDragDistance(); |
72 m_defaultStartDragDistance = QApplication::startDragDistance(); |
65 } |
73 |
|
74 grabGesture(QStm_Gesture::assignedType()); |
|
75 installEventFilter(this); |
|
76 |
|
77 } |
66 |
78 |
67 GTextLineItem::~GTextLineItem() |
79 GTextLineItem::~GTextLineItem() |
68 { |
80 { |
69 if (m_maxTextLength > 0) |
81 if (m_maxTextLength > 0) |
70 disconnect(document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(contentsChange(int, int, int))); |
82 disconnect(document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(contentsChange(int, int, int))); |
189 } |
204 } |
190 } |
205 } |
191 |
206 |
192 void GTextLineItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) |
207 void GTextLineItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) |
193 { |
208 { |
|
209 event->setPos(QPointF(event->pos().x(), boundingRect().center().y())); // make selecting easily by using a fixed y position |
194 QGraphicsTextItem::mouseMoveEvent(event); |
210 QGraphicsTextItem::mouseMoveEvent(event); |
195 emit cursorXChanged(cursorX()); |
211 emit cursorXChanged(cursorX()); |
196 } |
212 } |
197 |
213 |
198 void GTextLineItem::mousePressEvent(QGraphicsSceneMouseEvent * event) |
214 void GTextLineItem::mousePressEvent(QGraphicsSceneMouseEvent * event) |
199 { |
215 { |
|
216 event->setPos(QPointF(event->pos().x(), boundingRect().center().y())); // make selecting easily by using a fixed y position |
200 QGraphicsTextItem::mousePressEvent(event); |
217 QGraphicsTextItem::mousePressEvent(event); |
201 } |
218 } |
202 |
219 |
203 void GTextLineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) |
220 void GTextLineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) |
204 { |
221 { |
205 |
222 if (contextMenuOn()) |
|
223 return; |
|
224 event->setPos(QPointF(event->pos().x(), boundingRect().center().y())); // make selecting easily by using a fixed y position |
206 QGraphicsTextItem::mouseReleaseEvent(event); |
225 QGraphicsTextItem::mouseReleaseEvent(event); |
207 QPointF pos = event->pos(); |
226 QPointF pos = event->pos(); |
208 emit tapped(pos); |
227 emit tapped(pos); |
209 launchVKB(); |
228 launchVKB(); |
210 } |
229 } |
234 QApplication::setStartDragDistance(1000); |
253 QApplication::setStartDragDistance(1000); |
235 QGraphicsTextItem::focusInEvent(event); |
254 QGraphicsTextItem::focusInEvent(event); |
236 |
255 |
237 #ifndef ORBIT_UI |
256 #ifndef ORBIT_UI |
238 QWidget* fw = QApplication::focusWidget(); |
257 QWidget* fw = QApplication::focusWidget(); |
239 Qt::InputMethodHints hints = fw->inputMethodHints(); |
258 if (fw != NULL) { |
240 if (hints != m_hints) |
259 Qt::InputMethodHints hints = fw->inputMethodHints(); |
241 fw->setInputMethodHints(m_hints); |
260 if (hints != m_hints) |
|
261 fw->setInputMethodHints(m_hints); |
|
262 } |
242 #endif |
263 #endif |
243 |
264 |
244 if (event->reason() != Qt::PopupFocusReason) // to fix the special char issue on VKB |
265 if (event->reason() != Qt::PopupFocusReason) // to fix the special char issue on VKB |
245 emit focusChanged(true); |
266 emit focusChanged(true); |
246 } |
267 } |
249 { |
270 { |
250 Q_UNUSED(event); |
271 Q_UNUSED(event); |
251 // restore the drag & drop for other components |
272 // restore the drag & drop for other components |
252 QApplication::setStartDragDistance(m_defaultStartDragDistance); |
273 QApplication::setStartDragDistance(m_defaultStartDragDistance); |
253 QGraphicsTextItem::focusOutEvent(event); |
274 QGraphicsTextItem::focusOutEvent(event); |
254 if (event->reason() != Qt::PopupFocusReason && event->reason() != Qt::ActiveWindowFocusReason) // to fix the special char issue on VKB |
275 if (event->reason() != Qt::PopupFocusReason && event->reason() != Qt::ActiveWindowFocusReason && !contextMenuOn()) // to fix the special char issue on VKB |
255 emit focusChanged(false); |
276 emit focusChanged(false); |
256 } |
277 } |
257 |
278 |
258 void GTextLineItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) |
279 void GTextLineItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) |
259 { |
280 { |
264 void GTextLineItem::setInputMethodHints(Qt::InputMethodHints hints) |
285 void GTextLineItem::setInputMethodHints(Qt::InputMethodHints hints) |
265 { |
286 { |
266 m_hints = hints; |
287 m_hints = hints; |
267 m_hints |= Qt::ImhNoPredictiveText; // disable the predictive text |
288 m_hints |= Qt::ImhNoPredictiveText; // disable the predictive text |
268 } |
289 } |
|
290 |
|
291 bool GTextLineItem::eventFilter(QObject* o, QEvent* e) |
|
292 { |
|
293 if (e->type() == QEvent::GraphicsSceneMouseMove) |
|
294 return false; |
|
295 return QStm_GestureEventFilter::instance()->eventFilter(o, e); |
|
296 } |
|
297 |
|
298 bool GTextLineItem::event(QEvent* event) |
|
299 { |
|
300 bool ret = false; |
|
301 if (event->type() == QEvent::Gesture) { |
|
302 QStm_Gesture* gesture = getQStmGesture(event); |
|
303 if (gesture) { |
|
304 return handleQStmGesture(gesture); |
|
305 } |
|
306 } |
|
307 ret = QGraphicsTextItem::event(event); |
|
308 return ret; |
|
309 } |
|
310 |
|
311 bool GTextLineItem::handleQStmGesture(QStm_Gesture* gesture) |
|
312 { |
|
313 QStm_GestureType type = gesture->getGestureStmType(); |
|
314 |
|
315 if (type == QStmLongPressGestureType) { |
|
316 emit contextEvent(hasSelection()); |
|
317 } |
|
318 else { |
|
319 QEvent::Type mouseEventType = gesture->gestureType2GraphicsSceneMouseType(); |
|
320 |
|
321 if (mouseEventType == QEvent::GraphicsSceneMousePress || |
|
322 mouseEventType == QEvent::GraphicsSceneMouseRelease) { |
|
323 QGraphicsSceneMouseEvent gsme(mouseEventType); |
|
324 QPointF pos = gesture->scenePosition(this); |
|
325 qstmSetGraphicsSceneMouseEvent(pos, this, gsme); |
|
326 switch (mouseEventType) { |
|
327 case QEvent::GraphicsSceneMousePress: |
|
328 mousePressEvent(&gsme); |
|
329 break; |
|
330 case QEvent::GraphicsSceneMouseRelease: |
|
331 mouseReleaseEvent(&gsme); |
|
332 break; |
|
333 case QEvent::GraphicsSceneMouseMove: |
|
334 mouseMoveEvent(&gsme); |
|
335 break; |
|
336 } |
|
337 } |
|
338 } |
|
339 |
|
340 return true; |
|
341 } |
|
342 |
269 |
343 |
270 void GTextLineItem::launchVKB() { |
344 void GTextLineItem::launchVKB() { |
271 |
345 |
272 |
346 |
273 // add specific button |
347 // add specific button |
303 ic->filterEvent(event); |
377 ic->filterEvent(event); |
304 delete event; |
378 delete event; |
305 } |
379 } |
306 } |
380 } |
307 |
381 |
|
382 void GTextLineItem::cut() { |
|
383 QTextCursor tc = textCursor(); |
|
384 QApplication::clipboard()->setText(tc.selectedText()); |
|
385 tc.insertText(""); |
|
386 setTextCursor(tc); |
|
387 } |
|
388 |
|
389 void GTextLineItem::copy() { |
|
390 QTextCursor tc = textCursor(); |
|
391 QApplication::clipboard()->setText(tc.selectedText()); |
|
392 } |
|
393 |
|
394 void GTextLineItem::paste() { |
|
395 QTextCursor tc = textCursor(); |
|
396 tc.insertText(QApplication::clipboard()->text(QClipboard::Clipboard)); |
|
397 setTextCursor(tc); |
|
398 } |
|
399 |
308 // Methods for class GLineEditor |
400 // Methods for class GLineEditor |
309 // GLineEditor is a QGraphicsWidget that wraps a GTextLineItem to implement scrolling, |
401 // GLineEditor is a QGraphicsWidget that wraps a GTextLineItem to implement scrolling, |
310 // draw a background and set padding |
402 // draw a background and set padding |
311 |
403 |
312 GLineEditor::GLineEditor(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent) |
404 GLineEditor::GLineEditor(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent) |
322 Q_UNUSED(snippet); |
414 Q_UNUSED(snippet); |
323 |
415 |
324 // The viewport clips the editor when text overflows |
416 // The viewport clips the editor when text overflows |
325 // viewport size will be set in resize() |
417 // viewport size will be set in resize() |
326 m_viewPort = new QGraphicsWidget(this); |
418 m_viewPort = new QGraphicsWidget(this); |
|
419 m_viewPort->setObjectName("ViewPort"); |
327 m_viewPort->setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
420 m_viewPort->setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
328 |
421 |
329 // The actual text editor item |
422 // The actual text editor item |
330 //m_textColor = QColor(Qt::black); |
423 //m_textColor = QColor(Qt::black); |
331 m_editor = new GTextLineItem(m_viewPort); |
424 m_editor = new GTextLineItem(m_viewPort); |
|
425 m_editor->setObjectName("LineItem"); |
332 #ifndef BROWSER_LAYOUT_TENONE |
426 #ifndef BROWSER_LAYOUT_TENONE |
333 m_editor->setDefaultTextColor(m_textColor); |
427 m_editor->setDefaultTextColor(m_textColor); |
334 #endif |
428 #endif |
335 m_editor->installEventFilter(this); |
429 m_editor->installEventFilter(this); |
336 |
430 |
337 #ifdef BROWSER_LAYOUT_TENONE |
431 #ifdef BROWSER_LAYOUT_TENONE |
338 m_titleColor = QColor(Qt::white); |
432 m_titleColor = QColor(Qt::white); |
339 m_title = new GTitleItem(m_viewPort); |
433 m_title = new GTitleItem(m_viewPort); |
|
434 m_title->setObjectName("TitleItem"); |
340 m_title->setDefaultTextColor(m_titleColor); |
435 m_title->setDefaultTextColor(m_titleColor); |
341 m_title->hide(); |
436 m_title->hide(); |
342 safe_connect(m_title, SIGNAL(tapped(QPointF& )), |
437 safe_connect(m_title, SIGNAL(tapped(QPointF& )), |
343 this, SIGNAL(titleMouseEvent(QPointF&))); |
438 this, SIGNAL(titleMouseEvent(QPointF&))); |
344 #endif |
439 #endif |
357 this, SIGNAL(focusChanged(bool))); |
452 this, SIGNAL(focusChanged(bool))); |
358 |
453 |
359 safe_connect(m_editor, SIGNAL(tapped(QPointF&)), |
454 safe_connect(m_editor, SIGNAL(tapped(QPointF&)), |
360 this, SIGNAL(tapped(QPointF&))); |
455 this, SIGNAL(tapped(QPointF&))); |
361 |
456 |
|
457 safe_connect(m_editor, SIGNAL(contextEvent(bool)), |
|
458 this, SIGNAL(contextEvent(bool))); |
|
459 |
362 setAcceptDrops(false); |
460 setAcceptDrops(false); |
363 } |
461 } |
364 |
462 |
365 GLineEditor::~GLineEditor() |
463 GLineEditor::~GLineEditor() |
366 { |
464 { |
373 m_textColor = color; |
471 m_textColor = color; |
374 m_editor->setDefaultTextColor(m_textColor); |
472 m_editor->setDefaultTextColor(m_textColor); |
375 } |
473 } |
376 |
474 |
377 #ifdef BROWSER_LAYOUT_TENONE |
475 #ifdef BROWSER_LAYOUT_TENONE |
378 void GLineEditor::setTitleColor(QColor & color) |
476 void GLineEditor::setTitleColor(QColor & color) { |
379 { |
|
380 m_titleColor = color; |
477 m_titleColor = color; |
381 m_title->setDefaultTextColor(m_titleColor); |
478 m_title->setDefaultTextColor(m_titleColor); |
382 } |
479 } |
383 |
480 |
384 void GLineEditor::setTitleFont(QFont & font) |
481 void GLineEditor::setTitleFont(QFont & font) { |
385 { |
|
386 m_title->setFont(font); |
482 m_title->setFont(font); |
|
483 } |
|
484 |
|
485 void GLineEditor::setTextFont(QFont & font) { |
|
486 m_editor->setFont(font); |
387 } |
487 } |
388 #endif |
488 #endif |
389 |
489 |
390 void GLineEditor::setPadding(qreal padding) |
490 void GLineEditor::setPadding(qreal padding) |
391 { |
491 { |
413 painter->save(); |
513 painter->save(); |
414 painter->setRenderHint(QPainter::Antialiasing); |
514 painter->setRenderHint(QPainter::Antialiasing); |
415 // First, fill rectangle with background color. |
515 // First, fill rectangle with background color. |
416 painter->fillRect(boundingRect(), m_backgroundColor); |
516 painter->fillRect(boundingRect(), m_backgroundColor); |
417 painter->restore(); |
517 painter->restore(); |
|
518 #ifdef BROWSER_LAYOUT_TENONE |
|
519 if(!isEnabled() && !m_title->isVisible()) { |
|
520 #else |
418 if(!isEnabled()) { |
521 if(!isEnabled()) { |
|
522 #endif |
|
523 |
419 ChromeEffect::paintDisabledRect(painter, option->exposedRect); |
524 ChromeEffect::paintDisabledRect(painter, option->exposedRect); |
420 } |
525 } |
421 // Make sure any required horizontal scrolling happens |
526 // Make sure any required horizontal scrolling happens |
422 // before rendering editor widget, which will be drawn on top |
527 // before rendering editor widget, which will be drawn on top |
423 // of the background rectangle. |
528 // of the background rectangle. |
425 } |
530 } |
426 |
531 |
427 void GLineEditor::resizeEvent(QGraphicsSceneResizeEvent * event) |
532 void GLineEditor::resizeEvent(QGraphicsSceneResizeEvent * event) |
428 { |
533 { |
429 QSizeF size = event->newSize(); |
534 QSizeF size = event->newSize(); |
430 qreal height = size.height() - m_padding * 2; |
535 qreal height = size.height(); |
431 qreal width; |
536 qreal width; |
432 |
537 |
433 width = m_viewPortWidth = size.width() - m_rightTextMargin - m_padding * 2; |
538 width = m_viewPortWidth = size.width() - m_rightTextMargin - m_padding * 2; |
434 |
539 |
435 #ifdef BROWSER_LAYOUT_TENONE |
540 #ifdef BROWSER_LAYOUT_TENONE |
678 painter->setRenderHint(QPainter::Antialiasing); |
783 painter->setRenderHint(QPainter::Antialiasing); |
679 painter->fillRect(boundingRect(), m_backgroundColor); |
784 painter->fillRect(boundingRect(), m_backgroundColor); |
680 painter->fillRect(progressRect, m_progressColor); |
785 painter->fillRect(progressRect, m_progressColor); |
681 paintBorder(painter); |
786 paintBorder(painter); |
682 painter->restore(); |
787 painter->restore(); |
|
788 #ifdef BROWSER_LAYOUT_TENONE |
|
789 if(!isEnabled() && !m_title->isVisible()) { |
|
790 #else |
683 if(!isEnabled()) { |
791 if(!isEnabled()) { |
|
792 #endif |
684 ChromeEffect::paintDisabledRect(painter, option->exposedRect); |
793 ChromeEffect::paintDisabledRect(painter, option->exposedRect); |
685 } |
794 } |
686 } |
795 } |
687 |
796 |
688 void GProgressEditor::setProgress(int percent) |
797 void GProgressEditor::setProgress(int percent) |
720 |
829 |
721 //A chrome item that displays a GTextEditor. This can be embedded in HTML chrome instead of an input field. |
830 //A chrome item that displays a GTextEditor. This can be embedded in HTML chrome instead of an input field. |
722 |
831 |
723 TextEditItem::TextEditItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent) |
832 TextEditItem::TextEditItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent) |
724 : NativeChromeItem(snippet, parent) |
833 : NativeChromeItem(snippet, parent) |
725 , m_justFocusIn(false) |
834 , m_justFocusIn(false) |
726 { |
835 { |
727 m_textEditor = new GTextEditor(snippet, chrome, this); |
836 m_textEditor = new GTextEditor(snippet, chrome, this); |
|
837 m_textEditor->setObjectName("Editor"); |
728 |
838 |
729 //Style via CSS |
839 //Style via CSS |
730 QWebElement we = m_snippet->element(); |
840 QWebElement we = m_snippet->element(); |
731 |
841 |
732 QColor textColor; |
842 QColor textColor; |
749 |
859 |
750 //Padding sets the "border" width |
860 //Padding sets the "border" width |
751 QString cssPadding = we.styleProperty("padding-top", QWebElement::ComputedStyle); |
861 QString cssPadding = we.styleProperty("padding-top", QWebElement::ComputedStyle); |
752 m_textEditor->setPadding(cssPadding.remove("px").toInt()); |
862 m_textEditor->setPadding(cssPadding.remove("px").toInt()); |
753 |
863 |
754 safe_connect(m_textEditor, SIGNAL(focusChanged(bool)),this, SLOT(focusChanged(bool))); |
864 safe_connect(m_textEditor, SIGNAL(focusChanged(bool)),this, SLOT(focusChanged(bool))); |
755 safe_connect(m_textEditor, SIGNAL(tapped(QPointF&)),this, SLOT(tapped(QPointF&))); |
865 safe_connect(m_textEditor, SIGNAL(tapped(QPointF&)),this, SLOT(tapped(QPointF&))); |
756 } |
866 safe_connect(m_textEditor, SIGNAL(contextEvent(bool)), this, SIGNAL(contextEvent(bool))); |
|
867 } |
757 |
868 |
758 void TextEditItem::tapped(QPointF& pos) |
869 void TextEditItem::tapped(QPointF& pos) |
759 { |
870 { |
760 bool hitText = m_textEditor->tappedOnText(pos.x()); |
871 bool hitText = m_textEditor->tappedOnText(pos.x()); |
761 if (!m_justFocusIn && !hitText) |
|
762 m_textEditor->unselect(); |
|
763 |
|
764 if (m_justFocusIn) { |
872 if (m_justFocusIn) { |
765 m_justFocusIn = false; |
873 m_justFocusIn = false; |
766 if (hitText && !m_textEditor->hasSelection()) |
874 if (hitText && !m_textEditor->hasSelection()) |
767 m_textEditor->selectAll(); |
875 m_textEditor->selectAll(); |
768 } |
876 } |
769 } |
877 } |
770 |
878 |
771 void TextEditItem::focusChanged(bool focusIn) |
879 void TextEditItem::focusChanged(bool focusIn) |
772 { |
880 { |
773 if (focusIn) |
881 if (focusIn) |
774 m_justFocusIn = true; |
882 m_justFocusIn = true; |
775 else { |
883 else { |
776 m_justFocusIn = false; |
884 m_justFocusIn = false; |
777 m_textEditor->unselect(); |
885 m_textEditor->unselect(); |
778 m_textEditor->shiftToLeftEnd(); |
886 m_textEditor->shiftToLeftEnd(); |
779 } |
887 } |
780 } |
888 } |
781 |
889 |
782 TextEditItem::~TextEditItem() |
890 TextEditItem::~TextEditItem() |
783 { |
891 { |
784 delete m_textEditor; |
892 delete m_textEditor; |
785 } |
893 } |