author | hash <hash> | 2002-10-14 16:53:01 (UTC) |
---|---|---|
committer | hash <hash> | 2002-10-14 16:53:01 (UTC) |
commit | 03d355295dd4fd6c37e54d281280127c0cf8a068 (patch) (side-by-side diff) | |
tree | f36c74dd7909644a2ade8b4fc8fe2aeb4af32e90 /inputmethods | |
parent | 8168216f961dc60db1acdea8671eeaa93e3ed560 (diff) | |
download | opie-03d355295dd4fd6c37e54d281280127c0cf8a068.zip opie-03d355295dd4fd6c37e54d281280127c0cf8a068.tar.gz opie-03d355295dd4fd6c37e54d281280127c0cf8a068.tar.bz2 |
patch hector sent it for accent and back accent support
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 148 | ||||
-rw-r--r-- | inputmethods/multikey/keyboard.h | 6 |
2 files changed, 153 insertions, 1 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index 28d5cab..1dd8ca1 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp @@ -20,49 +20,49 @@ #include "keyboard.h" #include "configdlg.h" #include <qpe/global.h> #include <qpe/qcopenvelope_qws.h> #include <qwindowsystem_qws.h> #include <qpainter.h> #include <qfontmetrics.h> #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <ctype.h> #include <qfile.h> #include <qtextstream.h> #include <qstringlist.h> #include <sys/utsname.h> /* Keyboard::Keyboard {{{1 */ Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), - meta(0), circumflex(0), diaeresis(0), + meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0), useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1), unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), configdlg(0) { // get the default font Config *config = new Config( "qpe" ); config->setGroup( "Appearance" ); QString familyStr = config->readEntry( "FontFamily", "fixed" ); delete config; config = new Config("multikey"); config->setGroup ("general"); usePicks = config->readBoolEntry ("usePickboard", 0); // default closed useRepeat = config->readBoolEntry ("useRepeat", 1); delete config; setFont( QFont( familyStr, 10 ) ); picks = new KeyboardPicks( this ); picks->setFont( QFont( familyStr, 10 ) ); @@ -169,57 +169,65 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col) for (int i = 0; i < col; i++) { x += keys->width(row, i) * defaultKeyWidth; } int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); int keyWidth = keys->width(row, col); p.fillRect(x + 1, y + 1, keyWidth * defaultKeyWidth - 1, keyHeight - 1, pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); QImage *pix = keys->pix(row,col); ushort c = keys->uni(row, col); p.setPen(textcolor); if (!pix) { if ((shift || lock) && keys->shift(c)) if (circumflex && keys->circumflex(keys->shift(c))) c = keys->circumflex(keys->shift(c)); else if (diaeresis && keys->diaeresis(keys->shift(c))) c = keys->diaeresis(keys->shift(c)); + else if (baccent && keys->baccent(keys->shift(c))) + c = keys->baccent(keys->shift(c)); + else if (accent && keys->accent(keys->shift(c))) + c = keys->accent(keys->shift(c)); else if (meta && keys->meta(keys->shift(c))) c = keys->meta(keys->shift(c)); else c = keys->shift(c); else if (meta && keys->meta(c)) c = keys->meta(c); else if (circumflex && keys->circumflex(c)) c = keys->circumflex(c); + else if (baccent && keys->baccent(c)) + c = keys->baccent(c); + else if (accent && keys->accent(c)) + c = keys->accent(c); else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { // the diaeresis key itself has to be in the diaeresisMap, // or just do this to make it display the diaeresis char. if (c == 0x2c6) c = 0xa8; else c = keys->diaeresis(c); } p.drawText(x, y, defaultKeyWidth * keyWidth + 3, keyHeight, AlignCenter, (QChar)c); } else // center the image in the middle of the key p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1, y + (keyHeight - pix->height())/2 + 1, *pix ); // this fixes the problem that the very right end of the board's vertical line // gets painted over, because it's one pixel shorter than all other keys p.setPen(keycolor_lines); @@ -239,57 +247,65 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col) p.drawLine(x, y, x + width(), y); for (int col = 0; col < keys->numKeys(row); col++) { QImage *pix = keys->pix(row, col); int keyWidth = keys->width(row, col); int keyWidthPix = defaultKeyWidth * keyWidth; if (keys->pressed(row, col)) p.fillRect(x+1, y+1, keyWidthPix - 1, keyHeight - 1, keycolor_pressed); ushort c = keys->uni(row, col); p.setPen(textcolor); if (!pix) { if ((shift || lock) && keys->shift(c)) if (circumflex && keys->circumflex(keys->shift(c))) c = keys->circumflex(keys->shift(c)); else if (diaeresis && keys->diaeresis(keys->shift(c))) c = keys->diaeresis(keys->shift(c)); + else if (baccent && keys->baccent(keys->shift(c))) + c = keys->baccent(keys->shift(c)); + else if (accent && keys->accent(keys->shift(c))) + c = keys->accent(keys->shift(c)); else if (meta && keys->meta(keys->shift(c))) c = keys->meta(keys->shift(c)); else c = keys->shift(c); else if (meta && keys->meta(c)) c = keys->meta(c); else if (circumflex && keys->circumflex(c)) c = keys->circumflex(c); + else if (baccent && keys->baccent(c)) + c = keys->baccent(c); + else if (accent && keys->accent(c)) + c = keys->accent(c); else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { if (c == 0x2c6) c = 0xa8; else c = keys->diaeresis(c); } p.drawText(x, y, keyWidthPix + 3, keyHeight, AlignCenter, (QChar)c); } else { // center the image in the middle of the key pix->setColor(1, textcolor.rgb()); p.drawImage( x + (keyWidthPix - pix->width())/2 + 1, y + (keyHeight - pix->height())/2 + 1, QImage(*pix) ); } p.setPen(keycolor_lines); p.drawLine(x, y, x, y + keyHeight); x += keyWidthPix; @@ -325,48 +341,83 @@ void Keyboard::mousePressEvent(QMouseEvent *e) qkeycode = keys->qcode(row, col); unicode = keys->uni(row, col); // might need to repaint if two or more of the same keys. // should be faster if just paint one key even though multiple keys exist. bool need_repaint = FALSE; // circumflex and diaeresis support // messy to have this here, but too hard to implement any other method if (unicode == 0x2c6) { unicode = 0; if (shift || lock) { // diaeresis qkeycode = 0x2001; } else { // circumflex qkeycode = 0x2000; } } + // Back accent character support + + if (unicode == 0x60) { + + unicode = 0; + if (shift || lock) { + + // circumblex + qkeycode = 0x2000; + } + else { + + // back accent + qkeycode = 0x2002; + } + } + + // Accent character support + + if (unicode == 0xb4) { + + unicode = 0; + if (shift || lock) { + + // diaeresis + qkeycode = 0x2001; + } + else { + + // accent + qkeycode = 0x2003; + } + } + + if (unicode == 0) { // either Qt char, or nothing if (qkeycode == Qt::Key_F1) { // toggle the pickboard if ( configdlg ) { delete (ConfigDlg *) configdlg; configdlg = 0; } else { configdlg = new ConfigDlg (); connect(configdlg, SIGNAL(setMapToDefault()), this, SLOT(setMapToDefault())); connect(configdlg, SIGNAL(setMapToFile(QString)), this, SLOT(setMapToFile(QString))); connect(configdlg, SIGNAL(pickboardToggled(bool)), this, SLOT(togglePickboard(bool))); connect(configdlg, SIGNAL(repeatToggled(bool)), this, SLOT(toggleRepeat(bool))); connect(configdlg, SIGNAL(reloadKeyboard()), this, SLOT(reloadKeyboard())); connect(configdlg, SIGNAL(configDlgClosed()), this, SLOT(cleanupConfigDlg())); configdlg->showMaximized(); @@ -451,48 +502,50 @@ void Keyboard::mousePressEvent(QMouseEvent *e) /* if (meta) { *meta = 0; meta = 0; } if (circumflex) { *circumflex = 0; circumflex = 0; } if (diaeresis) { *diaeresis = 0; diaeresis = 0; } */ } else if (qkeycode == Qt::Key_Meta) { need_repaint = TRUE; if (meta) { *meta = 0; meta = 0; } else { meta = keys->pressedPtr(row, col); *meta = true; } // reset all the other keys if (shift) { *shift = 0; shift = 0; } if (lock) { *lock = 0; lock = 0; } if (circumflex) { *circumflex = 0; circumflex = 0; } if (diaeresis) { *diaeresis = 0; diaeresis = 0; } + if (baccent) { *baccent = 0; baccent = 0; } + if (accent) { *accent = 0; accent = 0; } // dont need to emit this key... acts same as alt qkeycode = 0; // circumflex } else if (qkeycode == 0x2000) { need_repaint = TRUE; if (circumflex) { *circumflex = 0; circumflex = 0; } else { circumflex = keys->pressedPtr(row, col); *circumflex = true; } /* no need to turn off shift or lock if circumflex * keys are pressed if (shift) { *shift = 0; shift = 0; } if (lock) { *lock = 0; lock = 0; } @@ -530,76 +583,130 @@ void Keyboard::mousePressEvent(QMouseEvent *e) *diaeresis = true; } if (shift) { *shift = 0; shift = 0; } /* * if (lock) { *lock = 0; lock = 0; } * */ if (meta) { *meta = 0; meta = 0; } if (circumflex) { // *circumflex = 0; // // same thing the diaeresis pointer points too circumflex = 0; } qkeycode = 0; + + // Back accent + } else if (qkeycode == 0x2002) { + need_repaint = TRUE; + + if (baccent) { + + *baccent = 0; + baccent = 0; + + } else { + + baccent = keys->pressedPtr(row, col); + *baccent = true; + } + + + if (shift) { *shift = 0; shift = 0; } + if (meta) { *meta = 0; meta = 0; } + if (accent) { *accent = 0; accent = 0; } + + qkeycode = 0; + + // Accent + } else if (qkeycode == 0x2003) { + need_repaint = TRUE; + + if (accent) { + + *accent = 0; + accent = 0; + + } else { + + accent = keys->pressedPtr(row, col); + *accent = true; + } + + + if (shift) { *shift = 0; shift = 0; } + if (meta) { *meta = 0; meta = 0; } + if (baccent) { *baccent = 0; } + + qkeycode = 0; } } else { // normal char if ((shift || lock) && keys->shift(unicode)) { // make diaeresis/circumflex -> shift input shifted // diaeresis/circumflex chars if (circumflex && keys->circumflex(keys->shift(unicode))) unicode = keys->circumflex(keys->shift(unicode)); else if (diaeresis && keys->diaeresis(keys->shift(unicode))) unicode = keys->diaeresis(keys->shift(unicode)); + else if (baccent && keys->baccent(keys->shift(unicode))) + unicode = keys->baccent(keys->shift(unicode)); + else if (accent && keys->accent(keys->shift(unicode))) + unicode = keys->accent(keys->shift(unicode)); else if (meta && keys->meta(keys->shift(unicode))) unicode = keys->meta(keys->shift(unicode)); else unicode = keys->shift(unicode); } else if (meta && keys->meta(unicode)) { unicode = keys->meta(unicode); } else if (circumflex && keys->circumflex(unicode)) { unicode = keys->circumflex(unicode); } else if (diaeresis && keys->diaeresis(unicode)) { unicode = keys->diaeresis(unicode); } + else if (baccent && keys->baccent(unicode)) { + unicode = keys->baccent(unicode); + } + else if (accent && keys->accent(unicode)) { + unicode = keys->accent(unicode); + } } // korean parsing if (keys->lang == "ko") { unicode = parseKoreanInput(unicode); } modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); if ('A' <= unicode && unicode <= 'z' && modifiers) { qkeycode = QChar(unicode).upper(); unicode = qkeycode - '@'; } QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); // pickboard stuff if (usePicks) { KeyboardConfig *dc = picks->dc; if (dc) { @@ -712,48 +819,50 @@ void Keyboard::clearHighlight() QPainter p(this); drawKeyboard(p, tmpRow, tmpCol); } } /* Keyboard::sizeHint {{{1 */ QSize Keyboard::sizeHint() const { QFontMetrics fm=fontMetrics(); int keyHeight = fm.lineSpacing() + 2; return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1); } void Keyboard::resetState() { if (shift) { *shift = 0; shift = 0; } if (lock) {*lock = 0; lock = 0; } if (meta) { *meta = 0; meta = 0; } if (circumflex) { *circumflex = 0; circumflex = 0; } if (diaeresis) { *diaeresis = 0; diaeresis = 0; } + if (baccent) { *baccent = 0; baccent = 0; } + if (accent) { *accent = 0; accent = 0; } schar = mchar = echar = 0; picks->resetState(); } /* Keyboard::togglePickboard {{{1 */ void Keyboard::togglePickboard(bool on_off) { usePicks = on_off; if (usePicks) { picks->show(); //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send //adjustSize(); QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); } else { picks->hide(); picks->resetState(); //move(x(), y() + picks->height()); //adjustSize(); QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); @@ -1319,48 +1428,73 @@ void Keys::setKeysFromFile(const char * filename) { // circumflex else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { QTextStream tmp (buf, IO_ReadOnly); ushort lower, shift; QChar c; tmp >> c >> lower >> shift; circumflexMap.insert(lower, shift); buf = t.readLine(); } // diaeresis else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { QTextStream tmp (buf, IO_ReadOnly); ushort lower, shift; QChar d; tmp >> d >> lower >> shift; diaeresisMap.insert(lower, shift); buf = t.readLine(); } + // back accent + else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { + + QTextStream tmp (buf, IO_ReadOnly); + ushort lower, shift; + QChar d; + tmp >> d >> lower >> shift; + + baccentMap.insert(lower, shift); + + qDebug ("Estoy añadiendo %i con %i", lower, shift); + buf = t.readLine(); + } + // accent + else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { + + QTextStream tmp (buf, IO_ReadOnly); + ushort lower, shift; + QChar d; + tmp >> d >> lower >> shift; + + accentMap.insert(lower, shift); + + buf = t.readLine(); + } // other variables like lang & title else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { QTextStream tmp (buf, IO_ReadOnly); QString name, equals, value; tmp >> name >> equals >> value; if (name == "lang") { lang = value; } buf = t.readLine(); } // comments else if (buf.contains(QRegExp("^\\s*#"))) { buf = t.readLine(); } else { // blank line, or garbage @@ -1468,28 +1602,40 @@ void Keys::setPressed(const int row, const int col, const bool pressed) { ushort Keys::shift(const ushort uni) { if (shiftMap[uni]) return shiftMap[uni]; else return 0; } ushort Keys::meta(const ushort uni) { if (metaMap[uni]) return metaMap[uni]; else return 0; } ushort Keys::circumflex(const ushort uni) { if (circumflexMap[uni]) return circumflexMap[uni]; else return 0; } ushort Keys::diaeresis(const ushort uni) { if(diaeresisMap[uni]) return diaeresisMap[uni]; else return 0; } +ushort Keys::baccent(const ushort uni) { + + if(baccentMap[uni]) return baccentMap[uni]; + else return 0; +} + +ushort Keys::accent(const ushort uni) { + + if(accentMap[uni]) return accentMap[uni]; + else return 0; +} + bool *Keys::pressedPtr(const int row, const int col) { return keys[row].at(col)->pressed; } diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h index 8af80d0..bc74e71 100644 --- a/inputmethods/multikey/keyboard.h +++ b/inputmethods/multikey/keyboard.h @@ -45,120 +45,126 @@ public: KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0) : PickboardPicks(parent, name, f) { } void initialise(); virtual QSize sizeHint() const; KeyboardConfig *dc; }; class Keys { public: Keys(); Keys(const char * filename); ~Keys(); int width(const int row, const int col); int rows(); ushort uni(const int row, const int col); int qcode(const int row, const int col); bool pressed(const int row, const int col); bool *pressedPtr(const int row, const int col); ushort shift(const ushort); ushort meta(const ushort); ushort circumflex(const ushort); ushort diaeresis(const ushort); + ushort baccent(const ushort); + ushort accent(const ushort); QImage *pix(const int row, const int col); int numKeys(const int row); void setKeysFromFile(const char *filename); void setKey(const int row, const int qcode, const ushort unicode, const int width, QImage *pix); void setPressed(const int row, const int col, const bool pressed); QString lang; QString label; private: typedef struct Key { int qcode; // are qt key codes just unicode values? ushort unicode; int width; // not pixels but relative key width. normal key is 2 // only needed for keys like ctrl that can have multiple keys pressed at once bool *pressed; QImage *pix; }; QList<Key> keys[6]; QMap<ushort,ushort> shiftMap; QMap<ushort,ushort> metaMap; QMap<ushort,ushort> circumflexMap; QMap<ushort,ushort> diaeresisMap; + QMap<ushort,ushort> baccentMap; + QMap<ushort,ushort> accentMap; }; class Keyboard : public QFrame { Q_OBJECT public: Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 ); ~Keyboard(); void resetState(); void mousePressEvent(QMouseEvent*); void mouseReleaseEvent(QMouseEvent*); void resizeEvent(QResizeEvent*); void paintEvent(QPaintEvent* e); //void timerEvent(QTimerEvent* e); void drawKeyboard( QPainter &p, int row = -1, int col = -1); QSize sizeHint() const; signals: void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool ); private slots: void repeat(); void togglePickboard(bool on_off); void toggleRepeat(bool on_off); void setMapToDefault(); void setMapToFile(QString map); void cleanupConfigDlg(); // used to redraw keyboard after edited colors void reloadKeyboard(); private: int getKey( int &w, int j = -1 ); void clearHighlight(); bool *shift; bool *lock; bool *ctrl; bool *alt; bool *meta; bool *circumflex; bool *diaeresis; + bool *baccent; + bool *accent; uint useLargeKeys:1; uint usePicks:1; uint useRepeat:1; int pressedKeyRow; int pressedKeyCol; KeyboardPicks *picks; int keyHeight; int defaultKeyWidth; int xoffs; int unicode; int qkeycode; int modifiers; int pressTid; bool pressed; Keys *keys; /* for korean input */ |