emailuis/nmailui/src/nmeditorcontent.cpp
author hgs
Thu, 24 Jun 2010 14:32:18 +0300
changeset 47 f83bd4ae1fe3
parent 44 c2d07d913565
child 48 10eaf342f539
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description: Message editor contents widget
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include "nmuiheaders.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
// Layout
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
static const char *NMUI_EDITOR_BODY = "BodyTextEdit";
47
hgs
parents: 44
diff changeset
    22
static const char *NMUI_EDITOR_SCROLL_AREA = "scrollArea";
hgs
parents: 44
diff changeset
    23
static const char *NMUI_EDITOR_SCROLL_AREA_CONTENTS = "scrollAreaContents";
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
47
hgs
parents: 44
diff changeset
    25
// Regular expression for selecting img tags with "cid" in the mail.
hgs
parents: 44
diff changeset
    26
static const char *NMUI_EDITOR_REMOVE_EMBD_IMAGES_REG = 
hgs
parents: 44
diff changeset
    27
    "(<img (src\\s*=\\s*)(.{0,1}cid)([^<]+)(>\\s*|/>\\s*|></img>\\s*))";
hgs
parents: 44
diff changeset
    28
	
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
    Constructor
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
*/
47
hgs
parents: 44
diff changeset
    32
NmEditorContent::NmEditorContent(QObject *parent,
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    33
                                 HbDocumentLoader *documentLoader,
47
hgs
parents: 44
diff changeset
    34
                                 QNetworkAccessManager &manager,
hgs
parents: 44
diff changeset
    35
                                 NmApplication &application) :
hgs
parents: 44
diff changeset
    36
    QObject(parent),
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
    mHeaderWidget(NULL),
47
hgs
parents: 44
diff changeset
    38
    mMessageBodyType(NmPlainText),
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
    mEditorWidget(NULL),
47
hgs
parents: 44
diff changeset
    40
    mScrollArea(NULL),
hgs
parents: 44
diff changeset
    41
    mScrollAreaContents(NULL),
hgs
parents: 44
diff changeset
    42
    mApplication(application)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
{
43
hgs
parents: 23
diff changeset
    44
    NM_FUNCTION;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
47
hgs
parents: 44
diff changeset
    46
    // Construct container for the header widgets
hgs
parents: 44
diff changeset
    47
    mHeaderWidget = new NmEditorHeader(this, documentLoader);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
    // Get pointer to body text area handling widget
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
    mEditorWidget = qobject_cast<NmEditorTextEdit *>(documentLoader->findWidget(NMUI_EDITOR_BODY));
43
hgs
parents: 23
diff changeset
    51
    
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    52
    // Set body editor to use NmEditorTextDocument
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    53
    NmEditorTextDocument *textDocument = new NmEditorTextDocument(manager);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    54
    mEditorWidget->setDocument(textDocument); 
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    55
    textDocument->setParent(mEditorWidget); // ownership changes
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    56
47
hgs
parents: 44
diff changeset
    57
    mScrollArea = qobject_cast<NmBaseViewScrollArea *>
hgs
parents: 44
diff changeset
    58
        (documentLoader->findObject(NMUI_EDITOR_SCROLL_AREA));
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    59
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    60
    // Enable style picker menu item.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
    mEditorWidget->setFormatDialog(new HbFormatDialog());
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
47
hgs
parents: 44
diff changeset
    63
    mScrollAreaContents =
hgs
parents: 44
diff changeset
    64
        qobject_cast<HbWidget *>(documentLoader->findWidget(NMUI_EDITOR_SCROLL_AREA_CONTENTS));
hgs
parents: 44
diff changeset
    65
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
    // Create signal slot connections
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
    createConnections();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
    Destructor
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
NmEditorContent::~NmEditorContent()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
{
43
hgs
parents: 23
diff changeset
    75
    NM_FUNCTION;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
/*!
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    79
    Fill message data into header and body fileds. If reply envelopw is
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    80
    present, reply header is generated and set to editor. Reply
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    81
    envelope ownership is not transferred here.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
 */
47
hgs
parents: 44
diff changeset
    83
void NmEditorContent::setMessageData(const NmMessage &originalMessage, 
hgs
parents: 44
diff changeset
    84
                                     NmUiEditorStartMode &editorStartMode)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
{
43
hgs
parents: 23
diff changeset
    86
    NM_FUNCTION;
44
hgs
parents: 43
diff changeset
    87
    
hgs
parents: 43
diff changeset
    88
    QString bodyContent;
hgs
parents: 43
diff changeset
    89
    
47
hgs
parents: 44
diff changeset
    90
    // Create the "reply" header (also for forward message)
hgs
parents: 44
diff changeset
    91
    if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll || 
hgs
parents: 44
diff changeset
    92
        editorStartMode==NmUiEditorForward) {
hgs
parents: 44
diff changeset
    93
        bodyContent.append(NmUtilities::createReplyHeader(originalMessage.envelope()));
44
hgs
parents: 43
diff changeset
    94
    }
hgs
parents: 43
diff changeset
    95
    
43
hgs
parents: 23
diff changeset
    96
    // Check which part is present. Html or plain text part. We use the original message parts.
hgs
parents: 23
diff changeset
    97
    const NmMessagePart *htmlPart = originalMessage.htmlBodyPart();
hgs
parents: 23
diff changeset
    98
    const NmMessagePart *plainPart = originalMessage.plainTextBodyPart();
44
hgs
parents: 43
diff changeset
    99
 
47
hgs
parents: 44
diff changeset
   100
    if (htmlPart) {
44
hgs
parents: 43
diff changeset
   101
        bodyContent.append(htmlPart->textContent());
47
hgs
parents: 44
diff changeset
   102
        if(editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll ) {
hgs
parents: 44
diff changeset
   103
            removeEmbeddedImages(bodyContent);
hgs
parents: 44
diff changeset
   104
        }
44
hgs
parents: 43
diff changeset
   105
        emit setHtml(bodyContent);
47
hgs
parents: 44
diff changeset
   106
        mMessageBodyType = NmHTMLText;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   107
    }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   108
    else if (plainPart) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   109
        // Plain text part was present, set it to HbTextEdit
44
hgs
parents: 43
diff changeset
   110
        bodyContent.append(plainPart->textContent());
hgs
parents: 43
diff changeset
   111
        emit setPlainText(bodyContent);
47
hgs
parents: 44
diff changeset
   112
        mMessageBodyType = NmPlainText;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   113
    }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   114
}  
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   115
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   116
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   117
   This method creates all needed signal-slot connections
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   118
 */
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   119
void NmEditorContent::createConnections()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   120
{
43
hgs
parents: 23
diff changeset
   121
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   122
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   123
    // Signal for setting HbTextEdit widgets html content
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   124
    connect(this, SIGNAL(setHtml(QString)),
44
hgs
parents: 43
diff changeset
   125
            mEditorWidget, SLOT(setHtml(QString)), Qt::QueuedConnection);
47
hgs
parents: 44
diff changeset
   126
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   127
    // Signal for setting HbTextEdit widgets plain text content
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   128
    connect(this, SIGNAL(setPlainText(QString)),
44
hgs
parents: 43
diff changeset
   129
            mEditorWidget, SLOT(setPlainText(QString)), Qt::QueuedConnection);
47
hgs
parents: 44
diff changeset
   130
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   131
    // Inform text edit widget that header height has been changed
47
hgs
parents: 44
diff changeset
   132
    connect(mHeaderWidget, SIGNAL(headerHeightChanged(int)), this, SLOT(setEditorContentHeight()),
hgs
parents: 44
diff changeset
   133
        Qt::QueuedConnection);
hgs
parents: 44
diff changeset
   134
hgs
parents: 44
diff changeset
   135
    // we are interested in the document's height changes
hgs
parents: 44
diff changeset
   136
    connect(mEditorWidget->document()->documentLayout(), SIGNAL(documentSizeChanged(QSizeF)), this,
hgs
parents: 44
diff changeset
   137
        SLOT(setEditorContentHeight()), Qt::QueuedConnection);
hgs
parents: 44
diff changeset
   138
hgs
parents: 44
diff changeset
   139
    // We need to update the scroll position according the editor cursor position
hgs
parents: 44
diff changeset
   140
    connect(mEditorWidget, SIGNAL(cursorPositionChanged(int, int)), this, 
hgs
parents: 44
diff changeset
   141
        SLOT(setScrollPosition(int, int)), Qt::QueuedConnection);
hgs
parents: 44
diff changeset
   142
    
hgs
parents: 44
diff changeset
   143
    // We need to know the scroll area's current position for calculating the new position in
hgs
parents: 44
diff changeset
   144
	// setScrollPosition
hgs
parents: 44
diff changeset
   145
    connect(mScrollArea, SIGNAL(scrollPositionChanged(QPointF)), this, 
hgs
parents: 44
diff changeset
   146
        SLOT(updateScrollPosition(QPointF)), Qt::QueuedConnection);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   147
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   148
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   149
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
    Return pointer to the email body text edit widget
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
 */
47
hgs
parents: 44
diff changeset
   152
NmEditorTextEdit *NmEditorContent::editor() const
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   153
{
43
hgs
parents: 23
diff changeset
   154
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   155
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
    return mEditorWidget;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   159
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   160
    Return pointer to the header widget
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
 */
47
hgs
parents: 44
diff changeset
   162
NmEditorHeader *NmEditorContent::header() const
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
{
43
hgs
parents: 23
diff changeset
   164
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   165
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
    return mHeaderWidget;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   168
47
hgs
parents: 44
diff changeset
   169
/*!
hgs
parents: 44
diff changeset
   170
    This slot is called when header widget height has been changed. Function performs
hgs
parents: 44
diff changeset
   171
    the repositioning of the body field and resizing of the editor and content area.
hgs
parents: 44
diff changeset
   172
 */
hgs
parents: 44
diff changeset
   173
void NmEditorContent::setEditorContentHeight()
hgs
parents: 44
diff changeset
   174
{
hgs
parents: 44
diff changeset
   175
    NM_FUNCTION;
hgs
parents: 44
diff changeset
   176
    
hgs
parents: 44
diff changeset
   177
    qreal topMargin = 0;
hgs
parents: 44
diff changeset
   178
    HbStyle().parameter("hb-param-margin-gene-top", topMargin);
hgs
parents: 44
diff changeset
   179
    
hgs
parents: 44
diff changeset
   180
    // header height
hgs
parents: 44
diff changeset
   181
    qreal headerHeight = mHeaderWidget->headerHeight();
hgs
parents: 44
diff changeset
   182
hgs
parents: 44
diff changeset
   183
    // body area editor's document height with margins added
hgs
parents: 44
diff changeset
   184
    qreal documentHeightAndMargins = mEditorWidget->document()->size().height() +
hgs
parents: 44
diff changeset
   185
        (mEditorWidget->document()->documentMargin() * 2);
hgs
parents: 44
diff changeset
   186
hgs
parents: 44
diff changeset
   187
    // get the chrome height
hgs
parents: 44
diff changeset
   188
    qreal chromeHeight = 0;
hgs
parents: 44
diff changeset
   189
    HbStyle().parameter("hb-param-widget-chrome-height", chromeHeight);
hgs
parents: 44
diff changeset
   190
    
hgs
parents: 44
diff changeset
   191
    qreal toolbarHeight = 0;
hgs
parents: 44
diff changeset
   192
    HbStyle().parameter("hb-param-widget-toolbar-height", toolbarHeight);
hgs
parents: 44
diff changeset
   193
hgs
parents: 44
diff changeset
   194
    // screen height
hgs
parents: 44
diff changeset
   195
    qreal screenHeight = mApplication.screenSize().height();
hgs
parents: 44
diff changeset
   196
hgs
parents: 44
diff changeset
   197
    // set min size for the body area so that at least the screen area is always filled
hgs
parents: 44
diff changeset
   198
    qreal bodyAreaMinSize = screenHeight - chromeHeight - topMargin - headerHeight;
hgs
parents: 44
diff changeset
   199
    
hgs
parents: 44
diff changeset
   200
    qreal bodyAreaSize = fmax(bodyAreaMinSize, documentHeightAndMargins);
hgs
parents: 44
diff changeset
   201
hgs
parents: 44
diff changeset
   202
    mScrollAreaContents->setPreferredHeight(topMargin + headerHeight + bodyAreaSize);
hgs
parents: 44
diff changeset
   203
}
hgs
parents: 44
diff changeset
   204
hgs
parents: 44
diff changeset
   205
/*!
hgs
parents: 44
diff changeset
   206
    This slot is called when cursor position is changed in body area using
hgs
parents: 44
diff changeset
   207
    'pointing stick' or keyboard. Function will update the scroll position
hgs
parents: 44
diff changeset
   208
    of the content so that cursor does not go outside of the screen or
hgs
parents: 44
diff changeset
   209
    behind the virtual keyboard.
hgs
parents: 44
diff changeset
   210
 */
hgs
parents: 44
diff changeset
   211
void NmEditorContent::setScrollPosition(int oldPos, int newPos)
hgs
parents: 44
diff changeset
   212
{
hgs
parents: 44
diff changeset
   213
    NM_FUNCTION;
hgs
parents: 44
diff changeset
   214
    
hgs
parents: 44
diff changeset
   215
    Q_UNUSED(oldPos);
hgs
parents: 44
diff changeset
   216
hgs
parents: 44
diff changeset
   217
    qreal chromeHeight = 0;
hgs
parents: 44
diff changeset
   218
    HbStyle().parameter("hb-param-widget-chrome-height", chromeHeight);
hgs
parents: 44
diff changeset
   219
    
hgs
parents: 44
diff changeset
   220
    const QSizeF screenReso = mApplication.screenSize();
hgs
parents: 44
diff changeset
   221
    qreal maxHeight = screenReso.height() - chromeHeight;
hgs
parents: 44
diff changeset
   222
hgs
parents: 44
diff changeset
   223
    // Get cursor position coordinates
hgs
parents: 44
diff changeset
   224
    QRectF cursorPosPix = mEditorWidget->rectForPosition(newPos);
hgs
parents: 44
diff changeset
   225
    
hgs
parents: 44
diff changeset
   226
    // Calculate the screen top and bottom boundaries, this means the part of the
hgs
parents: 44
diff changeset
   227
    // background scroll area which is currently visible.
hgs
parents: 44
diff changeset
   228
    qreal visibleRectTopBoundary;
hgs
parents: 44
diff changeset
   229
    qreal visibleRectBottomBoundary;
hgs
parents: 44
diff changeset
   230
    
hgs
parents: 44
diff changeset
   231
    qreal headerHeight = mHeaderWidget->headerHeight();
hgs
parents: 44
diff changeset
   232
hgs
parents: 44
diff changeset
   233
    if (mScrollPosition.y() < headerHeight) {
hgs
parents: 44
diff changeset
   234
        // Header is completely or partially visible
hgs
parents: 44
diff changeset
   235
        visibleRectTopBoundary = headerHeight - mScrollPosition.y();
hgs
parents: 44
diff changeset
   236
        visibleRectBottomBoundary = maxHeight - visibleRectTopBoundary;
hgs
parents: 44
diff changeset
   237
    }
hgs
parents: 44
diff changeset
   238
    else {
hgs
parents: 44
diff changeset
   239
        // Header is not visible
hgs
parents: 44
diff changeset
   240
        visibleRectTopBoundary = mScrollPosition.y() - headerHeight;
hgs
parents: 44
diff changeset
   241
        visibleRectBottomBoundary = visibleRectTopBoundary + maxHeight;
hgs
parents: 44
diff changeset
   242
    }
hgs
parents: 44
diff changeset
   243
hgs
parents: 44
diff changeset
   244
    // Do scrolling if cursor is out of the screen boundaries
hgs
parents: 44
diff changeset
   245
    if (cursorPosPix.y() > visibleRectBottomBoundary) {
hgs
parents: 44
diff changeset
   246
        // Do scroll forward
hgs
parents: 44
diff changeset
   247
        mScrollArea->scrollContentsTo(QPointF(0, cursorPosPix.y() - maxHeight + headerHeight));
hgs
parents: 44
diff changeset
   248
    }
hgs
parents: 44
diff changeset
   249
    else if (cursorPosPix.y() + headerHeight < mScrollPosition.y()) {
hgs
parents: 44
diff changeset
   250
        // Do scroll backward
hgs
parents: 44
diff changeset
   251
        mScrollArea->scrollContentsTo(QPointF(0, cursorPosPix.y() + headerHeight));
hgs
parents: 44
diff changeset
   252
    }
hgs
parents: 44
diff changeset
   253
}
hgs
parents: 44
diff changeset
   254
hgs
parents: 44
diff changeset
   255
/*!
hgs
parents: 44
diff changeset
   256
    This slot is called when background scroll areas scroll position has been shanged.
hgs
parents: 44
diff changeset
   257
*/
hgs
parents: 44
diff changeset
   258
void NmEditorContent::updateScrollPosition(const QPointF &newPosition)
hgs
parents: 44
diff changeset
   259
{
hgs
parents: 44
diff changeset
   260
    NM_FUNCTION;
hgs
parents: 44
diff changeset
   261
    
hgs
parents: 44
diff changeset
   262
    mScrollPosition = newPosition;
hgs
parents: 44
diff changeset
   263
}
hgs
parents: 44
diff changeset
   264
hgs
parents: 44
diff changeset
   265
/*!
hgs
parents: 44
diff changeset
   266
    Removes embedded images from the message body
hgs
parents: 44
diff changeset
   267
 */
hgs
parents: 44
diff changeset
   268
void NmEditorContent::removeEmbeddedImages(QString &bodyContent)
hgs
parents: 44
diff changeset
   269
{
hgs
parents: 44
diff changeset
   270
    NM_FUNCTION;
hgs
parents: 44
diff changeset
   271
 
hgs
parents: 44
diff changeset
   272
    QRegExp regExp(NMUI_EDITOR_REMOVE_EMBD_IMAGES_REG, Qt::CaseInsensitive);
hgs
parents: 44
diff changeset
   273
    bodyContent.remove(regExp);
hgs
parents: 44
diff changeset
   274
}