-rw-r--r-- | noncore/apps/opie-console/widget_layer.cpp | 79 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.h | 2 |
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 @@ #include "widget_layer.h" #include <qclipboard.h> #include <qregexp.h> #include <qglobal.h> #include <string.h> //#include < #include "common.h" WidgetLayer::WidgetLayer( const Profile &config, QWidget *parent, const char *name ) : QFrame( parent, name ) { // get the clipboard m_clipboard = QApplication::clipboard(); // when data on clipboard changes, clear selection QObject::connect( (QObject*) m_clipboard, SIGNAL( dataChanged() ), (QObject*)this, SLOT( onClearSelection() ) ); // initialize vars: m_lines = 1; m_columns = 1; m_resizing = false; // just for demonstrating //m_image = QArray<Character>( m_lines * m_columns ); m_image = QArray<Character>( 1 ); } WidgetLayer::~WidgetLayer() { // clean up delete m_image; } /* --------------------------------- audio ---------------------------------- */ void WidgetLayer::bell() { QApplication::beep(); } +bool WidgetLayer::eventFilter( QObject *obj, QEvent *e ) +{ + if ( (e->type() == QEvent::Accel || + e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { + static_cast<QKeyEvent *>( e )->ignore(); + return true; + } + if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) + return FALSE; // not us + if ( e->type() == QEvent::Wheel) { + QApplication::sendEvent( m_scrollbar, e); + } + +#ifdef FAKE_CTRL_AND_ALT + static bool control = FALSE; + static bool alt = FALSE; +// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); + bool dele=FALSE; + if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { + QKeyEvent* ke = (QKeyEvent*)e; + bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); + switch (ke->key()) { + case Key_F9: // let this be "Control" + control = keydown; + e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); + dele=TRUE; + break; + case Key_F13: // let this be "Alt" + alt = keydown; + e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); + dele=TRUE; + break; + default: + if ( control ) { + int a = toupper(ke->ascii())-64; + if ( a >= 0 && a < ' ' ) { + e = new QKeyEvent(e->type(), ke->key(), + a, ke->state()|ControlButton, +QChar(a,0)); + dele=TRUE; + } + } + if ( alt ) { + e = new QKeyEvent(e->type(), ke->key(), + ke->ascii(), ke->state()|AltButton, ke->text()); + dele=TRUE; + } + } + } +#endif + + if ( e->type() == QEvent::KeyPress ) { + QKeyEvent* ke = (QKeyEvent*)e; + //actSel=0; // Key stroke implies a screen update, so Widget won't + // know where the current selection is. + +// qDebug("key pressed is 0x%x",ke->key()); + + if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker + insertText("\\"); // expose + } else + emit keyPressed( ke ); // expose + ke->accept(); +#ifdef FAKE_CTRL_AND_ALT + if ( dele ) delete e; +#endif + return true; // stop the event + } + if ( e->type() == QEvent::Enter ) { + QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), + this, SLOT(onClearSelection()) ); + } + if ( e->type() == QEvent::Leave ) { + QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), + this, SLOT(onClearSelection()) ); + } + return QFrame::eventFilter( obj, e ); +} + /* --------------------------------- screen --------------------------------- */ void WidgetLayer::propagateSize() { QArray<Character> oldimage = m_image.copy(); int oldlines = m_lines; int oldcolumns = m_columns; makeImage(); // copy old image, to reduce flicker if ( ! oldimage.isEmpty() ) { int lins = QMIN( oldlines, m_lines ); int cols = QMIN( oldcolumns, m_columns ); for ( int lin = 0; lin < lins; ++lin ) { memcpy( (void*) &m_image[m_columns*lin], (void*) &oldimage[oldcolumns*lin], cols*sizeof( Character ) ); } } else clearImage(); delete oldimage; m_resizing = true; emit imageSizeChanged( m_lines, m_columns ); m_resizing = false; } void WidgetLayer::makeImage() { calcGeometry(); m_image = QArray<Character>( m_columns * m_lines ); clearImage(); } void WidgetLayer::clearImage() { //should this belong here?? for ( int y = 0; y < m_lines; y++ ) for ( int x = 0; x < m_columns; x++ ) { 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: int lines() { return m_lines; } /** * @return int m_columns, the columns count */ int columns() { return m_columns; } /** * insert current selection (currently this is only the clipboard) */ void insertSelection(); /** * insert text * @param QString text, the text to be inserted */ void insertText( QString text ); /** * set selection (clipboard) to text * @param const QString &text, the text to be selected */ void setSelection( const QString &text ); /** * paste content of clipboard */ void pasteClipboard(); /** * reload configuration * @param const Profile& config, the config to be used (may be the same as in constructor) */ virtual void reloadConfig( const Profile& config ) = 0; /** * sets the scrollbar (if implemented by successor of this class) */ virtual void setScroll( int cursor, int slines ) = 0; /** * scrolls (if implemented, by successor of this class) * @param int value, how much the widget should scroll up (positive value) or down (negative value) */ virtual void scroll( int value ) = 0; + + virtual bool eventFilter( QObject *obj, QEvent *event ); signals: /** * key was pressed */ void keyPressed( QKeyEvent *e ); /** * whenever Mouse selects something * @param int button, the button that us pressed : * 0 left Button * 3 Button released * @param int x, x position * @param int y, y position * * // numbering due to layout in old TEWidget */ void mousePressed( int button, int x, int y ); /** * size of image changed * @param int lines, line count of new size * @param int columns, column count of new size */ void imageSizeChanged( int lines, int columns ); /** * cursor in history changed * @param int value, value of history cursor */ void historyCursorChanged( int value ); /** * selection should be cleared */ void selectionCleared(); /** * selection begin * @param const int x, x position * @param const int y, y position */ void selectionBegin( const int x, const int y ); /** * selection extended * (from begin (s.a.) to x, y) * @param const int x, x position |