-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 | |||
@@ -12,3 +12,8 @@ | |||
12 | #include <qrect.h> | 12 | #include <qrect.h> |
13 | #include <qscrollbar.h> | ||
13 | 14 | ||
15 | #define rimX 0 // left/right rim width | ||
16 | #define rimY 0 // top/bottom rim high | ||
17 | |||
18 | #define SCRWIDTH 16 // width of scrollbar | ||
14 | 19 | ||
@@ -17,2 +22,22 @@ EmulationWidget::EmulationWidget( const Profile& config, QWidget *parent, const | |||
17 | 22 | ||
23 | // initialize font attributes | ||
24 | QFontMetrics fm( font() ); | ||
25 | f_height = fm.height(); | ||
26 | f_width = fm.maxWidth(); | ||
27 | f_ascent = fm.ascent(); | ||
28 | |||
29 | // initialize scrollbar related vars | ||
30 | m_scrollbar = new QScrollBar( this ); | ||
31 | m_scrollbar->setCursor( arrowCursor ); | ||
32 | |||
33 | // load config | ||
34 | reloadConfig( config ); | ||
35 | |||
36 | m_resizing = false; | ||
37 | } | ||
38 | |||
39 | void EmulationWidget::reloadConfig( const Profile& config ) | ||
40 | { | ||
41 | |||
42 | // nothing yet | ||
18 | } | 43 | } |
@@ -21,15 +46,174 @@ EmulationWidget::~EmulationWidget() | |||
21 | { | 46 | { |
47 | //clean up | ||
22 | } | 48 | } |
23 | 49 | ||
50 | static QChar vt100extended(QChar c) | ||
51 | { | ||
52 | switch (c.unicode()) | ||
53 | { | ||
54 | case 0x25c6 : return 1; | ||
55 | case 0x2592 : return 2; | ||
56 | case 0x2409 : return 3; | ||
57 | case 0x240c : return 4; | ||
58 | case 0x240d : return 5; | ||
59 | case 0x240a : return 6; | ||
60 | case 0x00b0 : return 7; | ||
61 | case 0x00b1 : return 8; | ||
62 | case 0x2424 : return 9; | ||
63 | case 0x240b : return 10; | ||
64 | case 0x2518 : return 11; | ||
65 | case 0x2510 : return 12; | ||
66 | case 0x250c : return 13; | ||
67 | case 0x2514 : return 14; | ||
68 | case 0x253c : return 15; | ||
69 | case 0xf800 : return 16; | ||
70 | case 0xf801 : return 17; | ||
71 | case 0x2500 : return 18; | ||
72 | case 0xf803 : return 19; | ||
73 | case 0xf804 : return 20; | ||
74 | case 0x251c : return 21; | ||
75 | case 0x2524 : return 22; | ||
76 | case 0x2534 : return 23; | ||
77 | case 0x252c : return 24; | ||
78 | case 0x2502 : return 25; | ||
79 | case 0x2264 : return 26; | ||
80 | case 0x2265 : return 27; | ||
81 | case 0x03c0 : return 28; | ||
82 | case 0x2260 : return 29; | ||
83 | case 0x00a3 : return 30; | ||
84 | case 0x00b7 : return 31; | ||
85 | } | ||
86 | return c; | ||
87 | } | ||
24 | 88 | ||
25 | void setImage( QArray<Character> const newimg, int lines, int columns ) | 89 | |
90 | |||
91 | void EmulationWidget::setImage( QArray<Character> const newimg, int lines, int columns ) | ||
26 | { | 92 | { |
27 | } | 93 | const QPixmap* pm = backgroundPixmap(); |
94 | QPainter paint; | ||
95 | |||
96 | // dont allow updates, while drawing | ||
97 | setUpdatesEnabled( false ); | ||
98 | |||
99 | paint.begin( this ); | ||
100 | |||
101 | QPoint tL = contentsRect().topLeft(); | ||
102 | int tLx = tL.x(); | ||
103 | int tLy = tL.y(); | ||
104 | //hasBlinker = false; | ||
105 | |||
106 | int cf = -1; | ||
107 | int cb = -1; | ||
108 | int cr = -1; | ||
109 | |||
110 | int lins = QMIN( m_lines, QMAX( 0, lines ) ); | ||
111 | int cols = QMIN( m_columns, QMAX( 0, columns ) ); | ||
112 | QArray<QChar> disstrU = QArray<QChar>( cols ); | ||
28 | 113 | ||
29 | void drawAttrString( QString& string, QPainter &paint, QRect rect, Character attr, bool usePixmap, bool clear ) | 114 | for ( int y = 0; y < lins; ++y ) |
115 | {int len; | ||
116 | const Character* lcl = &m_image[y * m_columns]; | ||
117 | const Character* ext = &newimg[y * columns]; | ||
118 | if ( ! m_resizing ) | ||
119 | for ( int x = 0; x < cols; ++x ) | ||
120 | { | ||
121 | // disable, till widget works, WITHOUT blinking | ||
122 | //hasBlinker |= ( ext[x].r & RE_BLINK ); | ||
123 | |||
124 | if ( ext[x] != lcl[x] ) | ||
125 | { | ||
126 | cr = ext[x].r; | ||
127 | cb = ext[x].b; | ||
128 | if ( ext[x].f != cf ) cf = ext[x].f; | ||
129 | int lln = cols - x; | ||
130 | disstrU[0] = vt100extended( ext[x+0].c ); | ||
131 | for ( len = 1; len < lln; ++len ) | ||
132 | { | ||
133 | if ( ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || ext[x+len] == lcl[x+len] ) | ||
134 | break; | ||
135 | disstrU[len] = vt100extended( ext[x+len].c ); | ||
136 | } | ||
137 | QString unistr( disstrU, len ); | ||
138 | 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 ); | ||
139 | x += len -1; | ||
140 | } | ||
141 | } | ||
142 | // make image become newimg | ||
143 | memcpy( (void*) lcl, (const void*) ext, cols*sizeof( Character ) ); | ||
144 | } | ||
145 | drawFrame( &paint ); | ||
146 | paint.end(); | ||
147 | setUpdatesEnabled( true ); | ||
148 | |||
149 | /*if ( hasBlinker && !blinkT->isActive() ) | ||
150 | blinkT->start(1000); //ms | ||
151 | if ( ! hasBlinker && blinkT->isActive() ) | ||
152 | { | ||
153 | blinkT->stop(); | ||
154 | blinking = false; | ||
155 | }*/ | ||
156 | |||
157 | delete [] disstrU; | ||
158 | } | ||
159 | |||
160 | void EmulationWidget::calcGeometry() | ||
30 | { | 161 | { |
162 | m_scrollbar->resize(QApplication::style().scrollBarExtent().width(), contentsRect().height() ); | ||
163 | |||
164 | switch( scrollLoc ) | ||
165 | { | ||
166 | case SCRNONE : | ||
167 | m_columns = ( contentsRect().width() -2 * rimX ) / f_width; | ||
168 | m_blX = ( contentsRect().width() - ( m_columns*f_width ) ) / 2; | ||
169 | m_brX = m_blX; | ||
170 | m_scrollbar->hide(); | ||
171 | break; | ||
172 | case SCRLEFT : | ||
173 | m_columns = ( contentsRect().width() - 2 * rimX - m_scrollbar->width() ) / f_width; | ||
174 | m_brX = ( contentsRect().width() - ( m_columns*f_width ) - m_scrollbar->width() ) / 2; | ||
175 | m_blX = m_brX + m_scrollbar->width(); | ||
176 | m_scrollbar->move( contentsRect().topLeft() ); | ||
177 | m_scrollbar->show(); | ||
178 | break; | ||
179 | case SCRIGHT: | ||
180 | m_columns = ( contentsRect().width() - 2 * rimX - m_scrollbar->width() ) / f_width; | ||
181 | m_blX = ( contentsRect().width() - ( m_columns*f_width ) - m_scrollbar->width() ) / 2; | ||
182 | m_brX = m_blX; | ||
183 | m_scrollbar->move( contentsRect().topRight() - QPoint (m_scrollbar->width()-1,0 ) ); | ||
184 | m_scrollbar->show(); | ||
185 | break; | ||
186 | } | ||
187 | |||
188 | m_lines = ( contentsRect().height() - 2 * rimY ) / f_height; | ||
189 | m_bY = ( contentsRect().height() - (m_lines * f_height ) ) / 2; | ||
190 | } | ||
31 | 191 | ||
192 | void EmulationWidget::drawAttrString( QString& string, QPainter &painter, QRect rect, Character attr, bool usePixmap, bool clear ) | ||
193 | { | ||
194 | if ( usePixmap && color_table[attr.b].transparent ) | ||
195 | { | ||
196 | painter.setBackgroundMode( TransparentMode ); | ||
197 | if ( clear ) | ||
198 | erase( rect ); | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | if ( blinking ) | ||
203 | painter.fillRect( rect, color_table[attr.b].color ); | ||
204 | else | ||
205 | { | ||
206 | painter.setBackgroundMode( OpaqueMode ); | ||
207 | painter.setBackgroundColor( color_table[attr.b].color ); | ||
208 | } | ||
209 | } | ||
210 | if ( color_table[attr.f].bold ) | ||
211 | painter.setPen( QColor( 0x8F, 0x00, 0x00 ) ); | ||
212 | else | ||
213 | painter.setPen( color_table[attr.f].color ); | ||
214 | painter.drawText( rect.x(), rect.y() + f_ascent, string ); | ||
32 | 215 | ||
33 | } | 216 | } |
34 | 217 | ||
218 | |||
35 | /////////////////////// | 219 | /////////////////////// |
@@ -45 +229,17 @@ void EmulationWidget::setScroll( int cursor, int slines ) | |||
45 | } | 229 | } |
230 | |||
231 | |||
232 | static const ColorEntry color_table[TABLE_COLORS] = | ||
233 | { | ||
234 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback | ||
235 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red | ||
236 | ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow | ||
237 | ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta | ||
238 | ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White | ||
239 | // intensiv | ||
240 | ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), | ||
241 | ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), | ||
242 | ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), | ||
243 | ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), | ||
244 | ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) | ||
245 | }; | ||
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 | |||
@@ -13,2 +13,3 @@ | |||
13 | 13 | ||
14 | |||
14 | /** | 15 | /** |
@@ -42,3 +43,3 @@ public: | |||
42 | */ | 43 | */ |
43 | virtual void setImage( QArray<Character> const newimg, int columns, int lines ) {}; | 44 | virtual void setImage( QArray<Character> const newimg, int columns, int lines ); |
44 | 45 | ||
@@ -48,3 +49,3 @@ public: | |||
48 | */ | 49 | */ |
49 | virtual void reloadConfig( const Profile& config ) {}; | 50 | virtual void reloadConfig( const Profile& config ); |
50 | 51 | ||
@@ -66,3 +67,9 @@ protected: | |||
66 | */ | 67 | */ |
67 | virtual void calcGeometry() {}; | 68 | virtual void calcGeometry(); |
69 | |||
70 | |||
71 | /** | ||
72 | * @param const ColorEntry* table, the new color table | ||
73 | */ | ||
74 | void setColorTable( const ColorEntry table[] ); | ||
68 | 75 | ||
@@ -79,2 +86,27 @@ protected: | |||
79 | 86 | ||
87 | protected: | ||
88 | |||
89 | enum ScrollLocation | ||
90 | { | ||
91 | SCRNONE, | ||
92 | SCRLEFT, | ||
93 | SCRIGHT | ||
94 | }; | ||
95 | |||
96 | int f_height; | ||
97 | int f_width; | ||
98 | int f_ascent; | ||
99 | int m_blX; | ||
100 | int m_blY; | ||
101 | int m_brX; | ||
102 | |||
103 | int m_bY; | ||
104 | int m_bX; | ||
105 | QScrollBar* m_scrollbar; | ||
106 | |||
107 | ScrollLocation scrollLoc; | ||
108 | |||
109 | ColorEntry* color_table; | ||
110 | |||
111 | bool blinking; | ||
80 | }; | 112 | }; |