Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

unikeyboard.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "unikeyboard.h"
00022 
00023 #include <qpe/fontmanager.h>
00024 #include <qpe/config.h>
00025 #include <qpainter.h>
00026 #include <qfontmetrics.h>
00027 #include <qcombobox.h>
00028 #if defined(Q_WS_QWS) || defined(_WS_QWS_)
00029 #include <qwindowsystem_qws.h>
00030 #endif
00031 
00032 static const int nw = 8;
00033 
00034 typedef struct BlockMap {
00035     ushort start;
00036     ushort stop;
00037     const char *name;
00038 };
00039 
00040 //# Start Code; Block Name
00041 
00042 static const BlockMap blockMap[] = 
00043 {
00044 {0x0000, 0x007F, "Basic Latin"},
00045 {0x0080, 0x00FF, "Latin-1 Supplement"},
00046 {0x0100, 0x017F, "Latin Extended-A"},
00047 {0x0180, 0x024F, "Latin Extended-B"},
00048 {0x0250, 0x02AF, "IPA Extensions"},
00049 {0x02B0, 0x02FF, "Spacing Modifier Letters"},
00050 {0x0300, 0x036F, "Combining Diacritical Marks"},
00051 {0x0370, 0x03FF, "Greek"},
00052 {0x0400, 0x04FF, "Cyrillic"},
00053 {0x0530, 0x058F, "Armenian"},
00054 {0x0590, 0x05FF, "Hebrew"},
00055 {0x0600, 0x06FF, "Arabic"},
00056 {0x0700, 0x074F, "Syriac  "},
00057 {0x0780, 0x07BF, "Thaana"},
00058 {0x0900, 0x097F, "Devanagari"},
00059 {0x0980, 0x09FF, "Bengali"},
00060 {0x0A00, 0x0A7F, "Gurmukhi"},
00061 {0x0A80, 0x0AFF, "Gujarati"},
00062 {0x0B00, 0x0B7F, "Oriya"},
00063 {0x0B80, 0x0BFF, "Tamil"},
00064 {0x0C00, 0x0C7F, "Telugu"},
00065 {0x0C80, 0x0CFF, "Kannada"},
00066 {0x0D00, 0x0D7F, "Malayalam"},
00067 {0x0D80, 0x0DFF, "Sinhala"},
00068 {0x0E00, 0x0E7F, "Thai"},
00069 {0x0E80, 0x0EFF, "Lao"},
00070 {0x0F00, 0x0FFF, "Tibetan"},
00071 {0x1000, 0x109F, "Myanmar "},
00072 {0x10A0, 0x10FF, "Georgian"},
00073 {0x1100, 0x11FF, "Hangul Jamo"},
00074 {0x1200, 0x137F, "Ethiopic"},
00075 {0x13A0, 0x13FF, "Cherokee"},
00076 {0x1400, 0x167F, "Unified Canadian Aboriginal Syllabics"},
00077 {0x1680, 0x169F, "Ogham"},
00078 {0x16A0, 0x16FF, "Runic"},
00079 {0x1780, 0x17FF, "Khmer"},
00080 {0x1800, 0x18AF, "Mongolian"},
00081 {0x1E00, 0x1EFF, "Latin Extended Additional"},
00082 {0x1F00, 0x1FFF, "Greek Extended"},
00083 {0x2000, 0x206F, "General Punctuation"},
00084 {0x2070, 0x209F, "Superscripts and Subscripts"},
00085 {0x20A0, 0x20CF, "Currency Symbols"},
00086 {0x20D0, 0x20FF, "Combining Marks for Symbols"},
00087 {0x2100, 0x214F, "Letterlike Symbols"},
00088 {0x2150, 0x218F, "Number Forms"},
00089 {0x2190, 0x21FF, "Arrows"},
00090 {0x2200, 0x22FF, "Mathematical Operators"},
00091 {0x2300, 0x23FF, "Miscellaneous Technical"},
00092 {0x2400, 0x243F, "Control Pictures"},
00093 {0x2440, 0x245F, "Optical Character Recognition"},
00094 {0x2460, 0x24FF, "Enclosed Alphanumerics"},
00095 {0x2500, 0x257F, "Box Drawing"},
00096 {0x2580, 0x259F, "Block Elements"},
00097 {0x25A0, 0x25FF, "Geometric Shapes"},
00098 {0x2600, 0x26FF, "Miscellaneous Symbols"},
00099 {0x2700, 0x27BF, "Dingbats"},
00100 {0x2800, 0x28FF, "Braille Patterns"},
00101 {0x2E80, 0x2EFF, "CJK Radicals Supplement"},
00102 {0x2F00, 0x2FDF, "Kangxi Radicals"},
00103 {0x2FF0, 0x2FFF, "Ideographic Description Characters"},
00104 {0x3000, 0x303F, "CJK Symbols and Punctuation"},
00105 {0x3040, 0x309F, "Hiragana"},
00106 {0x30A0, 0x30FF, "Katakana"},
00107 {0x3100, 0x312F, "Bopomofo"},
00108 {0x3130, 0x318F, "Hangul Compatibility Jamo"},
00109 {0x3190, 0x319F, "Kanbun"},
00110 {0x31A0, 0x31BF, "Bopomofo Extended"},
00111 {0x3200, 0x32FF, "Enclosed CJK Letters and Months"},
00112 {0x3300, 0x33FF, "CJK Compatibility"},
00113 {0x3400, 0x4DB5, "CJK Unified Ideographs Extension A"},
00114 {0x4E00, 0x9FFF, "CJK Unified Ideographs"},
00115 {0xA000, 0xA48F, "Yi Syllables"},
00116 {0xA490, 0xA4CF, "Yi Radicals"},
00117 {0xAC00, 0xD7A3, "Hangul Syllables"},
00118 {0xD800, 0xDB7F, "High Surrogates"},
00119 {0xDB80, 0xDBFF, "High Private Use Surrogates"},
00120 {0xDC00, 0xDFFF, "Low Surrogates"},
00121 {0xE000, 0xF8FF, "Private Use"},
00122 {0xF900, 0xFAFF, "CJK Compatibility Ideographs"},
00123 {0xFB00, 0xFB4F, "Alphabetic Presentation Forms"},
00124 {0xFB50, 0xFDFF, "Arabic Presentation Forms-A"},
00125 {0xFE20, 0xFE2F, "Combining Half Marks"},
00126 {0xFE30, 0xFE4F, "CJK Compatibility Forms"},
00127 {0xFE50, 0xFE6F, "Small Form Variants"},
00128 {0xFE70, 0xFEFE, "Arabic Presentation Forms-B"},
00129 {0xFF00, 0xFEFF, "Halfwidth and Fullwidth Forms"},
00130 {0xFFF0, 0xFFEF, "Specials"},
00131 {0xFFFF, 0xFFFF,        0} };
00132 
00133 
00134 UniScrollview::UniScrollview(QWidget* parent, const char* name, int f) :
00135     QScrollView(parent, name, f)
00136 {
00137     //    smallFont.setRawName( "-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1" ); //######
00138 
00139     // get the default font
00140     Config *config = new Config( "qpe" );
00141     config->setGroup( "Appearance" );
00142     QString familyStr = config->readEntry( "FontFamily", "Helvetica" );
00143     int fontSize = config->readNumEntry( "FontSize", 8 ) - 2;
00144     delete config;
00145 
00146     smallFont = QFont( familyStr, fontSize );
00147     QFontMetrics sfm( smallFont );
00148     xoff = sfm.width( "AAA" );
00149     setFont( FontManager::unicodeFont( FontManager::Fixed ) );
00150     QFontMetrics fm( font() );
00151     cellsize = fm.lineSpacing() + 2;
00152     resizeContents( cellsize*nw, cellsize*65536/nw );
00153     verticalScrollBar()->setLineStep(cellsize);
00154     
00155     viewport()->setBackgroundMode( QWidget::PaletteBase );
00156 }
00157 
00158 
00159 
00160 void UniScrollview::contentsMousePressEvent(QMouseEvent* e)
00161 {
00162     if ( e->x() < xoff || e->x() > xoff + nw*cellsize )
00163         return;
00164     int row = e->y()/cellsize;
00165     int col = (e->x()-xoff)/cellsize;
00166     int u = row*nw+col;
00167 #if defined(Q_WS_QWS) || defined(_WS_QWS_)
00168     emit key( u, 0, 0, true, false );
00169     emit key( u, 0, 0, false, false );
00170 #endif
00171 }
00172 
00173 
00174 void UniScrollview::contentsMouseReleaseEvent(QMouseEvent*)
00175 {
00176 }
00177 
00178 void UniScrollview::scrollTo( int unicode )
00179 {
00180     int row = unicode / nw;
00181     setContentsPos( 0, row*cellsize );
00182 }
00183 
00184 
00185 void UniScrollview::drawContents( QPainter *p, int /*cx*/, int cy, int /*cw*/, int ch )
00186 {
00187     QFontMetrics fm = fontMetrics();
00188     int row = cy / cellsize;
00189     int y = row*cellsize;
00190     while ( y < cy+ch ) {
00191         p->drawLine( xoff, y, xoff+nw*cellsize, y );
00192         if ( row*nw%16 == 0 ) {
00193             p->setFont( smallFont );
00194             QString s;
00195             s.sprintf( "%03X", row*nw/16 ); 
00196             p->drawText( 0, y, xoff, cellsize, AlignLeft, s );
00197             p->setFont( font() );
00198         }
00199         for ( int i = 0; i < nw; i++ ) {
00200             p->drawLine( xoff+i*cellsize, y, xoff+i*cellsize, y+cellsize );
00201             QChar u = row*nw + i;
00202             if ( fm.inFont( u ) )
00203                 p->drawText( xoff+i*cellsize, y, cellsize, cellsize, AlignCenter,
00204                              u );
00205         }
00206         p->drawLine( xoff+nw*cellsize, y, xoff+nw*cellsize, y+cellsize );
00207         row++;
00208         y += cellsize;
00209     }
00210 }
00211 
00212 
00213 
00214 
00215 UniKeyboard::UniKeyboard(QWidget* parent, const char* name, int f )
00216     : QFrame( parent, name, f )
00217 {
00218     setFrameStyle( NoFrame );
00219     sv = new UniScrollview( this );
00220     cb = new QComboBox( FALSE, this );
00221     currentBlock = 0;
00222     QFontMetrics fm = sv->fontMetrics();
00223     cbmap = new int[sizeof(blockMap)/sizeof(blockMap[0])];
00224     for ( int i = 0; blockMap[i].name; i++ ) {
00225         bool any=FALSE;
00226         for ( int c=blockMap[i].start; !any && c<=blockMap[i].stop; c++ )
00227             any = fm.inFont(QChar(c));
00228         if ( any ) {
00229             cbmap[cb->count()]=i;
00230             cb->insertItem( blockMap[i].name );
00231         }
00232     }
00233     connect( cb, SIGNAL( activated(int)), this, SLOT( handleCombo(int)) );
00234     connect( sv, SIGNAL( contentsMoving(int,int)), this, SLOT( svMove(int,int)) );
00235     connect( sv, SIGNAL( key(ushort,ushort,ushort,bool,bool)),
00236             this, SIGNAL( key(ushort,ushort,ushort,bool,bool)) );
00237 }
00238 
00239 UniKeyboard::~UniKeyboard()
00240 {
00241     delete [] cbmap;
00242 }
00243 
00244 void UniKeyboard::resizeEvent(QResizeEvent *)
00245 {
00246     int d = frameWidth();
00247     cb->setGeometry( d, d, width()-2*d, cb->sizeHint().height() );
00248     sv->setGeometry( d, cb->height()+d, width()-2*d, height()-cb->height()-2*d );
00249 }
00250 
00251 void UniKeyboard::svMove( int /*x*/, int y )
00252 {
00253     int cs = sv->cellSize();
00254     int u = ((y+cs-1)/cs) * nw;
00255     int i = currentBlock;
00256     while ( i > 0 && blockMap[i].start > u ) {
00257        i--;
00258     }
00259     while ( blockMap[i+1].name && blockMap[i+1].start < u ) {
00260         i++;
00261     }
00262     if ( i != currentBlock ) {
00263         currentBlock = i;
00264         for (int ind=0; ind<cb->count(); ind++) {
00265             if ( cbmap[ind] == i ) {
00266                 cb->setCurrentItem( ind );
00267                 break;
00268             }
00269         }
00270     }
00271 }
00272 
00273 void UniKeyboard::handleCombo( int i )
00274 {
00275     currentBlock = cbmap[i];
00276     sv->scrollTo( blockMap[currentBlock].start );
00277 }
00278 
00279 void UniKeyboard::resetState()
00280 {
00281 }
00282 
00283 QSize UniKeyboard::sizeHint() const
00284 {
00285     return QSize( 240, 2+sv->cellSize()*4+cb->sizeHint().height() );
00286 }

Generated on Sat Nov 5 16:16:04 2005 for OPIE by  doxygen 1.4.2