-rw-r--r-- | noncore/apps/opie-console/widget_layer.cpp | 5 |
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,146 +1,151 @@ | |||
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 | ||
24 | WidgetLayer::WidgetLayer( const Profile &config, QWidget *parent, const char *name ) : QFrame( parent, name ) | 24 | WidgetLayer::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 | ||
45 | WidgetLayer::~WidgetLayer() | 49 | WidgetLayer::~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 | ||
53 | void WidgetLayer::bell() | 58 | void WidgetLayer::bell() |
54 | { | 59 | { |
55 | QApplication::beep(); | 60 | QApplication::beep(); |
56 | } | 61 | } |
57 | 62 | ||
58 | bool WidgetLayer::eventFilter( QObject *obj, QEvent *e ) | 63 | bool 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, |
93 | QChar(a,0)); | 98 | QChar(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 | ||
130 | void WidgetLayer::propagateSize() | 135 | void 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], |