summaryrefslogtreecommitdiff
authoribotty <ibotty>2002-10-06 19:17:57 (UTC)
committer ibotty <ibotty>2002-10-06 19:17:57 (UTC)
commite99c8b4ed69d844bfab7cb1f1f5a514fdad3118f (patch) (side-by-side diff)
tree88b9d305f7b12f1c7a9be01a027c1db73ee13dd0
parentaa8332baeebf7056d81fc245399477c7feaa1235 (diff)
downloadopie-e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f.zip
opie-e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f.tar.gz
opie-e99c8b4ed69d844bfab7cb1f1f5a514fdad3118f.tar.bz2
wrote first incarnation of widget_layer.cpp.
edited widget_layer.h accordingly.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/opie-console.pro6
-rw-r--r--noncore/apps/opie-console/widget_layer.cpp155
-rw-r--r--noncore/apps/opie-console/widget_layer.h104
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
@@ -18,13 +18,14 @@ HEADERS = io_layer.h io_serial.h \
emulation_layer.h \
widget.h \
vt102emulation.h \
common.h \
history.h \
screen.h \
- keytrans.h
+ keytrans.h \
+ widget_layer.h
SOURCES = io_layer.cpp io_serial.cpp \
file_layer.cpp main.cpp \
metafactory.cpp \
session.cpp \
mainwindow.cpp \
@@ -37,13 +38,14 @@ SOURCES = io_layer.cpp io_serial.cpp \
profileeditorplugins.cpp \
emulation_layer.cpp \
widget.cpp \
vt102emulation.cpp \
history.cpp \
screen.cpp \
- keytrans.cpp
+ keytrans.cpp \
+ widget_layer.cpp
INTERFACES = configurebase.ui editbase.ui
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopie
TARGET = opie-console
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,33 +1,48 @@
-
+/* -------------------------------------------------------------------------- */
/* */
/* [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 <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:
+
/**
* constructor
*/
- WidgetLayer();
+ WidgetLayer( QObject *parent=0, const char *name=0 );
/**
* destructor
*/
virtual ~WidgetLayer();
+public:
/**
* sets the image
*/
virtual void setImage( const Character* const newimg, int lines, int colums );
/**
@@ -40,91 +55,146 @@ public:
*/
int lines() { return m_lines; }
/**
* return the columns count
*/
- 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 );
/**
* paste content of clipboard
*/
void pasteClipboard();
signals:
/**
* key was pressed
*/
- keyPressed( QKeyEvent *e );
+ void keyPressed( QKeyEvent *e );
/**
* whenever Mouse selects something
* 0 left Button
* 3 Button released
* // numbering due to layout in old TEWidget
*/
- mousePressed( int button, int x, int y );
+ void mousePressed( int button, int x, int y );
/**
* size of image changed
*/
- imageSizeChanged( int lines, int columns );
+ void imageSizeChanged( int lines, int columns );
/**
* cursor in history changed
*/
- historyCursorChanged( int value );
+ void historyCursorChanged( int value );
/**
* selection should be cleared
*/
void selectionCleared();
/**
* selection begin
*/
- void selectionBegin( const int x, const int y )
+ void selectionBegin( const int x, const int y );
/**
* selection extended
- * (from begin s.a. to x, y)
+ * (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 );
-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:
/**
* clear selection
*/
- onClearSelection();
+ void onClearSelection();
+
// protected vars
protected:
/**
* current Session
*/
- 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