author | ibotty <ibotty> | 2002-10-06 19:17:57 (UTC) |
---|---|---|
committer | ibotty <ibotty> | 2002-10-06 19:17:57 (UTC) |
commit | e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f (patch) (side-by-side diff) | |
tree | 88b9d305f7b12f1c7a9be01a027c1db73ee13dd0 | |
parent | aa8332baeebf7056d81fc245399477c7feaa1235 (diff) | |
download | opie-e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f.zip opie-e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f.tar.gz opie-e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f.tar.bz2 |
wrote first incarnation of widget_layer.cpp.
edited widget_layer.h accordingly.
-rw-r--r-- | noncore/apps/opie-console/opie-console.pro | 6 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.cpp | 155 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.h | 104 |
3 files changed, 246 insertions, 19 deletions
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro index 831ca34..5c2d04e 100644 --- a/noncore/apps/opie-console/opie-console.pro +++ b/noncore/apps/opie-console/opie-console.pro @@ -23,3 +23,4 @@ HEADERS = io_layer.h io_serial.h \ screen.h \ - keytrans.h + keytrans.h \ + widget_layer.h @@ -42,3 +43,4 @@ SOURCES = io_layer.cpp io_serial.cpp \ screen.cpp \ - keytrans.cpp + keytrans.cpp \ + widget_layer.cpp diff --git a/noncore/apps/opie-console/widget_layer.cpp b/noncore/apps/opie-console/widget_layer.cpp new file mode 100644 index 0000000..28227e4 --- a/dev/null +++ b/noncore/apps/opie-console/widget_layer.cpp @@ -0,0 +1,155 @@ +/* ------------------------------------------------------------------------- */ +/* */ +/* widget_layer.cpp Widget Layer */ +/* */ +/* opie developers <opie@handhelds.org> */ +/* */ +/* ------------------------------------------------------------------------- */ + + + +#include "widget_layer.h" + +#include <qclipboard.h> +#include <qregexp.h> +#include <qglobal.h> + +#include <string.h> +//#include < + +#include "common.h" + + +#define loc(X,Y) ((Y)*m_columns+(X)) + + +WidgetLayer::WidgetLayer( QObject *parent, const char *name ) : QObject( parent, name ) +{ + // get the clipboard + m_clipboard = QApplication::clipboard(); + + // when data on clipboard changes, clear selection + QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), + (QObject*)this, SLOT( onClearSelection() ) ); + + // initialize vars: + m_lines = 1; + m_columns = 1; + m_resizing = false; + + m_image = QArray<Character>(); +} + +WidgetLayer::~WidgetLayer() +{ + // clean up! +} + +/* --------------------------------- audio ---------------------------------- */ + +void WidgetLayer::bell() +{ + QApplication::beep(); +} + + +/* --------------------------------- screen --------------------------------- */ + + +void WidgetLayer::propagateSize() +{ + QArray<Character> oldimage = m_image; + int oldlines = m_lines; + int oldcolumns = m_columns; + + makeImage(); + + // copy old image, to reduce flicker + if ( oldimage ) + { + //FIXME: is it possible to do this with QArray.dublicate()? + + int lins = QMIN( oldlines, m_lines ); + int cols = QMIN( oldcolumns, m_columns ); + for ( int lin = 0; lin < lins; ++lin ) + { + memcpy( (void*) &m_image[m_columns*lin], + (void*) &oldimage[oldcolumns*lin], + cols*sizeof( Character ) ); + } + //free( oldimage ); + } + else + clearImage(); + + m_resizing = true; + emit imageSizeChanged( m_lines, m_columns ); + m_resizing = false; +} + +void WidgetLayer::makeImage() +{ + calcGeometry(); + m_image = QArray<Character>(); + clearImage(); +} + +void WidgetLayer::clearImage() +{ + //should this belong here?? + for ( int y = 0; y < m_lines; y++ ) + for ( int x = 0; x < m_columns; x++ ) + { + m_image[loc(x,y)].c = 0xff; + m_image[loc(x,y)].f = 0xff; + m_image[loc(x,y)].b = 0xff; + m_image[loc(x,y)].r = 0xff; + } +} + +/* --------------------------------- selection ------------------------------ */ + +void WidgetLayer::pasteClipboard() +{ + insertSelection(); +} + + +void WidgetLayer::insertSelection() +{ + QString text = QApplication::clipboard()->text(); + if ( ! text.isNull() ) + { + text.replace( QRegExp( "\n" ), "\r" ); + insertText( text ); + // selection should be unselected + emit selectionCleared(); + } +} + +void WidgetLayer::insertText( QString text ) +{ + // text is inserted as key event + QKeyEvent e( QEvent::KeyPress, 0, -1, 0, text); + emit keyPressed( &e ); +} + +void WidgetLayer::onClearSelection() +{ + emit selectionCleared(); +} + +void WidgetLayer::setSelection( const QString& text ) +{ + // why get the clipboard, we have it as instance var... + QObject *m_clipboard = QApplication::clipboard(); + + // we know, that cliboard changes, when we change clipboard + QObject::disconnect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), + (QObject*) this, SLOT( selectionCleared() ) ); + + QApplication::clipboard()->setText( text ); + + QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), + (QObject*) this, SLOT( selectionCleared() ) ); +} diff --git a/noncore/apps/opie-console/widget_layer.h b/noncore/apps/opie-console/widget_layer.h index cf2a1e5..3cdd6aa 100644 --- a/noncore/apps/opie-console/widget_layer.h +++ b/noncore/apps/opie-console/widget_layer.h @@ -1,2 +1,2 @@ - +/* -------------------------------------------------------------------------- */ /* */ @@ -12,7 +12,21 @@ +#ifndef WIDGET_LAYER_H +#define WIDGET_LAYER_H + +// qt includes +#include <qapplication.h> +#include <qtimer.h> +#include <qkeycode.h> +#include <qclipboard.h> + + +// opie-console includes +#include "session.h" +#include "common.h" class WidgetLayer : public QObject -{ QObject +{ Q_OBJECT public: + /** @@ -20,3 +34,3 @@ public: */ - WidgetLayer(); + WidgetLayer( QObject *parent=0, const char *name=0 ); @@ -27,2 +41,3 @@ public: +public: /** @@ -45,13 +60,17 @@ public: */ - int columns() { return m_columns } + int columns() { return m_columns; } /** - * copy selection into clipboard, etc + * insert current selection (currently this is only the clipboard) */ - void emitSelection(); + void insertSelection(); /** + * insert text + */ + void insertText( QString text ); + /** * set selection (clipboard) to text */ - void setSelection( QString &text ) + void setSelection( const QString &text ); @@ -68,3 +87,3 @@ signals: */ - keyPressed( QKeyEvent *e ); + void keyPressed( QKeyEvent *e ); @@ -76,3 +95,3 @@ signals: */ - mousePressed( int button, int x, int y ); + void mousePressed( int button, int x, int y ); @@ -81,3 +100,3 @@ signals: */ - imageSizeChanged( int lines, int columns ); + void imageSizeChanged( int lines, int columns ); @@ -86,3 +105,3 @@ signals: */ - historyCursorChanged( int value ); + void historyCursorChanged( int value ); @@ -96,3 +115,3 @@ signals: */ - void selectionBegin( const int x, const int y ) + void selectionBegin( const int x, const int y ); @@ -100,3 +119,3 @@ signals: * selection extended - * (from begin s.a. to x, y) + * (from begin (s.a.) to x, y) */ @@ -110,3 +129,31 @@ signals: -slots: + + +// protected methods +protected: + + // image operations + + /** + * changes image, to suit new size + * TODO: find meaningful name! + */ + void propagateSize(); + + /** + * + */ + virtual void calcGeometry(); + + /** + * makes an empty image + */ + void makeImage(); + + /** + * clears the image + */ + void clearImage(); + +protected slots: @@ -115,3 +162,4 @@ slots: */ - onClearSelection(); + void onClearSelection(); + @@ -123,8 +171,30 @@ protected: */ - Session m_session; + Session *m_session; + + /** + * current character image + */ + QArray<Character> m_image; /** - * other misc vars + * lines count */ + int m_lines; + /** + * columns count + */ + int m_columns; + + /** + * clipboard + */ + QClipboard* m_clipboard; + + /** + * whether widget was resized + */ + bool m_resizing; }; + +#endif // WIDGET_LAYER_H |