summaryrefslogtreecommitdiff
Side-by-side diff
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
@@ -4,49 +4,50 @@
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "clipboard.h"
#include <qpe/resource.h>
#include <qpainter.h>
#include <qpopupmenu.h>
#include <qwindowsystem_qws.h>
-#include <qmessagebox.h>
+#include <qapplication.h>
+#include <qclipboard.h>
#include <qtimer.h>
//===========================================================================
/* XPM */
static const char * paste_xpm[] = {
"14 16 64 1",
" c None",
". c #020202",
"+ c #867616",
"@ c #A69A42",
"# c #BAB676",
"$ c #060606",
"% c #EAD2AA",
"& c #F6F6DA",
"* c #222212",
"= c #86761E",
"- c #868686",
"; c #5A5202",
"> c #8A7E2E",
", c #2C2C2C",
"' c #9A9A9A",
") c #F6EADA",
"! c #AAA262",
@@ -98,80 +99,135 @@ static const char * paste_xpm[] = {
"x c #E2E0E0",
"y c #7A7A7A",
" *{>; ",
" }}}@e:!;}}} ",
"<x8=&:#@+;ll, ",
"}k/=;;3}337|o ",
"<k's24444m45o ",
"}8'ss4xkkk]}a ",
"<1s224keee|b4 ",
"}r2itmkeee]]44",
"<9iitmkeeehkw.",
"<lt-u4keeb)pn.",
"<fu-umkebhp(0.",
"<cugg4kbh)_(q.",
"<cyyymk))p(%q.",
",5vvv4k)p_%[q.",
" ...$mljnn0qd.",
" 4.......,"};
ClipboardApplet::ClipboardApplet( QWidget *parent, const char *name ) : QWidget( parent, name )
{
setFixedWidth ( 14 );
setFixedHeight ( 18 );
- clipboardPixmap = QPixmap ( paste_xpm );
- menu = 0;
+ m_clipboardPixmap = QPixmap ( paste_xpm );
+
+ QTimer *timer = new QTimer ( this );
+
+ connect ( QApplication::clipboard ( ), SIGNAL( dataChanged ( )), this, SLOT( newData ( )));
+ connect ( timer, SIGNAL( timeout ( )), this, SLOT( newData ( )));
+
+ timer-> start ( 1000 );
+
+ m_menu = 0;
+ m_dirty = true;
+ m_lasttext = QString::null;
}
ClipboardApplet::~ClipboardApplet ( )
{
}
void ClipboardApplet::mousePressEvent ( QMouseEvent *)
{
- if ( !menu ) {
- menu = new QPopupMenu ( this );
- menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "cut" )), tr( "Cut" ), 0 );
- menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "copy" )), tr( "Copy" ), 1 );
- menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "paste" )), tr( "Paste" ), 2 );
- connect ( menu, SIGNAL( activated ( int )), this, SLOT( action ( int )));
+ if ( m_dirty ) {
+ delete m_menu;
+
+ m_menu = new QPopupMenu ( this );
+ m_menu-> setCheckable ( true );
+
+ if ( m_history. count ( )) {
+ for ( unsigned int i = 0; i < m_history. count ( ); i++ ) {
+ QString str = m_history [i];
+
+ if ( str. length ( ) > 20 )
+ str = str. left ( 20 ) + "...";
+
+ m_menu-> insertItem ( QString ( "%1: %2" ). arg ( i + 1 ). arg ( str ), i );
+ m_menu-> setItemChecked ( i, false );
+ }
+ m_menu-> setItemChecked ( m_history. count ( ) - 1, true );
+ m_menu-> insertSeparator ( );
+ }
+ m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "cut" )), tr( "Cut" ), 100 );
+ m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "copy" )), tr( "Copy" ), 101 );
+ m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "paste" )), tr( "Paste" ), 102 );
+
+ connect ( m_menu, SIGNAL( activated ( int )), this, SLOT( action ( int )));
+
+ m_dirty = false;
}
QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
- QSize s = menu-> sizeHint ( );
+ QSize s = m_menu-> sizeHint ( );
- menu-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( )));
+ m_menu-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( )));
}
void ClipboardApplet::action(int id)
{
- ushort unicode=0;
- int scan=0;
+ ushort unicode = 0;
+ int scan = 0;
switch ( id ) {
- case 0:
- unicode='X'-'@';
- scan=Key_X; // Cut
+ case 100:
+ unicode = 'X' - '@';
+ scan = Key_X; // Cut
+ break;
+ case 101:
+ unicode = 'C' - '@';
+ scan = Key_C; // Copy
break;
- case 1:
- unicode='C'-'@';
- scan=Key_C; // Copy
+ case 102:
+ unicode = 'V' - '@';
+ scan = Key_V; // Paste
break;
- case 2:
- unicode='V'-'@';
- scan=Key_V; // Paste
+
+ default:
+ if (( id >= 0 ) && ( uint( id ) < m_history. count ( ))) {
+ QApplication::clipboard ( )-> setText ( m_history [id] );
+
+ for ( uint i = 0; i < m_history. count ( ); i++ )
+ m_menu-> setItemChecked ( i, i == uint( id ));
+
+ unicode = 'V' - '@';
+ scan = Key_V;
+ }
break;
}
if ( scan ) {
qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false );
qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false );
}
}
void ClipboardApplet::paintEvent ( QPaintEvent* )
{
QPainter p ( this );
- p. drawPixmap ( 0, 1, clipboardPixmap );
+ p. drawPixmap ( 0, 1, m_clipboardPixmap );
}
+void ClipboardApplet::newData ( )
+{
+ QCString type = "plain";
+ QString txt = QApplication::clipboard ( )-> text ( type );
+
+ if ( !txt. isEmpty ( ) && !m_history. contains ( txt )) {
+ m_history. append ( txt );
+ if ( m_history. count ( ) > 5 )
+ m_history. remove ( m_history. begin ( ));
+
+ m_dirty = true;
+ }
+}
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 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef __CLIPBOARD_APPLET_H__
#define __CLIPBOARD_APPLET_H__
#include <qwidget.h>
#include <qpixmap.h>
+#include <qstringlist.h>
class ClipboardApplet : public QWidget
{
Q_OBJECT
public:
- ClipboardApplet( QWidget *parent = 0, const char *name=0 );
- ~ClipboardApplet();
+ ClipboardApplet ( QWidget *parent = 0, const char *name=0 );
+ ~ClipboardApplet ( );
protected:
- void mousePressEvent( QMouseEvent *);
- void paintEvent( QPaintEvent* );
+ void mousePressEvent ( QMouseEvent *);
+ void paintEvent ( QPaintEvent* );
private slots:
- void action(int);
+ void action ( int );
+ void newData ( );
private:
- QPopupMenu* menu;
- QPixmap clipboardPixmap;
+ QPopupMenu * m_menu;
+ QStringList m_history;
+ bool m_dirty;
+ QString m_lasttext;
+
+ QPixmap m_clipboardPixmap;
};
#endif // __CLIPBOARD_APPLET_H__