emailuis/nmailui/src/nmeditorcontent.cpp
author hgs
Tue, 29 Jun 2010 17:12:28 +0300
changeset 48 10eaf342f539
parent 47 f83bd4ae1fe3
child 49 00c7ae862740
permissions -rw-r--r--
201025_1
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 = 
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    27
    "(<img[^<]+(src\\s*=\\s*)(.{0,1}cid)([^<]+)(>\\s*|/>\\s*|></img>\\s*))";
47
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),
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    37
    mHeader(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
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    47
    mHeader = 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));
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    59
    mScrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    60
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    61
    // Enable style picker menu item.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
    mEditorWidget->setFormatDialog(new HbFormatDialog());
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
47
hgs
parents: 44
diff changeset
    64
    mScrollAreaContents =
hgs
parents: 44
diff changeset
    65
        qobject_cast<HbWidget *>(documentLoader->findWidget(NMUI_EDITOR_SCROLL_AREA_CONTENTS));
hgs
parents: 44
diff changeset
    66
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
    // Create signal slot connections
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
    createConnections();
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
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
    Destructor
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
NmEditorContent::~NmEditorContent()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
{
43
hgs
parents: 23
diff changeset
    76
    NM_FUNCTION;
18
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
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
/*!
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    80
    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
    81
    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
    82
    envelope ownership is not transferred here.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    83
 */
47
hgs
parents: 44
diff changeset
    84
void NmEditorContent::setMessageData(const NmMessage &originalMessage, 
hgs
parents: 44
diff changeset
    85
                                     NmUiEditorStartMode &editorStartMode)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
{
43
hgs
parents: 23
diff changeset
    87
    NM_FUNCTION;
44
hgs
parents: 43
diff changeset
    88
    
hgs
parents: 43
diff changeset
    89
    QString bodyContent;
hgs
parents: 43
diff changeset
    90
    
47
hgs
parents: 44
diff changeset
    91
    // Create the "reply" header (also for forward message)
hgs
parents: 44
diff changeset
    92
    if (editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll || 
hgs
parents: 44
diff changeset
    93
        editorStartMode==NmUiEditorForward) {
hgs
parents: 44
diff changeset
    94
        bodyContent.append(NmUtilities::createReplyHeader(originalMessage.envelope()));
44
hgs
parents: 43
diff changeset
    95
    }
hgs
parents: 43
diff changeset
    96
    
43
hgs
parents: 23
diff changeset
    97
    // Check which part is present. Html or plain text part. We use the original message parts.
hgs
parents: 23
diff changeset
    98
    const NmMessagePart *htmlPart = originalMessage.htmlBodyPart();
hgs
parents: 23
diff changeset
    99
    const NmMessagePart *plainPart = originalMessage.plainTextBodyPart();
44
hgs
parents: 43
diff changeset
   100
 
47
hgs
parents: 44
diff changeset
   101
    if (htmlPart) {
44
hgs
parents: 43
diff changeset
   102
        bodyContent.append(htmlPart->textContent());
47
hgs
parents: 44
diff changeset
   103
        if(editorStartMode==NmUiEditorReply || editorStartMode==NmUiEditorReplyAll ) {
hgs
parents: 44
diff changeset
   104
            removeEmbeddedImages(bodyContent);
hgs
parents: 44
diff changeset
   105
        }
44
hgs
parents: 43
diff changeset
   106
        emit setHtml(bodyContent);
47
hgs
parents: 44
diff changeset
   107
        mMessageBodyType = NmHTMLText;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   108
    }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   109
    else if (plainPart) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   110
        // Plain text part was present, set it to HbTextEdit
44
hgs
parents: 43
diff changeset
   111
        bodyContent.append(plainPart->textContent());
hgs
parents: 43
diff changeset
   112
        emit setPlainText(bodyContent);
47
hgs
parents: 44
diff changeset
   113
        mMessageBodyType = NmPlainText;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   114
    }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   115
}  
18
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
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   118
   This method creates all needed signal-slot connections
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   119
 */
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   120
void NmEditorContent::createConnections()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   121
{
43
hgs
parents: 23
diff changeset
   122
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   123
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   124
    // Signal for setting HbTextEdit widgets html content
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   125
    connect(this, SIGNAL(setHtml(QString)),
44
hgs
parents: 43
diff changeset
   126
            mEditorWidget, SLOT(setHtml(QString)), Qt::QueuedConnection);
47
hgs
parents: 44
diff changeset
   127
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   128
    // Signal for setting HbTextEdit widgets plain text content
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   129
    connect(this, SIGNAL(setPlainText(QString)),
44
hgs
parents: 43
diff changeset
   130
            mEditorWidget, SLOT(setPlainText(QString)), Qt::QueuedConnection);
47
hgs
parents: 44
diff changeset
   131
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   132
    // Inform text edit widget that header height has been changed
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   133
    connect(mHeader, SIGNAL(headerHeightChanged(int)), this, SLOT(setEditorContentHeight()),
47
hgs
parents: 44
diff changeset
   134
        Qt::QueuedConnection);
hgs
parents: 44
diff changeset
   135
hgs
parents: 44
diff changeset
   136
    // we are interested in the document's height changes
hgs
parents: 44
diff changeset
   137
    connect(mEditorWidget->document()->documentLayout(), SIGNAL(documentSizeChanged(QSizeF)), this,
hgs
parents: 44
diff changeset
   138
        SLOT(setEditorContentHeight()), Qt::QueuedConnection);
hgs
parents: 44
diff changeset
   139
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   140
    // We need to update the scroll position according the editor's cursor position
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   141
    connect(mHeader->toEdit(), SIGNAL(cursorPositionChanged(int, int)), this, 
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   142
        SLOT(ensureCursorVisibility()), Qt::QueuedConnection);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   143
    connect(mHeader->ccEdit(), SIGNAL(cursorPositionChanged(int, int)), this, 
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   144
        SLOT(ensureCursorVisibility()), Qt::QueuedConnection);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   145
    connect(mHeader->bccEdit(), SIGNAL(cursorPositionChanged(int, int)), this, 
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   146
        SLOT(ensureCursorVisibility()), Qt::QueuedConnection);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   147
    connect(mHeader->subjectEdit(), SIGNAL(cursorPositionChanged(int, int)), this, 
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   148
        SLOT(ensureCursorVisibility()), Qt::QueuedConnection);
47
hgs
parents: 44
diff changeset
   149
    connect(mEditorWidget, SIGNAL(cursorPositionChanged(int, int)), this, 
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   150
        SLOT(ensureCursorVisibility()), Qt::QueuedConnection);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   151
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   152
    // listen to the parent's (NmEditorView) size changes which happen eg. when VKB is opened/closed
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   153
    connect(parent(), SIGNAL(sizeChanged()), this, SLOT(ensureCursorVisibility()),
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   154
        Qt::QueuedConnection);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   155
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
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
    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
   159
 */
47
hgs
parents: 44
diff changeset
   160
NmEditorTextEdit *NmEditorContent::editor() const
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
{
43
hgs
parents: 23
diff changeset
   162
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   163
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
    return mEditorWidget;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   165
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
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
    Return pointer to the header widget
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
 */
47
hgs
parents: 44
diff changeset
   170
NmEditorHeader *NmEditorContent::header() const
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
{
43
hgs
parents: 23
diff changeset
   172
    NM_FUNCTION;
hgs
parents: 23
diff changeset
   173
    
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   174
    return mHeader;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   175
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   176
47
hgs
parents: 44
diff changeset
   177
/*!
hgs
parents: 44
diff changeset
   178
    This slot is called when header widget height has been changed. Function performs
hgs
parents: 44
diff changeset
   179
    the repositioning of the body field and resizing of the editor and content area.
hgs
parents: 44
diff changeset
   180
 */
hgs
parents: 44
diff changeset
   181
void NmEditorContent::setEditorContentHeight()
hgs
parents: 44
diff changeset
   182
{
hgs
parents: 44
diff changeset
   183
    NM_FUNCTION;
hgs
parents: 44
diff changeset
   184
    
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   185
    // the height of the margin between the title bar and the header
47
hgs
parents: 44
diff changeset
   186
    qreal topMargin = 0;
hgs
parents: 44
diff changeset
   187
    HbStyle().parameter("hb-param-margin-gene-top", topMargin);
hgs
parents: 44
diff changeset
   188
    
hgs
parents: 44
diff changeset
   189
    // header height
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   190
    qreal headerHeight = mHeader->headerHeight();
47
hgs
parents: 44
diff changeset
   191
hgs
parents: 44
diff changeset
   192
    // body area editor's document height with margins added
hgs
parents: 44
diff changeset
   193
    qreal documentHeightAndMargins = mEditorWidget->document()->size().height() +
hgs
parents: 44
diff changeset
   194
        (mEditorWidget->document()->documentMargin() * 2);
hgs
parents: 44
diff changeset
   195
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   196
    // chrome height
47
hgs
parents: 44
diff changeset
   197
    qreal chromeHeight = 0;
hgs
parents: 44
diff changeset
   198
    HbStyle().parameter("hb-param-widget-chrome-height", chromeHeight);
hgs
parents: 44
diff changeset
   199
    
hgs
parents: 44
diff changeset
   200
    // screen height
hgs
parents: 44
diff changeset
   201
    qreal screenHeight = mApplication.screenSize().height();
hgs
parents: 44
diff changeset
   202
hgs
parents: 44
diff changeset
   203
    // set min size for the body area so that at least the screen area is always filled
hgs
parents: 44
diff changeset
   204
    qreal bodyAreaMinSize = screenHeight - chromeHeight - topMargin - headerHeight;
hgs
parents: 44
diff changeset
   205
    
hgs
parents: 44
diff changeset
   206
    qreal bodyAreaSize = fmax(bodyAreaMinSize, documentHeightAndMargins);
hgs
parents: 44
diff changeset
   207
hgs
parents: 44
diff changeset
   208
    mScrollAreaContents->setPreferredHeight(topMargin + headerHeight + bodyAreaSize);
hgs
parents: 44
diff changeset
   209
}
hgs
parents: 44
diff changeset
   210
hgs
parents: 44
diff changeset
   211
/*!
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   212
    This slot is called when the cursor visibility has to be ensured ie. the scroll position is 
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   213
    adjusted so that the cursor can be seen.
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   214
*/
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   215
void NmEditorContent::ensureCursorVisibility()
47
hgs
parents: 44
diff changeset
   216
{
hgs
parents: 44
diff changeset
   217
    NM_FUNCTION;
hgs
parents: 44
diff changeset
   218
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   219
    // check which of the editors has the focus and get the x/y coordinates for the cursor position
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   220
    QGraphicsWidget *focused = mScrollAreaContents->focusWidget();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   221
    
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   222
    if (focused) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   223
        QRectF localRect(0, 0, 0, 0);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   224
        bool notFound = false;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   225
        
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   226
        if (focused == mHeader->toEdit()) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   227
            localRect = mHeader->toEdit()->rectForCursorPosition();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   228
        }
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   229
        else if (focused == mHeader->ccEdit()) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   230
            localRect = mHeader->ccEdit()->rectForCursorPosition();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   231
        }
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   232
        else if (focused == mHeader->bccEdit()) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   233
            localRect = mHeader->bccEdit()->rectForCursorPosition();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   234
        }
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   235
        else if (focused == mHeader->subjectEdit()) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   236
            localRect = mHeader->subjectEdit()->rectForCursorPosition();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   237
        }
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   238
        else if (focused == mEditorWidget) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   239
            localRect = mEditorWidget->rectForCursorPosition();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   240
        }
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   241
        else {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   242
            notFound = true;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   243
        }
47
hgs
parents: 44
diff changeset
   244
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   245
        if (!notFound) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   246
            QPointF topLeftPos = focused->mapToItem(mScrollAreaContents, localRect.topLeft());
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   247
            QPointF bottomRightPos =
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   248
                focused->mapToItem(mScrollAreaContents, localRect.bottomRight());
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   249
            qreal marginRight = 0;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   250
            HbStyle().parameter("hb-param-margin-gene-right", marginRight);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   251
            bottomRightPos.rx() += marginRight;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   252
            mScrollArea->ensureVisible(topLeftPos);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   253
            mScrollArea->ensureVisible(bottomRightPos);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   254
        }
47
hgs
parents: 44
diff changeset
   255
    }
hgs
parents: 44
diff changeset
   256
}
hgs
parents: 44
diff changeset
   257
/*!
hgs
parents: 44
diff changeset
   258
    Removes embedded images from the message body
hgs
parents: 44
diff changeset
   259
 */
hgs
parents: 44
diff changeset
   260
void NmEditorContent::removeEmbeddedImages(QString &bodyContent)
hgs
parents: 44
diff changeset
   261
{
hgs
parents: 44
diff changeset
   262
    NM_FUNCTION;
hgs
parents: 44
diff changeset
   263
 
hgs
parents: 44
diff changeset
   264
    QRegExp regExp(NMUI_EDITOR_REMOVE_EMBD_IMAGES_REG, Qt::CaseInsensitive);
hgs
parents: 44
diff changeset
   265
    bodyContent.remove(regExp);
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   266
}