Diffstat (limited to 'core/applets/clipboardapplet/clipboard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/clipboardapplet/clipboard.cpp | 102 |
1 files changed, 79 insertions, 23 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 | |||
@@ -26,5 +26,6 @@ | |||
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 | ||
@@ -120,6 +121,16 @@ ClipboardApplet::ClipboardApplet( QWidget *parent, const char *name ) : QWidget( | |||
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 | ||
@@ -130,34 +141,66 @@ ClipboardApplet::~ClipboardApplet ( ) | |||
130 | void ClipboardApplet::mousePressEvent ( QMouseEvent *) | 141 | void 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 | ||
145 | void ClipboardApplet::action(int id) | 176 | void 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 | } |
@@ -172,6 +215,19 @@ void 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 | ||
220 | void 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 | } | ||