Diffstat (limited to 'core/applets/clipboardapplet/clipboard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/clipboardapplet/clipboard.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/core/applets/clipboardapplet/clipboard.cpp b/core/applets/clipboardapplet/clipboard.cpp index 34d151e..4fc8076 100644 --- a/core/applets/clipboardapplet/clipboard.cpp +++ b/core/applets/clipboardapplet/clipboard.cpp | |||
@@ -1,189 +1,189 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "clipboard.h" | 21 | #include "clipboard.h" |
22 | 22 | ||
23 | #include <opie2/otaskbarapplet.h> | 23 | #include <opie2/otaskbarapplet.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/applnk.h> | 25 | #include <qpe/applnk.h> |
26 | 26 | ||
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qpopupmenu.h> | 28 | #include <qpopupmenu.h> |
29 | #include <qwindowsystem_qws.h> | 29 | #include <qwindowsystem_qws.h> |
30 | #include <qapplication.h> | 30 | #include <qapplication.h> |
31 | #include <qclipboard.h> | 31 | #include <qclipboard.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | 33 | ||
34 | //=========================================================================== | 34 | //=========================================================================== |
35 | 35 | ||
36 | 36 | ||
37 | ClipboardApplet::ClipboardApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) | 37 | ClipboardApplet::ClipboardApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) |
38 | { | 38 | { |
39 | setFixedWidth ( AppLnk::smallIconSize() ); | 39 | setFixedWidth ( AppLnk::smallIconSize() ); |
40 | setFixedHeight ( AppLnk::smallIconSize() ); | 40 | setFixedHeight ( AppLnk::smallIconSize() ); |
41 | 41 | ||
42 | QImage img = Resource::loadImage( "paste"); | 42 | QImage img = Resource::loadImage( "paste"); |
43 | img = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 43 | img = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
44 | 44 | ||
45 | m_clipboardPixmap.convertFromImage( img ); | 45 | m_clipboardPixmap.convertFromImage( img ); |
46 | 46 | ||
47 | m_timer = new QTimer ( this ); | 47 | m_timer = new QTimer ( this ); |
48 | 48 | ||
49 | connect ( QApplication::clipboard ( ), SIGNAL( dataChanged ( )), this, SLOT( newData ( ))); | 49 | connect ( QApplication::clipboard ( ), SIGNAL( dataChanged()), this, SLOT( newData())); |
50 | connect ( m_timer, SIGNAL( timeout ( )), this, SLOT( newData ( ))); | 50 | connect ( m_timer, SIGNAL( timeout()), this, SLOT( newData())); |
51 | connect ( qApp, SIGNAL( aboutToQuit ( )), this, SLOT( shutdown ( ))); | 51 | connect ( qApp, SIGNAL( aboutToQuit()), this, SLOT( shutdown())); |
52 | 52 | ||
53 | m_menu = 0; | 53 | m_menu = 0; |
54 | m_dirty = true; | 54 | m_dirty = true; |
55 | m_lasttext = QString::null; | 55 | m_lasttext = QString::null; |
56 | 56 | ||
57 | m_timer-> start ( 0, true ); | 57 | m_timer-> start ( 0, true ); |
58 | } | 58 | } |
59 | 59 | ||
60 | ClipboardApplet::~ClipboardApplet ( ) | 60 | ClipboardApplet::~ClipboardApplet ( ) |
61 | { | 61 | { |
62 | } | 62 | } |
63 | 63 | ||
64 | int ClipboardApplet::position() | 64 | int ClipboardApplet::position() |
65 | { | 65 | { |
66 | return 6; | 66 | return 6; |
67 | } | 67 | } |
68 | 68 | ||
69 | void ClipboardApplet::shutdown ( ) | 69 | void ClipboardApplet::shutdown ( ) |
70 | { | 70 | { |
71 | // the timer has to be stopped, or Qt/E will hang on quit() | 71 | // the timer has to be stopped, or Qt/E will hang on quit() |
72 | // see launcher/desktop.cpp | 72 | // see launcher/desktop.cpp |
73 | 73 | ||
74 | m_timer-> stop ( ); | 74 | m_timer-> stop ( ); |
75 | } | 75 | } |
76 | 76 | ||
77 | void ClipboardApplet::mousePressEvent ( QMouseEvent *) | 77 | void ClipboardApplet::mousePressEvent ( QMouseEvent *) |
78 | { | 78 | { |
79 | if ( m_dirty ) { | 79 | if ( m_dirty ) { |
80 | delete m_menu; | 80 | delete m_menu; |
81 | 81 | ||
82 | m_menu = new QPopupMenu ( this ); | 82 | m_menu = new QPopupMenu ( this ); |
83 | m_menu-> setCheckable ( true ); | 83 | m_menu-> setCheckable ( true ); |
84 | 84 | ||
85 | if ( m_history. count ( )) { | 85 | if ( m_history. count ( )) { |
86 | for ( unsigned int i = 0; i < m_history. count ( ); i++ ) { | 86 | for ( unsigned int i = 0; i < m_history. count ( ); i++ ) { |
87 | QString str = m_history [i]; | 87 | QString str = m_history [i]; |
88 | 88 | ||
89 | if ( str. length ( ) > 20 ) | 89 | if ( str. length ( ) > 20 ) |
90 | str = str. left ( 20 ) + "..."; | 90 | str = str. left ( 20 ) + "..."; |
91 | 91 | ||
92 | m_menu-> insertItem ( QString ( "%1: %2" ). arg ( i + 1 ). arg ( str ), i ); | 92 | m_menu-> insertItem ( QString ( "%1: %2" ). arg ( i + 1 ). arg ( str ), i ); |
93 | m_menu-> setItemChecked ( i, false ); | 93 | m_menu-> setItemChecked ( i, false ); |
94 | } | 94 | } |
95 | m_menu-> setItemChecked ( m_history. count ( ) - 1, true ); | 95 | m_menu-> setItemChecked ( m_history. count ( ) - 1, true ); |
96 | m_menu-> insertSeparator ( ); | 96 | m_menu-> insertSeparator ( ); |
97 | } | 97 | } |
98 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "cut" )), tr( "Cut" ), 100 ); | 98 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "cut" )), tr( "Cut" ), 100 ); |
99 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "copy" )), tr( "Copy" ), 101 ); | 99 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "copy" )), tr( "Copy" ), 101 ); |
100 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "paste" )), tr( "Paste" ), 102 ); | 100 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "paste" )), tr( "Paste" ), 102 ); |
101 | 101 | ||
102 | connect ( m_menu, SIGNAL( activated ( int )), this, SLOT( action ( int ))); | 102 | connect ( m_menu, SIGNAL( activated(int)), this, SLOT( action(int))); |
103 | 103 | ||
104 | m_dirty = false; | 104 | m_dirty = false; |
105 | } | 105 | } |
106 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); | 106 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); |
107 | QSize s = m_menu-> sizeHint ( ); | 107 | QSize s = m_menu-> sizeHint ( ); |
108 | 108 | ||
109 | m_menu-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ))); | 109 | m_menu-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ))); |
110 | } | 110 | } |
111 | 111 | ||
112 | void ClipboardApplet::action(int id) | 112 | void ClipboardApplet::action(int id) |
113 | { | 113 | { |
114 | ushort unicode = 0; | 114 | ushort unicode = 0; |
115 | int scan = 0; | 115 | int scan = 0; |
116 | 116 | ||
117 | switch ( id ) { | 117 | switch ( id ) { |
118 | case 100: | 118 | case 100: |
119 | unicode = 'X' - '@'; | 119 | unicode = 'X' - '@'; |
120 | scan = Key_X; // Cut | 120 | scan = Key_X; // Cut |
121 | break; | 121 | break; |
122 | case 101: | 122 | case 101: |
123 | unicode = 'C' - '@'; | 123 | unicode = 'C' - '@'; |
124 | scan = Key_C; // Copy | 124 | scan = Key_C; // Copy |
125 | break; | 125 | break; |
126 | case 102: | 126 | case 102: |
127 | unicode = 'V' - '@'; | 127 | unicode = 'V' - '@'; |
128 | scan = Key_V; // Paste | 128 | scan = Key_V; // Paste |
129 | break; | 129 | break; |
130 | 130 | ||
131 | default: | 131 | default: |
132 | if (( id >= 0 ) && ( uint( id ) < m_history. count ( ))) { | 132 | if (( id >= 0 ) && ( uint( id ) < m_history. count ( ))) { |
133 | QApplication::clipboard ( )-> setText ( m_history [id] ); | 133 | QApplication::clipboard ( )-> setText ( m_history [id] ); |
134 | 134 | ||
135 | for ( uint i = 0; i < m_history. count ( ); i++ ) | 135 | for ( uint i = 0; i < m_history. count ( ); i++ ) |
136 | m_menu-> setItemChecked ( i, i == uint( id )); | 136 | m_menu-> setItemChecked ( i, i == uint( id )); |
137 | 137 | ||
138 | unicode = 'V' - '@'; | 138 | unicode = 'V' - '@'; |
139 | scan = Key_V; | 139 | scan = Key_V; |
140 | } | 140 | } |
141 | break; | 141 | break; |
142 | } | 142 | } |
143 | 143 | ||
144 | if ( scan ) { | 144 | if ( scan ) { |
145 | qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false ); | 145 | qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false ); |
146 | qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, false, false ); | 146 | qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, false, false ); |
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | void ClipboardApplet::paintEvent ( QPaintEvent* ) | 150 | void ClipboardApplet::paintEvent ( QPaintEvent* ) |
151 | { | 151 | { |
152 | QPainter p ( this ); | 152 | QPainter p ( this ); |
153 | /* center the height but our pixmap is as big as the height ;)*/ | 153 | /* center the height but our pixmap is as big as the height ;)*/ |
154 | p. drawPixmap( 0, 0, | 154 | p. drawPixmap( 0, 0, |
155 | m_clipboardPixmap ); | 155 | m_clipboardPixmap ); |
156 | } | 156 | } |
157 | 157 | ||
158 | void ClipboardApplet::newData ( ) | 158 | void ClipboardApplet::newData ( ) |
159 | { | 159 | { |
160 | static bool excllock = false; | 160 | static bool excllock = false; |
161 | 161 | ||
162 | if ( excllock ) | 162 | if ( excllock ) |
163 | return; | 163 | return; |
164 | else | 164 | else |
165 | excllock = true; | 165 | excllock = true; |
166 | 166 | ||
167 | m_timer-> stop ( ); | 167 | m_timer-> stop ( ); |
168 | 168 | ||
169 | QCString type = "plain"; | 169 | QCString type = "plain"; |
170 | QString txt = QApplication::clipboard ( )-> text ( type ); | 170 | QString txt = QApplication::clipboard ( )-> text ( type ); |
171 | 171 | ||
172 | if ( !txt. isEmpty ( ) && !m_history. contains ( txt )) { | 172 | if ( !txt. isEmpty ( ) && !m_history. contains ( txt )) { |
173 | m_history. append ( txt ); | 173 | m_history. append ( txt ); |
174 | 174 | ||
175 | if ( m_history. count ( ) > 5 ) | 175 | if ( m_history. count ( ) > 5 ) |
176 | m_history. remove ( m_history. begin ( )); | 176 | m_history. remove ( m_history. begin ( )); |
177 | 177 | ||
178 | m_dirty = true; | 178 | m_dirty = true; |
179 | } | 179 | } |
180 | 180 | ||
181 | m_timer-> start ( 1500, true ); | 181 | m_timer-> start ( 1500, true ); |
182 | 182 | ||
183 | excllock = false; | 183 | excllock = false; |
184 | } | 184 | } |
185 | 185 | ||
186 | Q_EXPORT_INTERFACE() | 186 | Q_EXPORT_INTERFACE() |
187 | { | 187 | { |
188 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<ClipboardApplet> ); | 188 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<ClipboardApplet> ); |
189 | } | 189 | } |