Diffstat (limited to 'inputmethods/multikey/keyboard.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index 2ce6dd3..aec0ad3 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -18,33 +18,33 @@ | |||
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "keyboard.h" | 21 | #include "keyboard.h" |
22 | #include "configdlg.h" | 22 | #include "configdlg.h" |
23 | 23 | ||
24 | #include <qpe/global.h> | 24 | #include <qpe/global.h> |
25 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
26 | 26 | ||
27 | #include <qwindowsystem_qws.h> | 27 | #include <qwindowsystem_qws.h> |
28 | #include <qpainter.h> | 28 | #include <qpainter.h> |
29 | #include <qfontmetrics.h> | 29 | #include <qfontmetrics.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | #include <qpe/qpeapplication.h> | 31 | #include <qpe/qpeapplication.h> |
32 | #include <qpe/config.h> | 32 | #include <qpe/config.h> |
33 | #include <ctype.h> | 33 | #include <ctype.h> |
34 | #include <qfile.h> | 34 | #include <qdir.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qstringlist.h> | 36 | #include <qstringlist.h> |
37 | 37 | ||
38 | #include <sys/utsname.h> | 38 | #include <sys/utsname.h> |
39 | 39 | ||
40 | using namespace MultiKey; | 40 | using namespace MultiKey; |
41 | 41 | ||
42 | static const char * const kb_config_xpm[] = { | 42 | static const char * const kb_config_xpm[] = { |
43 | "13 7 2 1", | 43 | "13 7 2 1", |
44 | " c None", | 44 | " c None", |
45 | ". c #000000", | 45 | ". c #000000", |
46 | " ", | 46 | " ", |
47 | " . ", | 47 | " . ", |
48 | " ... ", | 48 | " ... ", |
49 | " ..... ", | 49 | " ..... ", |
50 | " . ", | 50 | " . ", |
@@ -81,38 +81,41 @@ Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : | |||
81 | picks->setFont( QFont( familyStr, 10 ) ); | 81 | picks->setFont( QFont( familyStr, 10 ) ); |
82 | picks->initialise(); | 82 | picks->initialise(); |
83 | if (usePicks) { | 83 | if (usePicks) { |
84 | 84 | ||
85 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 85 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
86 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 86 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
87 | 87 | ||
88 | } else picks->hide(); | 88 | } else picks->hide(); |
89 | 89 | ||
90 | loadKeyboardColors(); | 90 | loadKeyboardColors(); |
91 | 91 | ||
92 | keys = new Keys(); | 92 | keys = new Keys(); |
93 | 93 | ||
94 | repeatTimer = new QTimer( this ); | 94 | repeatTimer = new QTimer( this ); |
95 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | 95 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); |
96 | 96 | ||
97 | QCopChannel* kbdChannel = new QCopChannel("MultiKey/Keyboard", this); | ||
98 | connect(kbdChannel, SIGNAL(received(const QCString &, const QByteArray &)), | ||
99 | this, SLOT(receive(const QCString &, const QByteArray &))); | ||
97 | } | 100 | } |
98 | 101 | ||
99 | Keyboard::~Keyboard() { | 102 | Keyboard::~Keyboard() { |
100 | 103 | ||
101 | if ( configdlg ) { | 104 | if ( configdlg ) { |
102 | delete (ConfigDlg *) configdlg; | 105 | delete configdlg; |
103 | configdlg = 0; | 106 | configdlg = 0; |
104 | } | 107 | } |
105 | 108 | ||
106 | } | 109 | } |
107 | 110 | ||
108 | /* Keyboard::resizeEvent {{{1 */ | 111 | /* Keyboard::resizeEvent {{{1 */ |
109 | void Keyboard::resizeEvent(QResizeEvent*) | 112 | void Keyboard::resizeEvent(QResizeEvent*) |
110 | { | 113 | { |
111 | int ph = picks->sizeHint().height(); | 114 | int ph = picks->sizeHint().height(); |
112 | picks->setGeometry( 0, 0, width(), ph ); | 115 | picks->setGeometry( 0, 0, width(), ph ); |
113 | keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1); | 116 | keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1); |
114 | 117 | ||
115 | int nk; // number of keys? | 118 | int nk; // number of keys? |
116 | if ( useLargeKeys ) { | 119 | if ( useLargeKeys ) { |
117 | nk = 15; | 120 | nk = 15; |
118 | } else { | 121 | } else { |
@@ -404,49 +407,51 @@ void Keyboard::mousePressEvent(QMouseEvent *e) | |||
404 | qkeycode = 0x2001; | 407 | qkeycode = 0x2001; |
405 | } | 408 | } |
406 | else { | 409 | else { |
407 | 410 | ||
408 | // accent | 411 | // accent |
409 | qkeycode = 0x2003; | 412 | qkeycode = 0x2003; |
410 | } | 413 | } |
411 | } | 414 | } |
412 | 415 | ||
413 | 416 | ||
414 | if (unicode == 0) { // either Qt char, or nothing | 417 | if (unicode == 0) { // either Qt char, or nothing |
415 | 418 | ||
416 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard | 419 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard |
417 | 420 | ||
418 | if ( configdlg ) { | 421 | if ( configdlg ) { |
419 | 422 | ||
420 | delete (ConfigDlg *) configdlg; | 423 | delete configdlg; |
421 | configdlg = 0; | 424 | configdlg = 0; |
422 | } | 425 | } |
423 | else { | 426 | else { |
424 | configdlg = new ConfigDlg (); | 427 | configdlg = new ConfigDlg (); |
425 | connect(configdlg, SIGNAL(setMapToDefault()), | 428 | connect(configdlg, SIGNAL(setMapToDefault()), |
426 | this, SLOT(setMapToDefault())); | 429 | this, SLOT(setMapToDefault())); |
427 | connect(configdlg, SIGNAL(setMapToFile(QString)), | 430 | connect(configdlg, SIGNAL(setMapToFile(QString)), |
428 | this, SLOT(setMapToFile(QString))); | 431 | this, SLOT(setMapToFile(QString))); |
429 | connect(configdlg, SIGNAL(pickboardToggled(bool)), | 432 | connect(configdlg, SIGNAL(pickboardToggled(bool)), |
430 | this, SLOT(togglePickboard(bool))); | 433 | this, SLOT(togglePickboard(bool))); |
431 | connect(configdlg, SIGNAL(repeatToggled(bool)), | 434 | connect(configdlg, SIGNAL(repeatToggled(bool)), |
432 | this, SLOT(toggleRepeat(bool))); | 435 | this, SLOT(toggleRepeat(bool))); |
433 | connect(configdlg, SIGNAL(reloadKeyboard()), | 436 | connect(configdlg, SIGNAL(reloadKeyboard()), |
434 | this, SLOT(reloadKeyboard())); | 437 | this, SLOT(reloadKeyboard())); |
435 | connect(configdlg, SIGNAL(configDlgClosed()), | 438 | connect(configdlg, SIGNAL(configDlgClosed()), |
436 | this, SLOT(cleanupConfigDlg())); | 439 | this, SLOT(cleanupConfigDlg())); |
440 | connect(configdlg, SIGNAL(reloadSw()), | ||
441 | this, SLOT(reloadSw())); | ||
437 | configdlg->showMaximized(); | 442 | configdlg->showMaximized(); |
438 | configdlg->show(); | 443 | configdlg->show(); |
439 | configdlg->raise(); | 444 | configdlg->raise(); |
440 | } | 445 | } |
441 | 446 | ||
442 | } else if (qkeycode == Qt::Key_Control) { | 447 | } else if (qkeycode == Qt::Key_Control) { |
443 | need_repaint = TRUE; | 448 | need_repaint = TRUE; |
444 | 449 | ||
445 | if (ctrl) { | 450 | if (ctrl) { |
446 | 451 | ||
447 | *ctrl = 0; | 452 | *ctrl = 0; |
448 | ctrl = 0; | 453 | ctrl = 0; |
449 | 454 | ||
450 | } else { | 455 | } else { |
451 | 456 | ||
452 | ctrl = keys->pressedPtr(row, col); | 457 | ctrl = keys->pressedPtr(row, col); |
@@ -747,32 +752,43 @@ void Keyboard::mousePressEvent(QMouseEvent *e) | |||
747 | 752 | ||
748 | if (need_repaint) repaint(FALSE); | 753 | if (need_repaint) repaint(FALSE); |
749 | else { // just paint the one key pressed | 754 | else { // just paint the one key pressed |
750 | 755 | ||
751 | 756 | ||
752 | 757 | ||
753 | QPainter p(this); | 758 | QPainter p(this); |
754 | drawKeyboard(p, row, col); | 759 | drawKeyboard(p, row, col); |
755 | 760 | ||
756 | } | 761 | } |
757 | 762 | ||
758 | if (useRepeat) repeatTimer->start( 800 ); | 763 | if (useRepeat) repeatTimer->start( 800 ); |
759 | //pressTid = startTimer(80); | 764 | //pressTid = startTimer(80); |
760 | 765 | ||
761 | } | 766 | } |
762 | 767 | ||
768 | void Keyboard::receive(const QCString &msg, const QByteArray &data) | ||
769 | { | ||
770 | if (msg == "setmultikey(QString)") { | ||
771 | QDataStream stream(data, IO_ReadOnly); | ||
772 | QString map; | ||
773 | stream >> map; | ||
774 | setMapToFile(map); | ||
775 | } else if (msg == "getmultikey()") { | ||
776 | reloadSw(); | ||
777 | } | ||
778 | } | ||
763 | 779 | ||
764 | /* Keyboard::mouseReleaseEvent {{{1 */ | 780 | /* Keyboard::mouseReleaseEvent {{{1 */ |
765 | void Keyboard::mouseReleaseEvent(QMouseEvent*) | 781 | void Keyboard::mouseReleaseEvent(QMouseEvent*) |
766 | { | 782 | { |
767 | pressed = FALSE; | 783 | pressed = FALSE; |
768 | //if ( pressTid == 0 ) | 784 | //if ( pressTid == 0 ) |
769 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 785 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
770 | if ( unicode != -1 ) { | 786 | if ( unicode != -1 ) { |
771 | emit key( unicode, qkeycode, modifiers, false, false ); | 787 | emit key( unicode, qkeycode, modifiers, false, false ); |
772 | repeatTimer->stop(); | 788 | repeatTimer->stop(); |
773 | } | 789 | } |
774 | #endif | 790 | #endif |
775 | if (shift && unicode != 0) { | 791 | if (shift && unicode != 0) { |
776 | 792 | ||
777 | 793 | ||
778 | *shift = 0; // unpress shift key | 794 | *shift = 0; // unpress shift key |
@@ -898,47 +914,63 @@ void Keyboard::togglePickboard(bool on_off) | |||
898 | /* | 914 | /* |
899 | * this closes && opens the input method | 915 | * this closes && opens the input method |
900 | */ | 916 | */ |
901 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); | 917 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); |
902 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); | 918 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); |
903 | } | 919 | } |
904 | 920 | ||
905 | void Keyboard::toggleRepeat(bool on) { | 921 | void Keyboard::toggleRepeat(bool on) { |
906 | 922 | ||
907 | useRepeat = on; | 923 | useRepeat = on; |
908 | //cout << "setting useRepeat to: " << useRepeat << "\n"; | 924 | //cout << "setting useRepeat to: " << useRepeat << "\n"; |
909 | } | 925 | } |
910 | 926 | ||
911 | void Keyboard::cleanupConfigDlg() { | 927 | void Keyboard::cleanupConfigDlg() { |
912 | 928 | ||
913 | if ( configdlg ) { | 929 | if ( configdlg ) { |
914 | delete (ConfigDlg *) configdlg; | 930 | delete configdlg; |
915 | configdlg = 0; | 931 | configdlg = 0; |
916 | } | 932 | } |
917 | } | 933 | } |
918 | 934 | ||
935 | void Keyboard::reloadSw() { | ||
936 | QCopEnvelope e("MultiKey/Switcher", "setsw(QString,QString)"); | ||
937 | |||
938 | Config* config = new Config("multikey"); | ||
939 | config->setGroup("keymaps"); | ||
940 | QString current_map = config->readEntry("current", "en.keymap"); | ||
941 | delete config; | ||
942 | |||
943 | e << ConfigDlg::loadSw().join("|") << current_map; | ||
944 | } | ||
945 | |||
919 | /* Keyboard::setMapTo ... {{{1 */ | 946 | /* Keyboard::setMapTo ... {{{1 */ |
920 | void Keyboard::setMapToDefault() { | 947 | void Keyboard::setMapToDefault() { |
921 | 948 | ||
922 | 949 | ||
923 | /* load current locale language map */ | 950 | /* load current locale language map */ |
924 | Config *config = new Config("locale"); | 951 | Config *config = new Config("locale"); |
925 | config->setGroup( "Language" ); | 952 | config->setGroup( "Language" ); |
926 | QString l = config->readEntry( "Language" , "en" ); | 953 | QString l = config->readEntry( "Language" , "en" ); |
927 | delete config; | 954 | delete config; |
928 | 955 | ||
956 | /* if Language represents as en_US, ru_RU, etc... */ | ||
957 | int d = l.find('_'); | ||
958 | if (d != -1) { | ||
959 | l.remove(d, l.length()-d); | ||
960 | } | ||
929 | QString key_map = QPEApplication::qpeDir() + "share/multikey/" | 961 | QString key_map = QPEApplication::qpeDir() + "share/multikey/" |
930 | + l + ".keymap"; | 962 | + l + ".keymap"; |
931 | 963 | ||
932 | /* save change to multikey config file */ | 964 | /* save change to multikey config file */ |
933 | config = new Config("multikey"); | 965 | config = new Config("multikey"); |
934 | config->setGroup ("keymaps"); | 966 | config->setGroup ("keymaps"); |
935 | config->writeEntry ("current", key_map); // default closed | 967 | config->writeEntry ("current", key_map); // default closed |
936 | delete config; | 968 | delete config; |
937 | 969 | ||
938 | int prevRows = keys->rows(); | 970 | int prevRows = keys->rows(); |
939 | 971 | ||
940 | delete keys; | 972 | delete keys; |
941 | keys = new Keys(key_map); | 973 | keys = new Keys(key_map); |
942 | 974 | ||
943 | // have to repaint the keyboard | 975 | // have to repaint the keyboard |
944 | if (prevRows != keys->rows()) { | 976 | if (prevRows != keys->rows()) { |
@@ -1493,33 +1525,33 @@ void Keys::setKeysFromFile(const char * filename) { | |||
1493 | qDebug ("Estoy aadiendo %i con %i", lower, shift); | 1525 | qDebug ("Estoy aadiendo %i con %i", lower, shift); |
1494 | buf = t.readLine(); | 1526 | buf = t.readLine(); |
1495 | } | 1527 | } |
1496 | // accent | 1528 | // accent |
1497 | else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1529 | else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1498 | 1530 | ||
1499 | QTextStream tmp (buf, IO_ReadOnly); | 1531 | QTextStream tmp (buf, IO_ReadOnly); |
1500 | ushort lower, shift; | 1532 | ushort lower, shift; |
1501 | QChar d; | 1533 | QChar d; |
1502 | tmp >> d >> lower >> shift; | 1534 | tmp >> d >> lower >> shift; |
1503 | 1535 | ||
1504 | accentMap.insert(lower, shift); | 1536 | accentMap.insert(lower, shift); |
1505 | 1537 | ||
1506 | buf = t.readLine(); | 1538 | buf = t.readLine(); |
1507 | } | 1539 | } |
1508 | 1540 | ||
1509 | // other variables like lang & title | 1541 | // other variables like lang & title & sw |
1510 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { | 1542 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { |
1511 | 1543 | ||
1512 | QTextStream tmp (buf, IO_ReadOnly); | 1544 | QTextStream tmp (buf, IO_ReadOnly); |
1513 | QString name, equals, value; | 1545 | QString name, equals, value; |
1514 | 1546 | ||
1515 | tmp >> name >> equals >> value; | 1547 | tmp >> name >> equals >> value; |
1516 | 1548 | ||
1517 | if (name == "lang") { | 1549 | if (name == "lang") { |
1518 | 1550 | ||
1519 | lang = value; | 1551 | lang = value; |
1520 | 1552 | ||
1521 | } | 1553 | } |
1522 | 1554 | ||
1523 | buf = t.readLine(); | 1555 | buf = t.readLine(); |
1524 | } | 1556 | } |
1525 | // comments | 1557 | // comments |