-rw-r--r-- | noncore/apps/opie-console/widget_layer.cpp | 24 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.h | 27 |
2 files changed, 35 insertions, 16 deletions
diff --git a/noncore/apps/opie-console/widget_layer.cpp b/noncore/apps/opie-console/widget_layer.cpp index 28227e4..f428ed4 100644 --- a/noncore/apps/opie-console/widget_layer.cpp +++ b/noncore/apps/opie-console/widget_layer.cpp @@ -1,155 +1,157 @@ /* ------------------------------------------------------------------------- */ /* */ /* 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 ) +WidgetLayer::WidgetLayer( QWidget *parent, const char *name ) : QFrame( 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>(); + // just for demonstrating + //m_image = QArray<Character>( m_lines * m_columns ); + m_image = QArray<Character>( 1 ); + } + WidgetLayer::~WidgetLayer() { - // clean up! + // clean up + delete m_image; } /* --------------------------------- audio ---------------------------------- */ void WidgetLayer::bell() { QApplication::beep(); } /* --------------------------------- screen --------------------------------- */ void WidgetLayer::propagateSize() { - QArray<Character> oldimage = m_image; + QArray<Character> oldimage = m_image.copy(); int oldlines = m_lines; int oldcolumns = m_columns; makeImage(); // copy old image, to reduce flicker - if ( oldimage ) + if ( ! oldimage.isEmpty() ) { - //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(); + delete oldimage; + m_resizing = true; emit imageSizeChanged( m_lines, m_columns ); m_resizing = false; } void WidgetLayer::makeImage() { calcGeometry(); - m_image = QArray<Character>(); + m_image = QArray<Character>( m_columns * m_lines ); 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 07ec12a..99d248e 100644 --- a/noncore/apps/opie-console/widget_layer.h +++ b/noncore/apps/opie-console/widget_layer.h @@ -1,200 +1,217 @@ /* -------------------------------------------------------------------------- */ /* */ /* [widget_layer.h] Widget Layer */ /* */ /* -------------------------------------------------------------------------- */ // proposal of a widget Layer in opie-console // // fellow devels: // just mail me (ibotty@web.de), what you additionally need from the main widget // (or say in chat) #ifndef WIDGET_LAYER_H #define WIDGET_LAYER_H // qt includes #include <qapplication.h> +#include <qframe.h> +#include <qarray.h> #include <qtimer.h> #include <qkeycode.h> #include <qclipboard.h> // opie-console includes #include "session.h" #include "common.h" -class WidgetLayer : public QObject +/* + * given a pseudo location ( column, line ), + * returns the actual index, in the QArray<Character> + */ +#define loc(X,Y) ((Y)*m_columns+(X)) + + + + +class WidgetLayer : public QFrame { Q_OBJECT public: /** * constructor */ - WidgetLayer( QObject *parent=0, const char *name=0 ); + WidgetLayer( QWidget *parent=0, const char *name=0 ); /** * destructor */ virtual ~WidgetLayer(); public: /** * sets the image */ - virtual void setImage( const Character* const newimg, int lines, int colums ) = 0; + virtual void setImage( QArray<Character> const newimg, int lines, int colums ); /** * annoy the user */ void bell(); /** * return the lines count */ int lines() { return m_lines; } /** * return the columns count */ int columns() { return m_columns; } /** * insert current selection (currently this is only the clipboard) */ void insertSelection(); /** * insert text */ void insertText( QString text ); /** * set selection (clipboard) to text */ void setSelection( const QString &text ); /** * paste content of clipboard */ void pasteClipboard(); signals: /** * key was pressed */ void keyPressed( QKeyEvent *e ); /** * whenever Mouse selects something * 0 left Button * 3 Button released * // numbering due to layout in old TEWidget */ void mousePressed( int button, int x, int y ); /** * size of image changed */ void imageSizeChanged( int lines, int columns ); /** * cursor in history changed */ void historyCursorChanged( int value ); /** * selection should be cleared */ void selectionCleared(); /** * selection begin */ void selectionBegin( const int x, const int y ); /** * selection extended * (from begin (s.a.) to x, y) */ void selectionExtended( const int x, const int y ); /** * selection end * bool: preserve line breaks in selection */ void selectionEnd( const bool lineBreakPreserve ); // protected methods protected: // image operations /** * changes image, to suit new size * TODO: find meaningful name! */ void propagateSize(); /** - * + *determines count of lines and columns */ virtual void calcGeometry() = 0; /** * makes an empty image */ void makeImage(); /** * clears the image */ void clearImage(); protected slots: /** * clear selection */ void onClearSelection(); // protected vars protected: /** * current Session */ Session *m_session; /** * current character image + * + * a Character at loc( column, line ) + * has the actual index: + * ix = line * m_columns + column; + * + * use loc( x, y ) macro to access. */ QArray<Character> m_image; /** * lines count */ int m_lines; /** * columns count */ int m_columns; /** * clipboard */ QClipboard* m_clipboard; /** - * whether widget was resized + * whether widget is resizing */ bool m_resizing; }; #endif // WIDGET_LAYER_H |