summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/clipboardapplet/clipboard.cpp102
-rw-r--r--core/applets/clipboardapplet/clipboard.h20
2 files changed, 92 insertions, 30 deletions
diff --git a/core/applets/clipboardapplet/clipboard.cpp b/core/applets/clipboardapplet/clipboard.cpp
index 203e23e..181f4bf 100644
--- a/core/applets/clipboardapplet/clipboard.cpp
+++ b/core/applets/clipboardapplet/clipboard.cpp
@@ -1,177 +1,233 @@
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 <qpe/resource.h> 23#include <qpe/resource.h>
24 24
25#include <qpainter.h> 25#include <qpainter.h>
26#include <qpopupmenu.h> 26#include <qpopupmenu.h>
27#include <qwindowsystem_qws.h> 27#include <qwindowsystem_qws.h>
28#include <qmessagebox.h> 28#include <qapplication.h>
29#include <qclipboard.h>
29#include <qtimer.h> 30#include <qtimer.h>
30 31
31//=========================================================================== 32//===========================================================================
32 33
33/* XPM */ 34/* XPM */
34static const char * paste_xpm[] = { 35static const char * paste_xpm[] = {
35"14 16 64 1", 36"14 16 64 1",
36 " c None", 37 " c None",
37 ".c #020202", 38 ".c #020202",
38 "+c #867616", 39 "+c #867616",
39 "@c #A69A42", 40 "@c #A69A42",
40 "#c #BAB676", 41 "#c #BAB676",
41 "$c #060606", 42 "$c #060606",
42 "%c #EAD2AA", 43 "%c #EAD2AA",
43 "&c #F6F6DA", 44 "&c #F6F6DA",
44 "*c #222212", 45 "*c #222212",
45 "=c #86761E", 46 "=c #86761E",
46 "-c #868686", 47 "-c #868686",
47 ";c #5A5202", 48 ";c #5A5202",
48 ">c #8A7E2E", 49 ">c #8A7E2E",
49 ",c #2C2C2C", 50 ",c #2C2C2C",
50 "'c #9A9A9A", 51 "'c #9A9A9A",
51 ")c #F6EADA", 52 ")c #F6EADA",
52 "!c #AAA262", 53 "!c #AAA262",
53 "~c #323232", 54 "~c #323232",
54 "{c #726A32", 55 "{c #726A32",
55 "]c #6E6E6E", 56 "]c #6E6E6E",
56 "^c #C2B69E", 57 "^c #C2B69E",
57 "/c #9E9E9E", 58 "/c #9E9E9E",
58 "(c #EED6BA", 59 "(c #EED6BA",
59 "_c #F2DEC2", 60 "_c #F2DEC2",
60 ":c #D2CE8E", 61 ":c #D2CE8E",
61 "<c #3A3A3A", 62 "<c #3A3A3A",
62 "[c #EACAA2", 63 "[c #EACAA2",
63 "}c #3E3E3E", 64 "}c #3E3E3E",
64 "|c #727272", 65 "|c #727272",
65 "1c #CECECE", 66 "1c #CECECE",
66 "2c #929292", 67 "2c #929292",
67 "3c #4A462A", 68 "3c #4A462A",
68 "4c #424242", 69 "4c #424242",
69 "5c #666666", 70 "5c #666666",
70 "6c #C2AE96", 71 "6c #C2AE96",
71 "7c #767676", 72 "7c #767676",
72 "8c #D6D6D6", 73 "8c #D6D6D6",
73 "9c #C2C2C2", 74 "9c #C2C2C2",
74 "0c #BFA681", 75 "0c #BFA681",
75 "ac #1E1E1E", 76 "ac #1E1E1E",
76 "bc #FAF6F3", 77 "bc #FAF6F3",
77 "cc #AEAEAE", 78 "cc #AEAEAE",
78 "dc #C29A6A", 79 "dc #C29A6A",
79 "ec #FEFEFE", 80 "ec #FEFEFE",
80 "fc #B6B6B6", 81 "fc #B6B6B6",
81 "gc #7E7E7E", 82 "gc #7E7E7E",
82 "hc #FAF2E6", 83 "hc #FAF2E6",
83 "ic #8E8E8E", 84 "ic #8E8E8E",
84 "jc #C6BCAE", 85 "jc #C6BCAE",
85 "kc #DEDEDE", 86 "kc #DEDEDE",
86 "lc #BEBEBE", 87 "lc #BEBEBE",
87 "mc #464646", 88 "mc #464646",
88 "nc #BEAE92", 89 "nc #BEAE92",
89 "oc #262626", 90 "oc #262626",
90 "pc #F2E2CE", 91 "pc #F2E2CE",
91 "qc #C2A175", 92 "qc #C2A175",
92 "rc #CACACA", 93 "rc #CACACA",
93 "sc #969696", 94 "sc #969696",
94 "tc #8A8A8A", 95 "tc #8A8A8A",
95 "uc #828282", 96 "uc #828282",
96 "vc #6A6A6A", 97 "vc #6A6A6A",
97 "wc #BEB6AE", 98 "wc #BEB6AE",
98 "xc #E2E0E0", 99 "xc #E2E0E0",
99 "yc #7A7A7A", 100 "yc #7A7A7A",
100" *{>; ", 101" *{>; ",
101" }}}@e:!;}}} ", 102" }}}@e:!;}}} ",
102"<x8=&:#@+;ll, ", 103"<x8=&:#@+;ll, ",
103"}k/=;;3}337|o ", 104"}k/=;;3}337|o ",
104"<k's24444m45o ", 105"<k's24444m45o ",
105"}8'ss4xkkk]}a ", 106"}8'ss4xkkk]}a ",
106"<1s224keee|b4 ", 107"<1s224keee|b4 ",
107"}r2itmkeee]]44", 108"}r2itmkeee]]44",
108"<9iitmkeeehkw.", 109"<9iitmkeeehkw.",
109"<lt-u4keeb)pn.", 110"<lt-u4keeb)pn.",
110"<fu-umkebhp(0.", 111"<fu-umkebhp(0.",
111"<cugg4kbh)_(q.", 112"<cugg4kbh)_(q.",
112"<cyyymk))p(%q.", 113"<cyyymk))p(%q.",
113",5vvv4k)p_%[q.", 114",5vvv4k)p_%[q.",
114" ...$mljnn0qd.", 115" ...$mljnn0qd.",
115" 4.......,"}; 116" 4.......,"};
116 117
117 118
118ClipboardApplet::ClipboardApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) 119ClipboardApplet::ClipboardApplet( QWidget *parent, const char *name ) : QWidget( parent, name )
119{ 120{
120 setFixedWidth ( 14 ); 121 setFixedWidth ( 14 );
121 setFixedHeight ( 18 ); 122 setFixedHeight ( 18 );
122 clipboardPixmap = QPixmap ( paste_xpm ); 123 m_clipboardPixmap = QPixmap ( paste_xpm );
123 menu = 0; 124
125 QTimer *timer = new QTimer ( this );
126
127 connect ( QApplication::clipboard ( ), SIGNAL( dataChanged ( )), this, SLOT( newData ( )));
128 connect ( timer, SIGNAL( timeout ( )), this, SLOT( newData ( )));
129
130 timer-> start ( 1000 );
131
132 m_menu = 0;
133 m_dirty = true;
134 m_lasttext = QString::null;
124} 135}
125 136
126ClipboardApplet::~ClipboardApplet ( ) 137ClipboardApplet::~ClipboardApplet ( )
127{ 138{
128} 139}
129 140
130void ClipboardApplet::mousePressEvent ( QMouseEvent *) 141void ClipboardApplet::mousePressEvent ( QMouseEvent *)
131{ 142{
132 if ( !menu ) { 143 if ( m_dirty ) {
133 menu = new QPopupMenu ( this ); 144 delete m_menu;
134 menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "cut" )), tr( "Cut" ), 0 ); 145
135 menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "copy" )), tr( "Copy" ), 1 ); 146 m_menu = new QPopupMenu ( this );
136 menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "paste" )), tr( "Paste" ), 2 ); 147 m_menu-> setCheckable ( true );
137 connect ( menu, SIGNAL( activated ( int )), this, SLOT( action ( int ))); 148
149 if ( m_history. count ( )) {
150 for ( unsigned int i = 0; i < m_history. count ( ); i++ ) {
151 QString str = m_history [i];
152
153 if ( str. length ( ) > 20 )
154 str = str. left ( 20 ) + "...";
155
156 m_menu-> insertItem ( QString ( "%1: %2" ). arg ( i + 1 ). arg ( str ), i );
157 m_menu-> setItemChecked ( i, false );
158 }
159 m_menu-> setItemChecked ( m_history. count ( ) - 1, true );
160 m_menu-> insertSeparator ( );
161 }
162 m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "cut" )), tr( "Cut" ), 100 );
163 m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "copy" )), tr( "Copy" ), 101 );
164 m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "paste" )), tr( "Paste" ), 102 );
165
166 connect ( m_menu, SIGNAL( activated ( int )), this, SLOT( action ( int )));
167
168 m_dirty = false;
138 } 169 }
139 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 170 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
140 QSize s = menu-> sizeHint ( ); 171 QSize s = m_menu-> sizeHint ( );
141 172
142 menu-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ))); 173 m_menu-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( )));
143} 174}
144 175
145void ClipboardApplet::action(int id) 176void ClipboardApplet::action(int id)
146{ 177{
147 ushort unicode=0; 178 ushort unicode = 0;
148 int scan=0; 179 int scan = 0;
149 180
150 switch ( id ) { 181 switch ( id ) {
151 case 0: 182 case 100:
152 unicode='X'-'@'; 183 unicode = 'X' - '@';
153 scan=Key_X; // Cut 184 scan = Key_X; // Cut
185 break;
186 case 101:
187 unicode = 'C' - '@';
188 scan = Key_C; // Copy
154 break; 189 break;
155 case 1: 190 case 102:
156 unicode='C'-'@'; 191 unicode = 'V' - '@';
157 scan=Key_C; // Copy 192 scan = Key_V; // Paste
158 break; 193 break;
159 case 2: 194
160 unicode='V'-'@'; 195 default:
161 scan=Key_V; // Paste 196 if (( id >= 0 ) && ( uint( id ) < m_history. count ( ))) {
197 QApplication::clipboard ( )-> setText ( m_history [id] );
198
199 for ( uint i = 0; i < m_history. count ( ); i++ )
200 m_menu-> setItemChecked ( i, i == uint( id ));
201
202 unicode = 'V' - '@';
203 scan = Key_V;
204 }
162 break; 205 break;
163 } 206 }
164 207
165 if ( scan ) { 208 if ( scan ) {
166 qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false ); 209 qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false );
167 qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false ); 210 qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false );
168 } 211 }
169} 212}
170 213
171void ClipboardApplet::paintEvent ( QPaintEvent* ) 214void ClipboardApplet::paintEvent ( QPaintEvent* )
172{ 215{
173 QPainter p ( this ); 216 QPainter p ( this );
174 p. drawPixmap ( 0, 1, clipboardPixmap ); 217 p. drawPixmap ( 0, 1, m_clipboardPixmap );
175} 218}
176 219
220void ClipboardApplet::newData ( )
221{
222 QCString type = "plain";
223 QString txt = QApplication::clipboard ( )-> text ( type );
224
225 if ( !txt. isEmpty ( ) && !m_history. contains ( txt )) {
226 m_history. append ( txt );
177 227
228 if ( m_history. count ( ) > 5 )
229 m_history. remove ( m_history. begin ( ));
230
231 m_dirty = true;
232 }
233}
diff --git a/core/applets/clipboardapplet/clipboard.h b/core/applets/clipboardapplet/clipboard.h
index 9dd59ed..84743d9 100644
--- a/core/applets/clipboardapplet/clipboard.h
+++ b/core/applets/clipboardapplet/clipboard.h
@@ -1,47 +1,53 @@
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#ifndef __CLIPBOARD_APPLET_H__ 20#ifndef __CLIPBOARD_APPLET_H__
21#define __CLIPBOARD_APPLET_H__ 21#define __CLIPBOARD_APPLET_H__
22 22
23#include <qwidget.h> 23#include <qwidget.h>
24#include <qpixmap.h> 24#include <qpixmap.h>
25#include <qstringlist.h>
25 26
26class ClipboardApplet : public QWidget 27class ClipboardApplet : public QWidget
27{ 28{
28 Q_OBJECT 29 Q_OBJECT
29public: 30public:
30 ClipboardApplet( QWidget *parent = 0, const char *name=0 ); 31 ClipboardApplet ( QWidget *parent = 0, const char *name=0 );
31 ~ClipboardApplet(); 32 ~ClipboardApplet ( );
32 33
33protected: 34protected:
34 void mousePressEvent( QMouseEvent *); 35 void mousePressEvent ( QMouseEvent *);
35 void paintEvent( QPaintEvent* ); 36 void paintEvent ( QPaintEvent* );
36 37
37private slots: 38private slots:
38 void action(int); 39 void action ( int );
40 void newData ( );
39 41
40private: 42private:
41 QPopupMenu* menu; 43 QPopupMenu * m_menu;
42 QPixmap clipboardPixmap; 44 QStringList m_history;
45 bool m_dirty;
46 QString m_lasttext;
47
48 QPixmap m_clipboardPixmap;
43}; 49};
44 50
45 51
46#endif // __CLIPBOARD_APPLET_H__ 52#endif // __CLIPBOARD_APPLET_H__
47 53