|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 #ifndef HBSMILEYENGINE_P_P_H |
|
26 #define HBSMILEYENGINE_P_P_H |
|
27 |
|
28 #include <hbsmileytheme.h> |
|
29 #include <hbsmileyengine_p.h> |
|
30 #include <QTextCursor> |
|
31 #include <QTextObjectInterface> |
|
32 #include <QObject> |
|
33 #include <QPair> |
|
34 |
|
35 class HbIconAnimator; |
|
36 QT_FORWARD_DECLARE_CLASS(QTextDocument); |
|
37 |
|
38 struct HbSmileyDataType { |
|
39 HbSmileyDataType():cursor(0),animator(0),scaleFactor(1){} |
|
40 QTextCursor* cursor; |
|
41 HbIconAnimator* animator; |
|
42 qreal scaleFactor; |
|
43 }; |
|
44 |
|
45 |
|
46 class HbIconTextObject : public QObject, public QTextObjectInterface |
|
47 { |
|
48 Q_OBJECT |
|
49 Q_INTERFACES(QTextObjectInterface) |
|
50 public: |
|
51 enum Properties { HbSmileyData = 1 }; |
|
52 //typedef QPair<QTextCursor*, HbIconAnimator*> HbSmileyDataType; |
|
53 |
|
54 public: |
|
55 QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, |
|
56 const QTextFormat &format); |
|
57 void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, |
|
58 int posInDocument, const QTextFormat &format); |
|
59 }; |
|
60 |
|
61 class HbSmileyEnginePrivate |
|
62 { |
|
63 Q_DECLARE_PUBLIC(HbSmileyEngine) |
|
64 public: |
|
65 enum { HbIconTextFormat = QTextFormat::UserObject + 1 }; |
|
66 HbSmileyEnginePrivate(); |
|
67 virtual ~HbSmileyEnginePrivate(); |
|
68 void init(); |
|
69 void cleanUp(); |
|
70 void setDocument(QTextDocument *doc); |
|
71 void insertSmiley( QTextCursor cursor, const QString& name); |
|
72 void insertSmileys( QTextCursor cursor, bool insertOne = false); |
|
73 HbIconAnimator* lookupAnimator(const QString& name); |
|
74 bool isCursorValid(QTextCursor* cursor) const; |
|
75 |
|
76 HbIconAnimator* animatorForCursor(const QTextCursor& cursor); |
|
77 void removeCursor(const QTextCursor &cursor, HbIconAnimator* animator); |
|
78 void convertToText(QTextDocument *copyDoc) const; |
|
79 |
|
80 void _q_animationProgressed(); |
|
81 void _q_documentContentsChanged(int position, int charsRemoved, int charsAdded); |
|
82 |
|
83 HbSmileyEngine *q_ptr; |
|
84 |
|
85 QTextDocument *mDocument; |
|
86 HbSmileyTheme mSmileyTheme; |
|
87 bool mEdited; |
|
88 QObject *mIconTextObject; |
|
89 qreal mScaleFactor; |
|
90 |
|
91 |
|
92 QHash<HbIconAnimator*, QList<QTextCursor*> > mAnimatorToCursors; |
|
93 QHash<QTextCursor*,HbIconAnimator*> mCursorToAnimator; |
|
94 QHash<QString, HbIconAnimator*> mSmileyAnimator; |
|
95 |
|
96 static HbSmileyTheme mDefaultTheme; |
|
97 }; |
|
98 |
|
99 Q_DECLARE_METATYPE(HbIconAnimator*) |
|
100 Q_DECLARE_METATYPE(HbSmileyDataType) |
|
101 |
|
102 |
|
103 #endif // HBSMILEYENGINE_P_P_H |