-rw-r--r-- | noncore/apps/opie-console/emulation_widget.cpp | 9 | ||||
-rw-r--r-- | noncore/apps/opie-console/emulation_widget.h | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.cpp | 6 | ||||
-rw-r--r-- | noncore/apps/opie-console/widget_layer.h | 5 |
4 files changed, 21 insertions, 1 deletions
diff --git a/noncore/apps/opie-console/emulation_widget.cpp b/noncore/apps/opie-console/emulation_widget.cpp index e11c5e4..40199fa 100644 --- a/noncore/apps/opie-console/emulation_widget.cpp +++ b/noncore/apps/opie-console/emulation_widget.cpp @@ -45,124 +45,131 @@ void EmulationWidget::reloadConfig( const Profile& config ) // nothing yet } EmulationWidget::~EmulationWidget() { //clean up } static QChar vt100extended(QChar c) { switch (c.unicode()) { case 0x25c6 : return 1; case 0x2592 : return 2; case 0x2409 : return 3; case 0x240c : return 4; case 0x240d : return 5; case 0x240a : return 6; case 0x00b0 : return 7; case 0x00b1 : return 8; case 0x2424 : return 9; case 0x240b : return 10; case 0x2518 : return 11; case 0x2510 : return 12; case 0x250c : return 13; case 0x2514 : return 14; case 0x253c : return 15; case 0xf800 : return 16; case 0xf801 : return 17; case 0x2500 : return 18; case 0xf803 : return 19; case 0xf804 : return 20; case 0x251c : return 21; case 0x2524 : return 22; case 0x2534 : return 23; case 0x252c : return 24; case 0x2502 : return 25; case 0x2264 : return 26; case 0x2265 : return 27; case 0x03c0 : return 28; case 0x2260 : return 29; case 0x00a3 : return 30; case 0x00b7 : return 31; } return c; } +QSize EmulationWidget::calcSize( int cols, int lins ) const +{ + int frw = width() - contentsRect().width(); + int frh = height() - contentsRect().height(); + int scw = (scrollLoc == SCRNONE? 0 : m_scrollbar->width() ); + return QSize( f_width * cols + 2 * rimX + frw + scw, f_height * lins + 2 * rimY + frh ); +} void EmulationWidget::setImage( QArray<Character> const newimg, int lines, int columns ) { const QPixmap* pm = backgroundPixmap(); QPainter paint; // dont allow updates, while drawing setUpdatesEnabled( false ); paint.begin( this ); QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); // hasBlinker = false; int cf = -1; int cb = -1; int cr = -1; int lins = QMIN( m_lines, QMAX( 0, lines ) ); int cols = QMIN( m_columns, QMAX( 0, columns ) ); QArray<QChar> disstrU = QArray<QChar>( cols ); for ( int y = 0; y < lins; ++y ) { int len; const Character* lcl = &m_image[y * m_columns]; - const Character* ext = &newimg[y * columns]; + const Character* ext = &newimg[y * m_columns]; if ( ! m_resizing ) for ( int x = 0; x < cols; ++x ) { // disable, till widget works, WITHOUT blinking //hasBlinker |= ( ext[x].r & RE_BLINK ); if ( ext[x] != lcl[x] ) { cr = ext[x].r; cb = ext[x].b; if ( ext[x].f != cf ) cf = ext[x].f; int lln = cols - x; disstrU[0] = vt100extended( ext[x+0].c ); for ( len = 1; len < lln; ++len ) { if ( ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || ext[x+len] == lcl[x+len] ) break; disstrU[len] = vt100extended( ext[x+len].c ); } QString unistr( disstrU, len ); drawAttrString( unistr, paint, QRect( m_blX+tLx+f_width*x, m_bY+tLy+f_height*y, f_width*len, f_height ), ext[x], pm != NULL, true ); x += len -1; } } // make image become newimg memcpy( (void*) lcl, (const void*) ext, cols*sizeof( Character ) ); } drawFrame( &paint ); paint.end(); setUpdatesEnabled( true ); /*if ( hasBlinker && !blinkT->isActive() ) blinkT->start(1000); //ms if ( ! hasBlinker && blinkT->isActive() ) { blinkT->stop(); blinking = false; }*/ delete [] disstrU; } void EmulationWidget::calcGeometry() { m_scrollbar->resize(QApplication::style().scrollBarExtent().width(), contentsRect().height() ); switch( scrollLoc ) { diff --git a/noncore/apps/opie-console/emulation_widget.h b/noncore/apps/opie-console/emulation_widget.h index e185534..5e20dc4 100644 --- a/noncore/apps/opie-console/emulation_widget.h +++ b/noncore/apps/opie-console/emulation_widget.h @@ -15,96 +15,98 @@ /** * EmulationWidget * simple implementation of EmulationLayer * (doesn't support scrollbar, history, etc, yet) */ class EmulationWidget : public WidgetLayer { Q_OBJECT public: /** * constructor * @param const Profile& config, the configuration * @param QWidget* parent, parent widget * @param const char* name, the name of the widget */ EmulationWidget( const Profile& config, QWidget *parent=0, const char *name =0 ); /** * destructor */ ~EmulationWidget(); /** * sets the image * @param QArray<Character> const newimg, the new image * @param int lines, lines of the new image * @param int columns, columns of the new image */ virtual void setImage( QArray<Character> const newimg, int columns, int lines ); /** * reloads configuration * @param const Profile& config, configuration */ virtual void reloadConfig( const Profile& config ); /** * sets the scrollbar (not yet implemented) */ virtual void setScroll( int cursor, int slines ); /** * scrolls (not yet implemented) * @param int value, scroll by this value */ virtual void scroll( int value ); + virtual QSize calcSize( int cols, int lins ) const; + protected: /** * calculates current image bounds */ virtual void calcGeometry(); /** * @param const ColorEntry* table, the new color table */ void setColorTable( const ColorEntry table[] ); /** * draws a String * @param QString& string, string to be drawn * @param QPainter& painter, painter, that should draw * @param QRect rect, rect to be drawn into * @param Character attr, attributes of Characters * @param bool usePixmap, if to use the background pixmap (currently not supported) * @param bool clear, if rect should be cleared */ void drawAttrString( QString& string, QPainter& painter, QRect rect, Character attr, bool pm, bool clear ); protected: enum ScrollLocation { SCRNONE, SCRLEFT, SCRIGHT }; int f_height; int f_width; int f_ascent; int m_blX; int m_blY; int m_brX; int m_bY; int m_bX; QScrollBar* m_scrollbar; ScrollLocation scrollLoc; ColorEntry* color_table; diff --git a/noncore/apps/opie-console/widget_layer.cpp b/noncore/apps/opie-console/widget_layer.cpp index e4b0ede..ac84f8b 100644 --- a/noncore/apps/opie-console/widget_layer.cpp +++ b/noncore/apps/opie-console/widget_layer.cpp @@ -8,96 +8,102 @@ #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 ); // we need to install an event filter, // to emit keypresses. qApp->installEventFilter( this ); } WidgetLayer::~WidgetLayer() { // clean up delete m_image; } +QSize WidgetLayer::sizeHint() +{ + return size(); +} + + /* --------------------------------- 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 #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(), diff --git a/noncore/apps/opie-console/widget_layer.h b/noncore/apps/opie-console/widget_layer.h index 0c290f3..6812711 100644 --- a/noncore/apps/opie-console/widget_layer.h +++ b/noncore/apps/opie-console/widget_layer.h @@ -78,96 +78,101 @@ public: /** * @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 ); + + + QSize sizeHint(); + + virtual QSize calcSize( int cols, int lins ) const = 0; 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 |