messagingapp/msgui/unifiedviewer/inc/univiewertextitem.h
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  * Message body preview class.
       
    16  * has in built logic for finding phone number, email, url.
       
    17  *
       
    18  */
       
    19 
       
    20 #ifndef UNIVIEWERTEXTITEM_H
       
    21 #define UNIVIEWERTEXTITEM_H
       
    22 
       
    23 #include <HbTextEdit>
       
    24 
       
    25 
       
    26 //forward declarations
       
    27 class QRegExp;
       
    28 class XQAiwRequest;
       
    29 
       
    30 class UniViewerTextItem : public HbTextEdit
       
    31 {
       
    32     Q_OBJECT
       
    33 public:
       
    34     UniViewerTextItem(QGraphicsItem* parent=0);
       
    35     ~UniViewerTextItem();
       
    36     void setFindOn(bool on = true);
       
    37     void setText(const QString& text);
       
    38 
       
    39 protected:
       
    40     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
       
    41     void mousePressEvent(QGraphicsSceneMouseEvent *event);
       
    42 
       
    43 private:
       
    44 
       
    45     /**
       
    46      * Applies find rule and highlights text.
       
    47      */
       
    48     void applyRule();
       
    49 
       
    50     /**
       
    51       * Helper method to add menus.
       
    52       * @param contextMenu menu object.
       
    53       * @param data, anchor at current position.
       
    54       */
       
    55     void addNumberMenu(HbMenu* contextMenu,const QString& data);
       
    56     void addEmailMenu(HbMenu* contextMenu,const QString& data);
       
    57     void addUrlMenu(HbMenu* contextMenu,const QString& data);
       
    58     
       
    59     /**
       
    60      * short tap handler.
       
    61      * @param anchor anchor at cursor position.
       
    62      */
       
    63     void shortTapAction(QString anchor);    
       
    64     
       
    65     /**
       
    66      * Helper method to highlight find item on tap.
       
    67      * @param highlight, if true highlight else dont.
       
    68      */
       
    69     void highlightText(bool highlight);
       
    70 	
       
    71     /** Helper method to get contact id against phone number or e-mail id.
       
    72      * @param value phone number or email id.
       
    73      * @param fieldName name of field to be matched.
       
    74      * @param fieldType type of field to be matched.
       
    75      */
       
    76     int resolveContactId(const QString& value,
       
    77                          const QString& fieldName, 
       
    78                          const QString& fieldType);
       
    79 
       
    80 private slots:
       
    81     /**
       
    82       * called when aboutToShowContextMenu signal is emitted.
       
    83       */
       
    84     void aboutToShowContextMenu(HbMenu *contextMenu, const QPointF &pos);
       
    85     
       
    86     /**
       
    87      * Called when option menu is closed.
       
    88      */
       
    89     void menuClosed();
       
    90 
       
    91 
       
    92     //handlers for phone number specific menu items.
       
    93     void call();
       
    94     void sendMessage();    
       
    95 
       
    96     //handlers for e-mail specific menu items.
       
    97     void createEmail();
       
    98 
       
    99     //handlers for url specific menu items.
       
   100     void openLink();
       
   101     void addToBookmarks();
       
   102 
       
   103     //common handlers.
       
   104     void openContactInfo();
       
   105     void saveToContacts();
       
   106     void copyToClipboard();
       
   107     
       
   108     //called after service request is completed.
       
   109     void onServiceRequestCompleted();
       
   110     
       
   111 signals:
       
   112     /**
       
   113      * this signal is emitted when send message is triggered for a highlighted number.
       
   114      */
       
   115     void sendMessage(const QString& phoneNumber);
       
   116     
       
   117 
       
   118 private:
       
   119     //map to hold rule and patterns.
       
   120     QMap<QString,QString> mRules;
       
   121 
       
   122     //property to on/off find patterns. default is on.
       
   123     bool mFindOn;
       
   124 
       
   125     //char formats for highlight.
       
   126     QTextCharFormat mFormatHighlight;
       
   127     QTextCharFormat mFormatNormal;
       
   128 
       
   129     //Current cursor position.
       
   130     int mCursorPos;
       
   131 };
       
   132 
       
   133 #endif // UNIVIEWERTEXTITEM_H