summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/widget_layer.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-console/widget_layer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/widget_layer.cpp155
1 files changed, 155 insertions, 0 deletions
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 @@
1/* ------------------------------------------------------------------------- */
2/* */
3/* widget_layer.cpp Widget Layer */
4/* */
5/* opie developers <opie@handhelds.org> */
6/* */
7/* ------------------------------------------------------------------------- */
8
9
10
11#include "widget_layer.h"
12
13#include <qclipboard.h>
14#include <qregexp.h>
15#include <qglobal.h>
16
17#include <string.h>
18//#include <
19
20#include "common.h"
21
22
23#define loc(X,Y) ((Y)*m_columns+(X))
24
25
26WidgetLayer::WidgetLayer( QObject *parent, const char *name ) : QObject( parent, name )
27{
28 // get the clipboard
29 m_clipboard = QApplication::clipboard();
30
31 // when data on clipboard changes, clear selection
32 QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ),
33 (QObject*)this, SLOT( onClearSelection() ) );
34
35 // initialize vars:
36 m_lines = 1;
37 m_columns = 1;
38 m_resizing = false;
39
40 m_image = QArray<Character>();
41}
42
43WidgetLayer::~WidgetLayer()
44{
45 // clean up!
46}
47
48/* --------------------------------- audio ---------------------------------- */
49
50void WidgetLayer::bell()
51{
52 QApplication::beep();
53}
54
55
56/* --------------------------------- screen --------------------------------- */
57
58
59void WidgetLayer::propagateSize()
60{
61 QArray<Character> oldimage = m_image;
62 int oldlines = m_lines;
63 int oldcolumns = m_columns;
64
65 makeImage();
66
67 // copy old image, to reduce flicker
68 if ( oldimage )
69 {
70 //FIXME: is it possible to do this with QArray.dublicate()?
71
72 int lins = QMIN( oldlines, m_lines );
73 int cols = QMIN( oldcolumns, m_columns );
74 for ( int lin = 0; lin < lins; ++lin )
75 {
76 memcpy( (void*) &m_image[m_columns*lin],
77 (void*) &oldimage[oldcolumns*lin],
78 cols*sizeof( Character ) );
79 }
80 //free( oldimage );
81 }
82 else
83 clearImage();
84
85 m_resizing = true;
86 emit imageSizeChanged( m_lines, m_columns );
87 m_resizing = false;
88}
89
90void WidgetLayer::makeImage()
91{
92 calcGeometry();
93 m_image = QArray<Character>();
94 clearImage();
95}
96
97void WidgetLayer::clearImage()
98{
99 //should this belong here??
100 for ( int y = 0; y < m_lines; y++ )
101 for ( int x = 0; x < m_columns; x++ )
102 {
103 m_image[loc(x,y)].c = 0xff;
104 m_image[loc(x,y)].f = 0xff;
105 m_image[loc(x,y)].b = 0xff;
106 m_image[loc(x,y)].r = 0xff;
107 }
108}
109
110/* --------------------------------- selection ------------------------------ */
111
112void WidgetLayer::pasteClipboard()
113{
114 insertSelection();
115}
116
117
118void WidgetLayer::insertSelection()
119{
120 QString text = QApplication::clipboard()->text();
121 if ( ! text.isNull() )
122 {
123 text.replace( QRegExp( "\n" ), "\r" );
124 insertText( text );
125 // selection should be unselected
126 emit selectionCleared();
127 }
128}
129
130void WidgetLayer::insertText( QString text )
131{
132 // text is inserted as key event
133 QKeyEvent e( QEvent::KeyPress, 0, -1, 0, text);
134 emit keyPressed( &e );
135}
136
137void WidgetLayer::onClearSelection()
138{
139 emit selectionCleared();
140}
141
142void WidgetLayer::setSelection( const QString& text )
143{
144 // why get the clipboard, we have it as instance var...
145 QObject *m_clipboard = QApplication::clipboard();
146
147 // we know, that cliboard changes, when we change clipboard
148 QObject::disconnect( (QObject*) m_clipboard, SIGNAL( dataChanged() ),
149 (QObject*) this, SLOT( selectionCleared() ) );
150
151 QApplication::clipboard()->setText( text );
152
153 QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ),
154 (QObject*) this, SLOT( selectionCleared() ) );
155}