|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #ifndef __COPY_CUT_PASTE_SNIPPET_H__ |
|
23 #define __COPY_CUT_PASTE_SNIPPET_H__ |
|
24 |
|
25 #include "ChromeSnippet.h" |
|
26 #include "ChromeWidget.h" |
|
27 #include "NativeChromeItem.h" |
|
28 #include "ExternalEventCharm.h" |
|
29 |
|
30 #include <QPushButton> |
|
31 |
|
32 namespace GVA { |
|
33 |
|
34 class CopyCutPasteButton : public QObject |
|
35 { |
|
36 Q_OBJECT |
|
37 |
|
38 public: |
|
39 CopyCutPasteButton(const QString & text, QWidget * parent = 0); |
|
40 virtual ~CopyCutPasteButton() {} |
|
41 |
|
42 void render(QPainter * painter, const QPoint & targetOffset = QPoint()); |
|
43 void setMousePressed(bool pressed) { m_mousePressed = pressed; } |
|
44 QString text() const { return m_text; } |
|
45 void setText(QString & text) { m_text = text; } |
|
46 QSize size() const { return m_size; } |
|
47 void setFixedSize(int w, int h) { m_size = QSize(w, h); } |
|
48 void setDisabled(bool disabled) { m_disabled = disabled; } |
|
49 bool isEnabled() const { return !m_disabled; } |
|
50 |
|
51 void mousePressEvent(QGraphicsSceneMouseEvent * event); |
|
52 void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); |
|
53 |
|
54 signals: |
|
55 void clicked(); |
|
56 |
|
57 private: |
|
58 QString m_text; |
|
59 bool m_mousePressed; |
|
60 QSize m_size; |
|
61 bool m_disabled; |
|
62 }; |
|
63 |
|
64 class CopyCutPasteItem : public NativeChromeItem |
|
65 { |
|
66 Q_OBJECT |
|
67 |
|
68 public: |
|
69 CopyCutPasteItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent = 0); |
|
70 virtual ~CopyCutPasteItem(); |
|
71 void buildMenu(bool isContentSelected); |
|
72 void setEditorSnippet(ChromeSnippet * snippet) { m_editorSnippet = snippet; } |
|
73 ChromeSnippet * editorSnippet() { return m_editorSnippet; } |
|
74 |
|
75 private slots: |
|
76 void cut(); |
|
77 void copy(); |
|
78 void paste(); |
|
79 |
|
80 protected: |
|
81 virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget); |
|
82 virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); |
|
83 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); |
|
84 |
|
85 private: |
|
86 void reset(); |
|
87 |
|
88 private: |
|
89 CopyCutPasteButton * m_cutButton; |
|
90 CopyCutPasteButton * m_copyButton; |
|
91 CopyCutPasteButton * m_pasteButton; |
|
92 ChromeSnippet * m_editorSnippet; |
|
93 }; |
|
94 |
|
95 class CopyCutPasteSnippet : public ChromeSnippet |
|
96 { |
|
97 Q_OBJECT |
|
98 public: |
|
99 CopyCutPasteSnippet(const QString & elementId, ChromeWidget * chrome, QGraphicsWidget * widget, const QWebElement & element); |
|
100 virtual ~CopyCutPasteSnippet() { if (m_externalEventCharm) delete m_externalEventCharm ;} |
|
101 static CopyCutPasteSnippet * instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element); |
|
102 virtual void setChromeWidget(QGraphicsWidget * widget); |
|
103 |
|
104 public slots: |
|
105 virtual void setVisible(bool visiblity, bool animate = true); |
|
106 |
|
107 private: |
|
108 void connectAll(); |
|
109 CopyCutPasteItem *copyCutPasteItem(); |
|
110 |
|
111 private slots: |
|
112 void onTimeout(); |
|
113 void onChromeComplete(); |
|
114 void onContextEvent(bool isContentSelected, QString snippetId); |
|
115 void onExternalMouseEvent(QEvent *, const QString &, const QString &); |
|
116 void onAspectChanged(int aspect); |
|
117 |
|
118 private: |
|
119 QTimer * m_timer; |
|
120 ExternalEventCharm * m_externalEventCharm; |
|
121 }; |
|
122 } |
|
123 |
|
124 #endif |