emailuis/nmailuiwidgets/src/nmhtmllineedit.cpp
changeset 74 6c59112cfd31
parent 68 83cc6bae1de8
child 76 38bf5461e270
equal deleted inserted replaced
69:4e54af54a4a1 74:6c59112cfd31
    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);
    83 void NmHtmlLineEdit::setHtml(const QString &text)
    87 void NmHtmlLineEdit::setHtml(const QString &text)
    84 {
    88 {
    85     NM_FUNCTION;
    89     NM_FUNCTION;
    86     
    90     
    87     HbAbstractEdit::setHtml(text);
    91     HbAbstractEdit::setHtml(text);
       
    92     // Resetting the indent is called because setting new content lose old indention set. 
       
    93     setIndentForLabel(NmLabelIndentUsePreviousValue);    
    88 }
    94 }
    89 
    95 
    90 QString NmHtmlLineEdit::toPlainText () const
    96 QString NmHtmlLineEdit::toPlainText () const
    91 {
    97 {
    92     NM_FUNCTION;
    98     NM_FUNCTION;
    97 void NmHtmlLineEdit::setPlainText (const QString &text)
   103 void NmHtmlLineEdit::setPlainText (const QString &text)
    98 {
   104 {
    99     NM_FUNCTION;
   105     NM_FUNCTION;
   100     
   106     
   101     HbAbstractEdit::setPlainText(text);
   107     HbAbstractEdit::setPlainText(text);
       
   108     // Resetting the indent is called because setting new content lose old indention set. 
       
   109     setIndentForLabel(NmLabelIndentUsePreviousValue);    
   102 }
   110 }
   103 
   111 
   104 /*!
   112 /*!
   105  *  Returns true if this widget has the input focus.
   113  *  Returns true if this widget has the input focus.
   106  */
   114  */
   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