author | sandman <sandman> | 2002-06-26 00:43:45 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-06-26 00:43:45 (UTC) |
commit | d31131a054c7ab5d42034d040dae5b72a3338085 (patch) (side-by-side diff) | |
tree | 8e4796072b772450ee0f41a23dd570482363a65a /core/applets/clipboardapplet | |
parent | b970aebbdfc7e6f811c9b75ee62ad9370f74ace0 (diff) | |
download | opie-d31131a054c7ab5d42034d040dae5b72a3338085.zip opie-d31131a054c7ab5d42034d040dae5b72a3338085.tar.gz opie-d31131a054c7ab5d42034d040dae5b72a3338085.tar.bz2 |
Added FIFO history entries for the last 5 cut/copy operations.
-rw-r--r-- | core/applets/clipboardapplet/clipboard.cpp | 86 | ||||
-rw-r--r-- | core/applets/clipboardapplet/clipboard.h | 10 |
2 files changed, 79 insertions, 17 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 @@ -27,3 +27,4 @@ #include <qwindowsystem_qws.h> -#include <qmessagebox.h> +#include <qapplication.h> +#include <qclipboard.h> #include <qtimer.h> @@ -121,4 +122,14 @@ ClipboardApplet::ClipboardApplet( QWidget *parent, const char *name ) : QWidget( 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; } @@ -131,13 +142,33 @@ 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 ( ))); } @@ -150,3 +181,3 @@ void ClipboardApplet::action(int id) switch ( id ) { - case 0: + case 100: unicode='X'-'@'; @@ -154,3 +185,3 @@ void ClipboardApplet::action(int id) break; - case 1: + case 101: unicode='C'-'@'; @@ -158,3 +189,3 @@ void ClipboardApplet::action(int id) break; - case 2: + case 102: unicode='V'-'@'; @@ -162,2 +193,14 @@ void ClipboardApplet::action(int id) break; + + 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; } @@ -173,5 +216,18 @@ 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 @@ -24,2 +24,3 @@ #include <qpixmap.h> +#include <qstringlist.h> @@ -38,6 +39,11 @@ private slots: 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; }; |