summaryrefslogtreecommitdiff
authoribotty <ibotty>2002-10-13 10:49:21 (UTC)
committer ibotty <ibotty>2002-10-13 10:49:21 (UTC)
commit72d9ce37fdd97b7ff37111e365cc8a14e0bbc52c (patch) (unidiff)
tree95ddc3c8ec3740d9544d6df08695a26fb52d46c9
parentb8377d9c462d7edbc92c6809503cb53a09f8fd98 (diff)
downloadopie-72d9ce37fdd97b7ff37111e365cc8a14e0bbc52c.zip
opie-72d9ce37fdd97b7ff37111e365cc8a14e0bbc52c.tar.gz
opie-72d9ce37fdd97b7ff37111e365cc8a14e0bbc52c.tar.bz2
does not work... but committed to get things started
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/widget_layer.cpp79
-rw-r--r--noncore/apps/opie-console/widget_layer.h2
2 files changed, 81 insertions, 0 deletions
diff --git a/noncore/apps/opie-console/widget_layer.cpp b/noncore/apps/opie-console/widget_layer.cpp
index c00871f..3875a6e 100644
--- a/noncore/apps/opie-console/widget_layer.cpp
+++ b/noncore/apps/opie-console/widget_layer.cpp
@@ -10,96 +10,175 @@
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 41
42} 42}
43 43
44 44
45WidgetLayer::~WidgetLayer() 45WidgetLayer::~WidgetLayer()
46{ 46{
47 // clean up 47 // clean up
48 delete m_image; 48 delete m_image;
49} 49}
50 50
51/* --------------------------------- audio ---------------------------------- */ 51/* --------------------------------- audio ---------------------------------- */
52 52
53void WidgetLayer::bell() 53void WidgetLayer::bell()
54{ 54{
55 QApplication::beep(); 55 QApplication::beep();
56} 56}
57 57
58bool WidgetLayer::eventFilter( QObject *obj, QEvent *e )
59{
60 if ( (e->type() == QEvent::Accel ||
61 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
62 static_cast<QKeyEvent *>( e )->ignore();
63 return true;
64 }
65 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
66 return FALSE; // not us
67 if ( e->type() == QEvent::Wheel) {
68 QApplication::sendEvent( m_scrollbar, e);
69 }
70
71#ifdef FAKE_CTRL_AND_ALT
72 static bool control = FALSE;
73 static bool alt = FALSE;
74// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
75 bool dele=FALSE;
76 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
77 QKeyEvent* ke = (QKeyEvent*)e;
78 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
79 switch (ke->key()) {
80 case Key_F9: // let this be "Control"
81 control = keydown;
82 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
83 dele=TRUE;
84 break;
85 case Key_F13: // let this be "Alt"
86 alt = keydown;
87 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
88 dele=TRUE;
89 break;
90 default:
91 if ( control ) {
92 int a = toupper(ke->ascii())-64;
93 if ( a >= 0 && a < ' ' ) {
94 e = new QKeyEvent(e->type(), ke->key(),
95 a, ke->state()|ControlButton,
96QChar(a,0));
97 dele=TRUE;
98 }
99 }
100 if ( alt ) {
101 e = new QKeyEvent(e->type(), ke->key(),
102 ke->ascii(), ke->state()|AltButton, ke->text());
103 dele=TRUE;
104 }
105 }
106 }
107#endif
108
109 if ( e->type() == QEvent::KeyPress ) {
110 QKeyEvent* ke = (QKeyEvent*)e;
111 //actSel=0; // Key stroke implies a screen update, so Widget won't
112 // know where the current selection is.
113
114// qDebug("key pressed is 0x%x",ke->key());
115
116 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker
117 insertText("\\"); // expose
118 } else
119 emit keyPressed( ke ); // expose
120 ke->accept();
121#ifdef FAKE_CTRL_AND_ALT
122 if ( dele ) delete e;
123#endif
124 return true; // stop the event
125 }
126 if ( e->type() == QEvent::Enter ) {
127 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
128 this, SLOT(onClearSelection()) );
129 }
130 if ( e->type() == QEvent::Leave ) {
131 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
132 this, SLOT(onClearSelection()) );
133 }
134 return QFrame::eventFilter( obj, e );
135}
136
58 137
59/* --------------------------------- screen --------------------------------- */ 138/* --------------------------------- screen --------------------------------- */
60 139
61 140
62void WidgetLayer::propagateSize() 141void WidgetLayer::propagateSize()
63{ 142{
64 QArray<Character> oldimage = m_image.copy(); 143 QArray<Character> oldimage = m_image.copy();
65 int oldlines = m_lines; 144 int oldlines = m_lines;
66 int oldcolumns = m_columns; 145 int oldcolumns = m_columns;
67 146
68 makeImage(); 147 makeImage();
69 148
70 // copy old image, to reduce flicker 149 // copy old image, to reduce flicker
71 if ( ! oldimage.isEmpty() ) 150 if ( ! oldimage.isEmpty() )
72 { 151 {
73 int lins = QMIN( oldlines, m_lines ); 152 int lins = QMIN( oldlines, m_lines );
74 int cols = QMIN( oldcolumns, m_columns ); 153 int cols = QMIN( oldcolumns, m_columns );
75 for ( int lin = 0; lin < lins; ++lin ) 154 for ( int lin = 0; lin < lins; ++lin )
76 { 155 {
77 memcpy( (void*) &m_image[m_columns*lin], 156 memcpy( (void*) &m_image[m_columns*lin],
78 (void*) &oldimage[oldcolumns*lin], 157 (void*) &oldimage[oldcolumns*lin],
79 cols*sizeof( Character ) ); 158 cols*sizeof( Character ) );
80 } 159 }
81 } 160 }
82 else 161 else
83 clearImage(); 162 clearImage();
84 163
85 delete oldimage; 164 delete oldimage;
86 165
87 m_resizing = true; 166 m_resizing = true;
88 emit imageSizeChanged( m_lines, m_columns ); 167 emit imageSizeChanged( m_lines, m_columns );
89 m_resizing = false; 168 m_resizing = false;
90} 169}
91 170
92void WidgetLayer::makeImage() 171void WidgetLayer::makeImage()
93{ 172{
94 calcGeometry(); 173 calcGeometry();
95 m_image = QArray<Character>( m_columns * m_lines ); 174 m_image = QArray<Character>( m_columns * m_lines );
96 clearImage(); 175 clearImage();
97} 176}
98 177
99void WidgetLayer::clearImage() 178void WidgetLayer::clearImage()
100{ 179{
101 //should this belong here?? 180 //should this belong here??
102 for ( int y = 0; y < m_lines; y++ ) 181 for ( int y = 0; y < m_lines; y++ )
103 for ( int x = 0; x < m_columns; x++ ) 182 for ( int x = 0; x < m_columns; x++ )
104 { 183 {
105 m_image[loc(x,y)].c = 0xff; 184 m_image[loc(x,y)].c = 0xff;
diff --git a/noncore/apps/opie-console/widget_layer.h b/noncore/apps/opie-console/widget_layer.h
index 067f3da..1d96bf4 100644
--- a/noncore/apps/opie-console/widget_layer.h
+++ b/noncore/apps/opie-console/widget_layer.h
@@ -76,96 +76,98 @@ public:
76 int lines(){ return m_lines; } 76 int lines(){ return m_lines; }
77 77
78 /** 78 /**
79 * @return int m_columns, the columns count 79 * @return int m_columns, the columns count
80 */ 80 */
81 int columns(){ return m_columns; } 81 int columns(){ return m_columns; }
82 82
83 /** 83 /**
84 * insert current selection (currently this is only the clipboard) 84 * insert current selection (currently this is only the clipboard)
85 */ 85 */
86 void insertSelection(); 86 void insertSelection();
87 87
88 /** 88 /**
89 * insert text 89 * insert text
90 * @param QString text, the text to be inserted 90 * @param QString text, the text to be inserted
91 */ 91 */
92 void insertText( QString text ); 92 void insertText( QString text );
93 93
94 /** 94 /**
95 * set selection (clipboard) to text 95 * set selection (clipboard) to text
96 * @param const QString &text, the text to be selected 96 * @param const QString &text, the text to be selected
97 */ 97 */
98 void setSelection( const QString &text ); 98 void setSelection( const QString &text );
99 99
100 /** 100 /**
101 * paste content of clipboard 101 * paste content of clipboard
102 */ 102 */
103 void pasteClipboard(); 103 void pasteClipboard();
104 104
105 105
106 /** 106 /**
107 * reload configuration 107 * reload configuration
108 * @param const Profile& config, the config to be used (may be the same as in constructor) 108 * @param const Profile& config, the config to be used (may be the same as in constructor)
109 */ 109 */
110 virtual void reloadConfig( const Profile& config ) = 0; 110 virtual void reloadConfig( const Profile& config ) = 0;
111 111
112 112
113 /** 113 /**
114 * sets the scrollbar (if implemented by successor of this class) 114 * sets the scrollbar (if implemented by successor of this class)
115 */ 115 */
116 virtual void setScroll( int cursor, int slines ) = 0; 116 virtual void setScroll( int cursor, int slines ) = 0;
117 117
118 /** 118 /**
119 * scrolls (if implemented, by successor of this class) 119 * scrolls (if implemented, by successor of this class)
120 * @param int value, how much the widget should scroll up (positive value) or down (negative value) 120 * @param int value, how much the widget should scroll up (positive value) or down (negative value)
121 */ 121 */
122 virtual void scroll( int value ) = 0; 122 virtual void scroll( int value ) = 0;
123 123
124
125 virtual bool eventFilter( QObject *obj, QEvent *event );
124signals: 126signals:
125 127
126 /** 128 /**
127 * key was pressed 129 * key was pressed
128 */ 130 */
129 void keyPressed( QKeyEvent *e ); 131 void keyPressed( QKeyEvent *e );
130 132
131 /** 133 /**
132 * whenever Mouse selects something 134 * whenever Mouse selects something
133 * @param int button, the button that us pressed : 135 * @param int button, the button that us pressed :
134 * 0left Button 136 * 0left Button
135 * 3Button released 137 * 3Button released
136 * @param int x, x position 138 * @param int x, x position
137 * @param int y, y position 139 * @param int y, y position
138 * 140 *
139 * // numbering due to layout in old TEWidget 141 * // numbering due to layout in old TEWidget
140 */ 142 */
141 void mousePressed( int button, int x, int y ); 143 void mousePressed( int button, int x, int y );
142 144
143 /** 145 /**
144 * size of image changed 146 * size of image changed
145 * @param int lines, line count of new size 147 * @param int lines, line count of new size
146 * @param int columns, column count of new size 148 * @param int columns, column count of new size
147 */ 149 */
148 void imageSizeChanged( int lines, int columns ); 150 void imageSizeChanged( int lines, int columns );
149 151
150 /** 152 /**
151 * cursor in history changed 153 * cursor in history changed
152 * @param int value, value of history cursor 154 * @param int value, value of history cursor
153 */ 155 */
154 void historyCursorChanged( int value ); 156 void historyCursorChanged( int value );
155 157
156 /** 158 /**
157 * selection should be cleared 159 * selection should be cleared
158 */ 160 */
159 void selectionCleared(); 161 void selectionCleared();
160 162
161 /** 163 /**
162 * selection begin 164 * selection begin
163 * @param const int x, x position 165 * @param const int x, x position
164 * @param const int y, y position 166 * @param const int y, y position
165 */ 167 */
166 void selectionBegin( const int x, const int y ); 168 void selectionBegin( const int x, const int y );
167 169
168 /** 170 /**
169 * selection extended 171 * selection extended
170 * (from begin (s.a.) to x, y) 172 * (from begin (s.a.) to x, y)
171 * @param const int x, x position 173 * @param const int x, x position