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

keyboard.h

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 #include <qframe.h>
00021 #include <qmap.h>
00022 #include <pickboardcfg.h>
00023 #include <pickboardpicks.h>
00024 #include "configdlg.h"
00025 
00026 class QTimer;
00027 
00028 namespace MultiKey
00029 {
00030 
00031 class KeyboardConfig : public DictFilterConfig
00032 {
00033 public:
00034     KeyboardConfig(PickboardPicks* p) : DictFilterConfig(p), backspaces(0) { nrows = 1; }
00035     virtual void generateText(const QString &s);
00036     void decBackspaces() { if (backspaces) backspaces--; }
00037     void incBackspaces() { backspaces++; }
00038     void resetBackspaces() { backspaces = 0; }
00039 private:
00040     int backspaces;
00041 };
00042 
00043 
00044 class KeyboardPicks : public PickboardPicks
00045 {
00046     Q_OBJECT
00047 public:
00048     KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0)
00049         : PickboardPicks(parent, name, f) { }
00050     void initialise();
00051     virtual QSize sizeHint() const;
00052     KeyboardConfig *dc;
00053 };
00054 
00055 
00056 class Keys {
00057 public:
00058 
00059     Keys();
00060     Keys(const char * filename);
00061     ~Keys();
00062     int     width(const int row, const int col);
00063     int     rows();
00064     ushort  uni(const int row, const int col);
00065     int     qcode(const int row, const int col);
00066     bool    pressed(const int row, const int col);
00067     bool    *pressedPtr(const int row, const int col);
00068     ushort  shift(const ushort);
00069     ushort  meta(const ushort);
00070     ushort  circumflex(const ushort);
00071     ushort  diaeresis(const ushort);
00072     ushort  baccent(const ushort);
00073     ushort  accent(const ushort);
00074     QImage *pix(const int row, const int col);
00075     int     numKeys(const int row);
00076     void    setKeysFromFile(const char *filename);
00077     void    setKey(const int row, const int qcode, const ushort unicode, 
00078                     const int width, QImage *pix);
00079     void    setPressed(const int row, const int col, const bool pressed);
00080     QString lang;
00081     QString label;
00082 
00083 private:
00084 
00085     typedef struct Key {
00086             int qcode; // are qt key codes just unicode values?
00087             ushort unicode;
00088             int width;  // not pixels but relative key width. normal key is 2
00089 
00090         // only needed for keys like ctrl that can have multiple keys pressed at once
00091         bool *pressed; 
00092             QImage *pix;
00093     };
00094 
00095     QList<Key> keys[6];
00096     QMap<ushort,ushort> shiftMap;
00097     QMap<ushort,ushort> metaMap;
00098     QMap<ushort,ushort> circumflexMap;
00099     QMap<ushort,ushort> diaeresisMap;
00100     QMap<ushort,ushort> baccentMap;
00101     QMap<ushort,ushort> accentMap;
00102 
00103 };
00104 
00105 class Keyboard : public QFrame
00106 {
00107     Q_OBJECT
00108 public:
00109     Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 );
00110     ~Keyboard();
00111 
00112     void resetState();
00113 
00114     void mousePressEvent(QMouseEvent*);
00115     void mouseReleaseEvent(QMouseEvent*);
00116     void resizeEvent(QResizeEvent*);
00117     void paintEvent(QPaintEvent* e);
00118     //void timerEvent(QTimerEvent* e);
00119     void drawKeyboard( QPainter &p, int row = -1, int col = -1);
00120 
00121     QSize sizeHint() const;
00122 
00123 signals:
00124     void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool );
00125 
00126 private slots:
00127     void repeat();
00128     void togglePickboard(bool on_off);
00129     void toggleRepeat(bool on_off);
00130     void setMapToDefault();
00131     void setMapToFile(QString map);
00132     void cleanupConfigDlg();
00133     void reloadSw();
00134 
00135     // used to redraw keyboard after edited colors
00136     void reloadKeyboard();
00137     void receive( const QCString &msg, const QByteArray &data );
00138     
00139 private:
00140     int getKey( int &w, int j = -1 );
00141     void clearHighlight();
00142 
00143     bool *shift;
00144     bool *lock;
00145     bool *ctrl;
00146     bool *alt;
00147     bool *meta;
00148     bool *circumflex;
00149     bool *diaeresis;
00150     bool *baccent;
00151     bool *accent;
00152 
00153     uint useLargeKeys:1;
00154     uint usePicks:1;
00155     uint useRepeat:1;
00156     
00157     int pressedKeyRow;
00158     int pressedKeyCol;
00159 
00160     KeyboardPicks *picks;
00161 
00162     int keyHeight;
00163     int defaultKeyWidth;
00164     int xoffs;
00165 
00166     int unicode;
00167     int qkeycode;
00168     int modifiers;
00169 
00170     int pressTid;
00171     bool pressed;
00172 
00173     Keys *keys;
00174 
00175     /* for korean input */
00176     ushort schar, mchar, echar;
00177     ushort parseKoreanInput(ushort c);
00178     ushort combineKoreanChars(const ushort s, const ushort m, const ushort e);
00179     ushort constoe(const ushort c);
00180 
00181     QTimer *repeatTimer;
00182 
00183     /* colors */
00184     void loadKeyboardColors();
00185     QColor keycolor;
00186     QColor keycolor_pressed;
00187     QColor keycolor_lines;
00188     QColor textcolor;
00189 
00190     ConfigDlg *configdlg;
00191 };
00192 
00193 } // namespace MultiKey

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