summaryrefslogtreecommitdiff
authoribotty <ibotty>2002-10-12 17:27:39 (UTC)
committer ibotty <ibotty>2002-10-12 17:27:39 (UTC)
commit9c983d273b055d847cf2d1fa4f5b6e082ce850c9 (patch) (unidiff)
treee9e6c6320ad3ba926089786f7b187dc62b0af359
parente6b92ad451dba66f4eb5000a41b96eb2ee203dce (diff)
downloadopie-9c983d273b055d847cf2d1fa4f5b6e082ce850c9.zip
opie-9c983d273b055d847cf2d1fa4f5b6e082ce850c9.tar.gz
opie-9c983d273b055d847cf2d1fa4f5b6e082ce850c9.tar.bz2
added functionality to emulation_widget
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/emulation_widget.cpp208
-rw-r--r--noncore/apps/opie-console/emulation_widget.h38
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
@@ -1,45 +1,245 @@
1// opie-console includes 1// opie-console includes
2#include "emulation_widget.h" 2#include "emulation_widget.h"
3#include "common.h" 3#include "common.h"
4#include "widget_layer.h" 4#include "widget_layer.h"
5#include "profile.h" 5#include "profile.h"
6 6
7// qt includes 7// qt includes
8#include <qwidget.h> 8#include <qwidget.h>
9#include <qarray.h> 9#include <qarray.h>
10#include <qstring.h> 10#include <qstring.h>
11#include <qpainter.h> 11#include <qpainter.h>
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
15EmulationWidget::EmulationWidget( const Profile& config, QWidget *parent, const char* name ) : WidgetLayer( config, parent, name ) 20EmulationWidget::EmulationWidget( const Profile& config, QWidget *parent, const char* name ) : WidgetLayer( config, parent, name )
16{ 21{
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
39void EmulationWidget::reloadConfig( const Profile& config )
40{
41
42 // nothing yet
18} 43}
19 44
20EmulationWidget::~EmulationWidget() 45EmulationWidget::~EmulationWidget()
21{ 46{
47 //clean up
22} 48}
23 49
50static 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
25void setImage( QArray<Character> const newimg, int lines, int columns ) 89
90
91void 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
29void 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
160void 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
192void 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///////////////////////
36// scrollbar 220// scrollbar
37// //////////////////// 221// ////////////////////
38 222
39void EmulationWidget::scroll( int value ) 223void EmulationWidget::scroll( int value )
40{ 224{
41} 225}
42 226
43void EmulationWidget::setScroll( int cursor, int slines ) 227void EmulationWidget::setScroll( int cursor, int slines )
44{ 228{
45} 229}
230
231
232static 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
@@ -2,24 +2,25 @@
2#include "widget_layer.h" 2#include "widget_layer.h"
3#include "profile.h" 3#include "profile.h"
4#include "common.h" 4#include "common.h"
5 5
6// qt includes 6// qt includes
7#include <qwidget.h> 7#include <qwidget.h>
8#include <qpainter.h> 8#include <qpainter.h>
9#include <qstring.h> 9#include <qstring.h>
10#include <qarray.h> 10#include <qarray.h>
11#include <qrect.h> 11#include <qrect.h>
12 12
13 13
14
14/** 15/**
15 * EmulationWidget 16 * EmulationWidget
16 * simple implementation of EmulationLayer 17 * simple implementation of EmulationLayer
17 * (doesn't support scrollbar, history, etc, yet) 18 * (doesn't support scrollbar, history, etc, yet)
18 */ 19 */
19class EmulationWidget : public WidgetLayer 20class EmulationWidget : public WidgetLayer
20{ Q_OBJECT 21{ Q_OBJECT
21 22
22public: 23public:
23 24
24 /** 25 /**
25 * constructor 26 * constructor
@@ -31,50 +32,81 @@ public:
31 32
32 /** 33 /**
33 * destructor 34 * destructor
34 */ 35 */
35 ~EmulationWidget(); 36 ~EmulationWidget();
36 37
37 /** 38 /**
38 * sets the image 39 * sets the image
39 * @param QArray<Character> const newimg, the new image 40 * @param QArray<Character> const newimg, the new image
40 * @param int lines, lines of the new image 41 * @param int lines, lines of the new image
41 * @param int columns, columns of the new image 42 * @param int columns, columns of the new image
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
45 /** 46 /**
46 * reloads configuration 47 * reloads configuration
47 * @param const Profile& config, configuration 48 * @param const Profile& config, configuration
48 */ 49 */
49 virtual void reloadConfig( const Profile& config ) {}; 50 virtual void reloadConfig( const Profile& config );
50 51
51 /** 52 /**
52 * sets the scrollbar (not yet implemented) 53 * sets the scrollbar (not yet implemented)
53 */ 54 */
54 virtual void setScroll( int cursor, int slines ); 55 virtual void setScroll( int cursor, int slines );
55 56
56 /** 57 /**
57 * scrolls (not yet implemented) 58 * scrolls (not yet implemented)
58 * @param int value, scroll by this value 59 * @param int value, scroll by this value
59 */ 60 */
60 virtual void scroll( int value ); 61 virtual void scroll( int value );
61 62
62protected: 63protected:
63 64
64 /** 65 /**
65 * calculates current image bounds 66 * calculates current image bounds
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
69 /** 76 /**
70 * draws a String 77 * draws a String
71 * @param QString& string, string to be drawn 78 * @param QString& string, string to be drawn
72 * @param QPainter& painter, painter, that should draw 79 * @param QPainter& painter, painter, that should draw
73 * @param QRect rect, rect to be drawn into 80 * @param QRect rect, rect to be drawn into
74 * @param Character attr, attributes of Characters 81 * @param Character attr, attributes of Characters
75 * @param bool usePixmap, if to use the background pixmap (currently not supported) 82 * @param bool usePixmap, if to use the background pixmap (currently not supported)
76 * @param bool clear, if rect should be cleared 83 * @param bool clear, if rect should be cleared
77 */ 84 */
78 void drawAttrString( QString& string, QPainter& painter, QRect rect, Character attr, bool pm, bool clear ); 85 void drawAttrString( QString& string, QPainter& painter, QRect rect, Character attr, bool pm, bool clear );
79 86
87protected:
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};