summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/widget_layer.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/noncore/apps/opie-console/widget_layer.cpp b/noncore/apps/opie-console/widget_layer.cpp
index 0364e66..6682708 100644
--- a/noncore/apps/opie-console/widget_layer.cpp
+++ b/noncore/apps/opie-console/widget_layer.cpp
@@ -1,238 +1,243 @@
1/* ------------------------------------------------------------------------- */ 1/* ------------------------------------------------------------------------- */
2/* */ 2/* */
3/* widget_layer.cpp Widget Layer */ 3/* widget_layer.cpp Widget Layer */
4/* */ 4/* */
5/* opie developers <opie@handhelds.org> */ 5/* opie developers <opie@handhelds.org> */
6/* */ 6/* */
7/* ------------------------------------------------------------------------- */ 7/* ------------------------------------------------------------------------- */
8 8
9 9
10 10
11#include "widget_layer.h" 11#include "widget_layer.h"
12 12
13#include <qclipboard.h> 13#include <qclipboard.h>
14#include <qregexp.h> 14#include <qregexp.h>
15#include <qglobal.h> 15#include <qglobal.h>
16 16
17#include <string.h> 17#include <string.h>
18//#include < 18//#include <
19 19
20#include "common.h" 20#include "common.h"
21 21
22 22
23 23
24WidgetLayer::WidgetLayer( const Profile &config, QWidget *parent, const char *name ) : QFrame( parent, name ) 24WidgetLayer::WidgetLayer( const Profile &config, QWidget *parent, const char *name ) : QFrame( parent, name )
25{ 25{
26 // get the clipboard 26 // get the clipboard
27 m_clipboard = QApplication::clipboard(); 27 m_clipboard = QApplication::clipboard();
28 28
29 // when data on clipboard changes, clear selection 29 // when data on clipboard changes, clear selection
30 QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), 30 QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ),
31 (QObject*)this, SLOT( onClearSelection() ) ); 31 (QObject*)this, SLOT( onClearSelection() ) );
32 32
33 // initialize vars: 33 // initialize vars:
34 m_lines = 1; 34 m_lines = 1;
35 m_columns = 1; 35 m_columns = 1;
36 m_resizing = false; 36 m_resizing = false;
37 37
38 // just for demonstrating 38 // just for demonstrating
39 //m_image = QArray<Character>( m_lines * m_columns ); 39 //m_image = QArray<Character>( m_lines * m_columns );
40 m_image = QArray<Character>( 1 ); 40 m_image = QArray<Character>( 1 );
41
42 // we need to install an event filter,
43 // to emit keypresses.
44 qApp->installEventFilter( this );
41 45
42} 46}
43 47
44 48
45WidgetLayer::~WidgetLayer() 49WidgetLayer::~WidgetLayer()
46{ 50{
47 // clean up 51 // clean up
48 delete m_image; 52 delete m_image;
49} 53}
50 54
55
51/* --------------------------------- audio ---------------------------------- */ 56/* --------------------------------- audio ---------------------------------- */
52 57
53void WidgetLayer::bell() 58void WidgetLayer::bell()
54{ 59{
55 QApplication::beep(); 60 QApplication::beep();
56} 61}
57 62
58bool WidgetLayer::eventFilter( QObject *obj, QEvent *e ) 63bool WidgetLayer::eventFilter( QObject *obj, QEvent *e )
59{ 64{
60 if ( (e->type() == QEvent::Accel || 65 if ( (e->type() == QEvent::Accel ||
61 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 66 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
62 static_cast<QKeyEvent *>( e )->ignore(); 67 static_cast<QKeyEvent *>( e )->ignore();
63 return true; 68 return true;
64 } 69 }
65 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 70 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
66 return FALSE; // not us 71 return FALSE; // not us
67 72
68#ifdef FAKE_CTRL_AND_ALT 73#ifdef FAKE_CTRL_AND_ALT
69 static bool control = FALSE; 74 static bool control = FALSE;
70 static bool alt = FALSE; 75 static bool alt = FALSE;
71// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); 76// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
72 bool dele=FALSE; 77 bool dele=FALSE;
73 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 78 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
74 QKeyEvent* ke = (QKeyEvent*)e; 79 QKeyEvent* ke = (QKeyEvent*)e;
75 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 80 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
76 switch (ke->key()) { 81 switch (ke->key()) {
77 case Key_F9: // let this be "Control" 82 case Key_F9: // let this be "Control"
78 control = keydown; 83 control = keydown;
79 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 84 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
80 dele=TRUE; 85 dele=TRUE;
81 break; 86 break;
82 case Key_F13: // let this be "Alt" 87 case Key_F13: // let this be "Alt"
83 alt = keydown; 88 alt = keydown;
84 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 89 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
85 dele=TRUE; 90 dele=TRUE;
86 break; 91 break;
87 default: 92 default:
88 if ( control ) { 93 if ( control ) {
89 int a = toupper(ke->ascii())-64; 94 int a = toupper(ke->ascii())-64;
90 if ( a >= 0 && a < ' ' ) { 95 if ( a >= 0 && a < ' ' ) {
91 e = new QKeyEvent(e->type(), ke->key(), 96 e = new QKeyEvent(e->type(), ke->key(),
92 a, ke->state()|ControlButton, 97 a, ke->state()|ControlButton,
93QChar(a,0)); 98QChar(a,0));
94 dele=TRUE; 99 dele=TRUE;
95 } 100 }
96 } 101 }
97 if ( alt ) { 102 if ( alt ) {
98 e = new QKeyEvent(e->type(), ke->key(), 103 e = new QKeyEvent(e->type(), ke->key(),
99 ke->ascii(), ke->state()|AltButton, ke->text()); 104 ke->ascii(), ke->state()|AltButton, ke->text());
100 dele=TRUE; 105 dele=TRUE;
101 } 106 }
102 } 107 }
103 } 108 }
104#endif 109#endif
105 110
106 if ( e->type() == QEvent::KeyPress ) { 111 if ( e->type() == QEvent::KeyPress ) {
107 QKeyEvent* ke = (QKeyEvent*)e; 112 QKeyEvent* ke = (QKeyEvent*)e;
108 //actSel=0; // Key stroke implies a screen update, so Widget won't 113 //actSel=0; // Key stroke implies a screen update, so Widget won't
109 // know where the current selection is. 114 // know where the current selection is.
110 115
111// qDebug("key pressed is 0x%x",ke->key()); 116// qDebug("key pressed is 0x%x",ke->key());
112 117
113 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker 118 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker
114 insertText("\\"); // expose 119 insertText("\\"); // expose
115 } else 120 } else
116 emit keyPressed( ke ); // expose 121 emit keyPressed( ke ); // expose
117 ke->accept(); 122 ke->accept();
118#ifdef FAKE_CTRL_AND_ALT 123#ifdef FAKE_CTRL_AND_ALT
119 if ( dele ) delete e; 124 if ( dele ) delete e;
120#endif 125#endif
121 return true; // stop the event 126 return true; // stop the event
122 } 127 }
123 return QFrame::eventFilter( obj, e ); 128 return QFrame::eventFilter( obj, e );
124} 129}
125 130
126 131
127/* --------------------------------- screen --------------------------------- */ 132/* --------------------------------- screen --------------------------------- */
128 133
129 134
130void WidgetLayer::propagateSize() 135void WidgetLayer::propagateSize()
131{ 136{
132 QArray<Character> oldimage = m_image.copy(); 137 QArray<Character> oldimage = m_image.copy();
133 int oldlines = m_lines; 138 int oldlines = m_lines;
134 int oldcolumns = m_columns; 139 int oldcolumns = m_columns;
135 140
136 makeImage(); 141 makeImage();
137 142
138 // copy old image, to reduce flicker 143 // copy old image, to reduce flicker
139 if ( ! oldimage.isEmpty() ) 144 if ( ! oldimage.isEmpty() )
140 { 145 {
141 int lins = QMIN( oldlines, m_lines ); 146 int lins = QMIN( oldlines, m_lines );
142 int cols = QMIN( oldcolumns, m_columns ); 147 int cols = QMIN( oldcolumns, m_columns );
143 for ( int lin = 0; lin < lins; ++lin ) 148 for ( int lin = 0; lin < lins; ++lin )
144 { 149 {
145 memcpy( (void*) &m_image[m_columns*lin], 150 memcpy( (void*) &m_image[m_columns*lin],
146 (void*) &oldimage[oldcolumns*lin], 151 (void*) &oldimage[oldcolumns*lin],
147 cols*sizeof( Character ) ); 152 cols*sizeof( Character ) );
148 } 153 }
149 } 154 }
150 else 155 else
151 clearImage(); 156 clearImage();
152 157
153 delete oldimage; 158 delete oldimage;
154 159
155 m_resizing = true; 160 m_resizing = true;
156 emit imageSizeChanged( m_lines, m_columns ); 161 emit imageSizeChanged( m_lines, m_columns );
157 m_resizing = false; 162 m_resizing = false;
158} 163}
159 164
160void WidgetLayer::makeImage() 165void WidgetLayer::makeImage()
161{ 166{
162 calcGeometry(); 167 calcGeometry();
163 m_image = QArray<Character>( m_columns * m_lines ); 168 m_image = QArray<Character>( m_columns * m_lines );
164 clearImage(); 169 clearImage();
165} 170}
166 171
167void WidgetLayer::clearImage() 172void WidgetLayer::clearImage()
168{ 173{
169 //should this belong here?? 174 //should this belong here??
170 for ( int y = 0; y < m_lines; y++ ) 175 for ( int y = 0; y < m_lines; y++ )
171 for ( int x = 0; x < m_columns; x++ ) 176 for ( int x = 0; x < m_columns; x++ )
172 { 177 {
173 m_image[loc(x,y)].c = 0xff; 178 m_image[loc(x,y)].c = 0xff;
174 m_image[loc(x,y)].f = 0xff; 179 m_image[loc(x,y)].f = 0xff;
175 m_image[loc(x,y)].b = 0xff; 180 m_image[loc(x,y)].b = 0xff;
176 m_image[loc(x,y)].r = 0xff; 181 m_image[loc(x,y)].r = 0xff;
177 } 182 }
178} 183}
179 184
180/* --------------------------------- selection ------------------------------ */ 185/* --------------------------------- selection ------------------------------ */
181 186
182void WidgetLayer::pasteClipboard() 187void WidgetLayer::pasteClipboard()
183{ 188{
184 insertSelection(); 189 insertSelection();
185} 190}
186 191
187 192
188void WidgetLayer::insertSelection() 193void WidgetLayer::insertSelection()
189{ 194{
190 QString text = QApplication::clipboard()->text(); 195 QString text = QApplication::clipboard()->text();
191 if ( ! text.isNull() ) 196 if ( ! text.isNull() )
192 { 197 {
193 text.replace( QRegExp( "\n" ), "\r" ); 198 text.replace( QRegExp( "\n" ), "\r" );
194 insertText( text ); 199 insertText( text );
195 // selection should be unselected 200 // selection should be unselected
196 emit selectionCleared(); 201 emit selectionCleared();
197 } 202 }
198} 203}
199 204
200void WidgetLayer::insertText( QString text ) 205void WidgetLayer::insertText( QString text )
201{ 206{
202 // text is inserted as key event 207 // text is inserted as key event
203 QKeyEvent e( QEvent::KeyPress, 0, -1, 0, text); 208 QKeyEvent e( QEvent::KeyPress, 0, -1, 0, text);
204 emit keyPressed( &e ); 209 emit keyPressed( &e );
205} 210}
206 211
207void WidgetLayer::onClearSelection() 212void WidgetLayer::onClearSelection()
208{ 213{
209 emit selectionCleared(); 214 emit selectionCleared();
210} 215}
211 216
212void WidgetLayer::setSelection( const QString& text ) 217void WidgetLayer::setSelection( const QString& text )
213{ 218{
214 // why get the clipboard, we have it as instance var... 219 // why get the clipboard, we have it as instance var...
215 QObject *m_clipboard = QApplication::clipboard(); 220 QObject *m_clipboard = QApplication::clipboard();
216 221
217 // we know, that cliboard changes, when we change clipboard 222 // we know, that cliboard changes, when we change clipboard
218 QObject::disconnect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), 223 QObject::disconnect( (QObject*) m_clipboard, SIGNAL( dataChanged() ),
219 (QObject*) this, SLOT( selectionCleared() ) ); 224 (QObject*) this, SLOT( selectionCleared() ) );
220 225
221 QApplication::clipboard()->setText( text ); 226 QApplication::clipboard()->setText( text );
222 227
223 QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), 228 QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ),
224 (QObject*) this, SLOT( selectionCleared() ) ); 229 (QObject*) this, SLOT( selectionCleared() ) );
225} 230}
226 231
227 232
228///////// 233/////////
229// special font characters 234// special font characters
230///////// 235/////////
231unsigned short vt100_graphics[32] = 236unsigned short vt100_graphics[32] =
232{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 237{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15
233 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 238 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
234 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 239 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
235 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 240 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534,
236 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 241 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7
237}; 242};
238 243