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