⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyboard.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "keyboard.h"#include <qtopia/global.h>#ifdef QWS#include <qwindowsystem_qws.h>#endif#include <qpainter.h>#include <qfontmetrics.h>#include <qtimer.h>#include <ctype.h>#define USE_SMALL_BACKSPACEKeyboard::Keyboard(QWidget* parent, const char* name, WFlags f) :    QFrame(parent, name, f),  shift(FALSE), lock(FALSE), ctrl(FALSE),    alt(FALSE), useLargeKeys(TRUE), useOptiKeys(0), pressedKey(-1),    unicode(-1), qkeycode(0), modifiers(0), pressTid(0), pressed(FALSE){    //  setPalette(QPalette(QColor(240,240,230))); // Beige!    //  setFont( QFont( "Helvetica", 8 ) );//    setPalette(QPalette(QColor(200,200,200))); // Gray    setPalette(QPalette(QColor(220,220,220))); // Gray    picks = new KeyboardPicks( this );// under Win32 we may not have smallsmooth font #ifndef Q_OS_WIN32    picks->setFont( QFont( "smallsmooth", 9 ) );    setFont( QFont( "smallsmooth", 9 ) );#endif    picks->initialise();    QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),            this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );    repeatTimer = new QTimer( this );    connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );}void Keyboard::resizeEvent(QResizeEvent*){    int ph = picks->sizeHint().height();    picks->setGeometry( 0, 0, width(), ph );    keyHeight = (height()-ph)/5;    int nk;    if ( useOptiKeys ) {	nk = 15;    } else if ( useLargeKeys ) {	nk = 15;    } else {	nk = 19;    }    defaultKeyWidth = width()/nk;    xoffs = (width()-defaultKeyWidth*nk)/2;}KeyboardPicks::~KeyboardPicks(){    delete dc;}void KeyboardPicks::initialise(){    setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));    mode = 0;    dc = new KeyboardConfig(this);    configs.append(dc);}QSize KeyboardPicks::sizeHint() const{    return QSize(240,fontMetrics().lineSpacing());}void  KeyboardConfig::generateText(const QString &s){#if defined(Q_WS_QWS) || defined(_WS_QWS_)		  int i;    for ( i=0; i<(int)backspaces; i++) {			    parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );	      parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );    }    for ( i=0; i<(int)s.length(); i++) {	      uint code = 0;	      if ( s[i].unicode() >= 'a' && s[i].unicode() <= 'z' ) {	          code = s[i].unicode() - 'a' + Key_A;	      }	      parent->emitKey( s[i].unicode(), code, 0, true, false );	      parent->emitKey( s[i].unicode(), code, 0, false, false );    }    parent->emitKey( 0, Qt::Key_Space, 0, true, false );    parent->emitKey( 0, Qt::Key_Space, 0, false, false );    backspaces = 0;#endif}//PC keyboard layout and scancodes/*  Format: length, code, length, code, ..., 0    length is measured in half the width of a standard key.  If code < 0x80, code gives the ASCII value of the key    If code >= 0x80, the key is looked up in specialM[].   */static const uchar * const keyboard_opti[5] = {     (const uchar *const) "\001\223\003\240\002\20\002\41\002\26\002\62\002\56\002\45\002\54\003\200\001\223\002\226\002\235\002\234\002\236",    (const uchar *const) "\001\223\003\201\004\207\002\30\002\24\002\43\004\207\003\203\001\223\006\002\002\065",    (const uchar *const) "\001\223\003\202\002\60\002\37\002\23\002\22\002\36\002\21\002\55\003\203\001\223\006\005\002\055",    (const uchar *const) "\001\223\003\205\004\207\002\27\002\61\002\40\004\207\003\204\001\223\006\010\002\014",    (const uchar *const) "\001\223\003\206\002\44\002\31\002\57\002\42\002\46\002\25\002\207\003\204\001\223\002\013\002\064\002\015\002\230"};static const uchar * const keyboard_standard[5] = {#ifdef USE_SMALL_BACKSPACE    (const uchar *const)"\002\240\002`\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\002\200\002\223\002\215\002\216\002\217",#else    (const uchar *const)"\002\051\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\004\200\002\223\002\215\002\216\002\217",#endif    //~ + 123...+ BACKSPACE //+ INSERT + HOME + PGUP    (const uchar *const)"\003\201\002q\002w\002e\002r\002t\002y\002u\002i\002o\002p\002[\002]\002\\\001\224\002\223\002\221\002\220\002\222",    //TAB + qwerty..  + backslash //+ DEL + END + PGDN    (const uchar *const)"\004\202\002a\002s\002d\002f\002g\002h\002j\002k\002l\002;\002'\004\203",    //CAPS + asdf.. + RETURN     (const uchar *const)"\005\204\002z\002x\002c\002v\002b\002n\002m\002,\002.\002/\005\204\002\223\002\223\002\211",    //SHIFT + zxcv... //+ UP    (const uchar *const)"\003\205\003\206\022\207\003\206\003\205\002\223\002\212\002\213\002\214"     //CTRL + ALT + SPACE //+ LEFT + DOWN + RIGHT    };struct ShiftMap {    char normal;    char shifted;};static const ShiftMap shiftMap[] = {    { '`', '~' },    { '1', '!' },    { '2', '@' },    { '3', '#' },    { '4', '$' },    { '5', '%' },    { '6', '^' },    { '7', '&' },    { '8', '*' },    { '9', '(' },    { '0', ')' },    { '-', '_' },    { '=', '+' },    { '\\', '|' },    { '[', '{' },    { ']', '}' },    { ';', ':' },    { '\'', '"' },    { ',', '<' },    { '.', '>' },    { '/', '?' }};/* XPM */static const char * const uparrow_xpm[]={"9 9 2 1","a c #000000",". c None",".........","....a....","...aaa...","..aaaaa..","....a....","....a....","....a....","....a....","........."};/* XPM */static const char * const leftarrow_xpm[]={"9 9 2 1","a c #000000",". c None",".........",".........","...a.....","..aa.....",".aaaaaaa.","..aa.....","...a.....",".........","........."};/* XPM */static const char * const downarrow_xpm[]={"9 9 2 1","a c #000000",". c None",".........","....a....","....a....","....a....","....a....","..aaaaa..","...aaa...","....a....","........."};/* XPM */static const char * const rightarrow_xpm[]={"9 9 2 1","a c #000000",". c None",".........",".........",".....a...",".....aa..",".aaaaaaa.",".....aa..",".....a...",".........","........."};/* XPM */static const char * const insert_xpm[]={"9 9 2 1","a c #000000",". c None",".........","a........","a.aaa.aaa","a.a.a.a..","a.a.a..a.","a.a.a...a","a.a.a.aaa",".........","........."};/* XPM */static const char * const delete_xpm[]={"9 9 2 1","a c #000000",". c None",".........","aa......a","a.a.aaa.a","a.a.a.a.a","a.a.aaa.a.","a.a.a...a","aaa.aaa.a",".........","........."};/* XPM */static const char * const home_xpm[]={"9 9 2 1","a c #000000",". c None","....a....","...a.a...","..a...a..",".a.....a.","aa.aaa.aa",".a.a.a.a.",".a.a.a.a.",".aaaaaaa.","........."};/* XPM */static const char * const end_xpm[]={"10 9 2 1","a c #000000",". c None","..........","aa.......a","a..aaa.aaa","aa.a.a.a.a","a..a.a.a.a","a..a.a.a.a","aa.a.a.aaa","..........",".........."};/* XPM */static const char * const pageup_xpm[]={"9 9 2 1","a c #000000",". c None",".aaa.aaa.",".a.a.a.a.",".aaa..aa.",".a...aaa.",".........",".a.a.aaa.",".a.a.a.a.",".aaa.aaa.",".....a..."};/* XPM */static const char * const pagedown_xpm[]={"9 9 2 1","a c #000000",". c None",".aaa.aaa.",".a.a.a.a.",".aaa..aa.",".a...aaa.",".........","...a.....",".aaa.aaa.",".a.a.a.a.",".aaa.a.a."};/* XPM */static const char * const expand_xpm[]={"4 9 2 1","a c #408040",". c None","a...","aa..","aaa.","aaaa","aaaa","aaaa","aaa.","aa..","a..."};/* XPM */#ifdef USE_SMALL_BACKSPACEstatic const char * const backspace_xpm[]={"9 9 2 1","a c #000000",". c None",".........",".........","...a.....","..aa.....",".aaaaaaaa","..aa.....","...a.....",".........","........."};#elsestatic const char * const backspace_xpm[]={"21 9 2 1","a c #000000",". c None",".....................",".....................",".....aaa..a..........",".a...a..a.a.a.aaa.aaa","aaaa.aaa..aa..aa..a.a",".a...a..a.aaa..aa.a.a",".....aaaa.a.a.aaa.aa.","..................a..","....................."};#endif/* XPM */static const char * const escape_xpm[]={"9 9 2 1","a c #000000",". c None",".........",".........",".aa.aa.aa",".a..a..a.",".aa.aa.a.",".a...a.a.",".aa.aa.aa",".........","........."};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -