author | ibotty <ibotty> | 2002-10-12 17:27:39 (UTC) |
---|---|---|
committer | ibotty <ibotty> | 2002-10-12 17:27:39 (UTC) |
commit | 9c983d273b055d847cf2d1fa4f5b6e082ce850c9 (patch) (side-by-side diff) | |
tree | e9e6c6320ad3ba926089786f7b187dc62b0af359 | |
parent | e6b92ad451dba66f4eb5000a41b96eb2ee203dce (diff) | |
download | opie-9c983d273b055d847cf2d1fa4f5b6e082ce850c9.zip opie-9c983d273b055d847cf2d1fa4f5b6e082ce850c9.tar.gz opie-9c983d273b055d847cf2d1fa4f5b6e082ce850c9.tar.bz2 |
added functionality to emulation_widget
-rw-r--r-- | noncore/apps/opie-console/emulation_widget.cpp | 208 | ||||
-rw-r--r-- | noncore/apps/opie-console/emulation_widget.h | 38 |
2 files changed, 239 insertions, 7 deletions
diff --git a/noncore/apps/opie-console/emulation_widget.cpp b/noncore/apps/opie-console/emulation_widget.cpp index a45db8c..5c3b2d2 100644 --- a/noncore/apps/opie-console/emulation_widget.cpp +++ b/noncore/apps/opie-console/emulation_widget.cpp @@ -11,26 +11,210 @@ #include <qpainter.h> #include <qrect.h> +#include <qscrollbar.h> +#define rimX 0 // left/right rim width +#define rimY 0 // top/bottom rim high + +#define SCRWIDTH 16 // width of scrollbar EmulationWidget::EmulationWidget( const Profile& config, QWidget *parent, const char* name ) : WidgetLayer( config, parent, name ) { + // initialize font attributes + QFontMetrics fm( font() ); + f_height = fm.height(); + f_width = fm.maxWidth(); + f_ascent = fm.ascent(); + + // initialize scrollbar related vars + m_scrollbar = new QScrollBar( this ); + m_scrollbar->setCursor( arrowCursor ); + + // load config + reloadConfig( config ); + + m_resizing = false; +} + +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; +} -void setImage( QArray<Character> const newimg, int lines, int columns ) + + +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 ); -void drawAttrString( QString& string, QPainter &paint, QRect rect, Character attr, bool usePixmap, bool clear ) + for ( int y = 0; y < lins; ++y ) + { int len; + const Character* lcl = &m_image[y * m_columns]; + const Character* ext = &newimg[y * 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 ) + { + case SCRNONE : + m_columns = ( contentsRect().width() -2 * rimX ) / f_width; + m_blX = ( contentsRect().width() - ( m_columns*f_width ) ) / 2; + m_brX = m_blX; + m_scrollbar->hide(); + break; + case SCRLEFT : + m_columns = ( contentsRect().width() - 2 * rimX - m_scrollbar->width() ) / f_width; + m_brX = ( contentsRect().width() - ( m_columns*f_width ) - m_scrollbar->width() ) / 2; + m_blX = m_brX + m_scrollbar->width(); + m_scrollbar->move( contentsRect().topLeft() ); + m_scrollbar->show(); + break; + case SCRIGHT: + m_columns = ( contentsRect().width() - 2 * rimX - m_scrollbar->width() ) / f_width; + m_blX = ( contentsRect().width() - ( m_columns*f_width ) - m_scrollbar->width() ) / 2; + m_brX = m_blX; + m_scrollbar->move( contentsRect().topRight() - QPoint (m_scrollbar->width()-1,0 ) ); + m_scrollbar->show(); + break; + } + + m_lines = ( contentsRect().height() - 2 * rimY ) / f_height; + m_bY = ( contentsRect().height() - (m_lines * f_height ) ) / 2; +} +void EmulationWidget::drawAttrString( QString& string, QPainter &painter, QRect rect, Character attr, bool usePixmap, bool clear ) +{ + if ( usePixmap && color_table[attr.b].transparent ) + { + painter.setBackgroundMode( TransparentMode ); + if ( clear ) + erase( rect ); + } + else + { + if ( blinking ) + painter.fillRect( rect, color_table[attr.b].color ); + else + { + painter.setBackgroundMode( OpaqueMode ); + painter.setBackgroundColor( color_table[attr.b].color ); + } + } + if ( color_table[attr.f].bold ) + painter.setPen( QColor( 0x8F, 0x00, 0x00 ) ); + else + painter.setPen( color_table[attr.f].color ); + painter.drawText( rect.x(), rect.y() + f_ascent, string ); } - + + /////////////////////// // scrollbar @@ -44,2 +228,18 @@ void EmulationWidget::setScroll( int cursor, int slines ) { } + + +static const ColorEntry color_table[TABLE_COLORS] = +{ + ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback + ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red + ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow + ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta + ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White + // intensiv + ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), + ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), + ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), + ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), + ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) +}; diff --git a/noncore/apps/opie-console/emulation_widget.h b/noncore/apps/opie-console/emulation_widget.h index 56ea15f..e185534 100644 --- a/noncore/apps/opie-console/emulation_widget.h +++ b/noncore/apps/opie-console/emulation_widget.h @@ -12,4 +12,5 @@ + /** * EmulationWidget @@ -41,5 +42,5 @@ public: * @param int columns, columns of the new image */ - virtual void setImage( QArray<Character> const newimg, int columns, int lines ) {}; + virtual void setImage( QArray<Character> const newimg, int columns, int lines ); /** @@ -47,5 +48,5 @@ public: * @param const Profile& config, configuration */ - virtual void reloadConfig( const Profile& config ) {}; + virtual void reloadConfig( const Profile& config ); /** @@ -65,5 +66,11 @@ protected: * calculates current image bounds */ - virtual void calcGeometry() {}; + virtual void calcGeometry(); + + + /** + * @param const ColorEntry* table, the new color table + */ + void setColorTable( const ColorEntry table[] ); /** @@ -78,3 +85,28 @@ protected: 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; + + bool blinking; }; |