author | hash <hash> | 2002-08-15 19:46:43 (UTC) |
---|---|---|
committer | hash <hash> | 2002-08-15 19:46:43 (UTC) |
commit | 3e328409c2829dff590d0087518938851aff8bcc (patch) (unidiff) | |
tree | 0a0f9fe70fdd78ffd00702b73782f41ffbc56cd7 | |
parent | d9cc9bedf72e921f8f7d8edeb189db127c5651e3 (diff) | |
download | opie-3e328409c2829dff590d0087518938851aff8bcc.zip opie-3e328409c2829dff590d0087518938851aff8bcc.tar.gz opie-3e328409c2829dff590d0087518938851aff8bcc.tar.bz2 |
think i fixed a memory leak problem... please test it out and see if the size of qpe increases if you load/unload keymaps
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 10 | ||||
-rw-r--r-- | inputmethods/multikey/keyboard.h | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index b71f929..671868c 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -636,436 +636,446 @@ ushort Keyboard::parseKoreanInput (ushort c) { | |||
636 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ | 636 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ |
637 | else { | 637 | else { |
638 | schar = c; mchar = 0; echar = 0; | 638 | schar = c; mchar = 0; echar = 0; |
639 | return c; | 639 | return c; |
640 | } | 640 | } |
641 | 641 | ||
642 | } else if (echar == 0x11ba) { // ¤µ | 642 | } else if (echar == 0x11ba) { // ¤µ |
643 | 643 | ||
644 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ | 644 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ |
645 | else { | 645 | else { |
646 | schar = c; mchar = 0; echar = 0; | 646 | schar = c; mchar = 0; echar = 0; |
647 | return c; | 647 | return c; |
648 | } | 648 | } |
649 | 649 | ||
650 | } else { // if any other char, cannot combine chars | 650 | } else { // if any other char, cannot combine chars |
651 | 651 | ||
652 | schar = c; mchar = 0; echar = 0; | 652 | schar = c; mchar = 0; echar = 0; |
653 | return c; | 653 | return c; |
654 | } | 654 | } |
655 | 655 | ||
656 | unicode = echar; | 656 | unicode = echar; |
657 | } | 657 | } |
658 | } | 658 | } |
659 | 659 | ||
660 | } | 660 | } |
661 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input | 661 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input |
662 | 662 | ||
663 | if (schar != 0 && mchar == 0) { mchar = c; } | 663 | if (schar != 0 && mchar == 0) { mchar = c; } |
664 | 664 | ||
665 | else if (schar != 0 && mchar != 0 && echar == 0) { | 665 | else if (schar != 0 && mchar != 0 && echar == 0) { |
666 | 666 | ||
667 | switch (mchar) { | 667 | switch (mchar) { |
668 | case 0x1169: | 668 | case 0x1169: |
669 | if (c == 0x1161) mchar = 0x116a; | 669 | if (c == 0x1161) mchar = 0x116a; |
670 | else if (c == 0x1162) mchar = 0x116b; | 670 | else if (c == 0x1162) mchar = 0x116b; |
671 | else if (c == 0x1175) mchar = 0x116c; | 671 | else if (c == 0x1175) mchar = 0x116c; |
672 | else { | 672 | else { |
673 | schar = 0; mchar = 0; echar = 0; | 673 | schar = 0; mchar = 0; echar = 0; |
674 | return c; | 674 | return c; |
675 | } | 675 | } |
676 | break; | 676 | break; |
677 | case 0x116e: | 677 | case 0x116e: |
678 | if (c == 0x1165) mchar = 0x116f; | 678 | if (c == 0x1165) mchar = 0x116f; |
679 | else if (c == 0x1166) mchar = 0x1170; | 679 | else if (c == 0x1166) mchar = 0x1170; |
680 | else if (c == 0x1175) mchar = 0x1171; | 680 | else if (c == 0x1175) mchar = 0x1171; |
681 | else { | 681 | else { |
682 | schar = 0; mchar = 0; echar = 0; | 682 | schar = 0; mchar = 0; echar = 0; |
683 | return c; | 683 | return c; |
684 | } | 684 | } |
685 | break; | 685 | break; |
686 | case 0x1173: | 686 | case 0x1173: |
687 | if (c == 0x1175) mchar = 0x1174; | 687 | if (c == 0x1175) mchar = 0x1174; |
688 | else { | 688 | else { |
689 | schar = 0; mchar = 0; echar = 0; | 689 | schar = 0; mchar = 0; echar = 0; |
690 | return c; | 690 | return c; |
691 | } | 691 | } |
692 | break; | 692 | break; |
693 | default: | 693 | default: |
694 | schar = 0; mchar = 0; echar = 0; | 694 | schar = 0; mchar = 0; echar = 0; |
695 | return c; | 695 | return c; |
696 | } | 696 | } |
697 | } | 697 | } |
698 | else if (schar != 0 && mchar != 0 && echar != 0) { | 698 | else if (schar != 0 && mchar != 0 && echar != 0) { |
699 | 699 | ||
700 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 700 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
701 | 701 | ||
702 | ushort prev = 0; | 702 | ushort prev = 0; |
703 | switch (echar) { | 703 | switch (echar) { |
704 | /* | 704 | /* |
705 | case 0x11a9: | 705 | case 0x11a9: |
706 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 706 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
707 | schar = 0x1100; | 707 | schar = 0x1100; |
708 | break; | 708 | break; |
709 | */ | 709 | */ |
710 | case 0x11aa: | 710 | case 0x11aa: |
711 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 711 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
712 | schar = 0x1109; | 712 | schar = 0x1109; |
713 | break; | 713 | break; |
714 | case 0x11ac: | 714 | case 0x11ac: |
715 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 715 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
716 | schar = 0x110c; | 716 | schar = 0x110c; |
717 | break; | 717 | break; |
718 | case 0x11ad: | 718 | case 0x11ad: |
719 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 719 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
720 | schar = 0x1112; | 720 | schar = 0x1112; |
721 | break; | 721 | break; |
722 | case 0x11b0: | 722 | case 0x11b0: |
723 | prev = combineKoreanChars(schar, mchar, 0x11af); | 723 | prev = combineKoreanChars(schar, mchar, 0x11af); |
724 | schar = 0x1100; | 724 | schar = 0x1100; |
725 | break; | 725 | break; |
726 | case 0x11b1: | 726 | case 0x11b1: |
727 | prev = combineKoreanChars(schar, mchar, 0x11af); | 727 | prev = combineKoreanChars(schar, mchar, 0x11af); |
728 | schar = 0x1106; | 728 | schar = 0x1106; |
729 | break; | 729 | break; |
730 | case 0x11b2: | 730 | case 0x11b2: |
731 | prev = combineKoreanChars(schar, mchar, 0x11af); | 731 | prev = combineKoreanChars(schar, mchar, 0x11af); |
732 | schar = 0x1107; | 732 | schar = 0x1107; |
733 | break; | 733 | break; |
734 | case 0x11b3: | 734 | case 0x11b3: |
735 | prev = combineKoreanChars(schar, mchar, 0x11af); | 735 | prev = combineKoreanChars(schar, mchar, 0x11af); |
736 | schar = 0x1109; | 736 | schar = 0x1109; |
737 | break; | 737 | break; |
738 | case 0x11b4: | 738 | case 0x11b4: |
739 | prev = combineKoreanChars(schar, mchar, 0x11af); | 739 | prev = combineKoreanChars(schar, mchar, 0x11af); |
740 | schar = 0x1110; | 740 | schar = 0x1110; |
741 | break; | 741 | break; |
742 | case 0x11b9: | 742 | case 0x11b9: |
743 | prev = combineKoreanChars(schar, mchar, 0x11b8); | 743 | prev = combineKoreanChars(schar, mchar, 0x11b8); |
744 | schar = 0x1109; | 744 | schar = 0x1109; |
745 | break; | 745 | break; |
746 | /* | 746 | /* |
747 | case 0x11bb: | 747 | case 0x11bb: |
748 | prev = combineKoreanChars(schar, mchar, 0x11ba); | 748 | prev = combineKoreanChars(schar, mchar, 0x11ba); |
749 | schar = 0x1109; | 749 | schar = 0x1109; |
750 | break; | 750 | break; |
751 | */ | 751 | */ |
752 | default: | 752 | default: |
753 | 753 | ||
754 | if (constoe(echar)) { | 754 | if (constoe(echar)) { |
755 | 755 | ||
756 | prev = combineKoreanChars(schar, mchar, 0); | 756 | prev = combineKoreanChars(schar, mchar, 0); |
757 | schar = constoe(echar); | 757 | schar = constoe(echar); |
758 | } | 758 | } |
759 | break; | 759 | break; |
760 | } | 760 | } |
761 | 761 | ||
762 | emit key( prev, prev, 0, true, false ); | 762 | emit key( prev, prev, 0, true, false ); |
763 | 763 | ||
764 | mchar = c; echar = 0; | 764 | mchar = c; echar = 0; |
765 | 765 | ||
766 | return combineKoreanChars(schar, mchar, 0); | 766 | return combineKoreanChars(schar, mchar, 0); |
767 | 767 | ||
768 | } | 768 | } |
769 | else { | 769 | else { |
770 | schar = 0; mchar = 0; echar = 0; | 770 | schar = 0; mchar = 0; echar = 0; |
771 | return c; | 771 | return c; |
772 | } | 772 | } |
773 | 773 | ||
774 | } | 774 | } |
775 | else /*if (c == ' ')*/ return c; | 775 | else /*if (c == ' ')*/ return c; |
776 | 776 | ||
777 | 777 | ||
778 | // and now... finally delete previous char, and return new char | 778 | // and now... finally delete previous char, and return new char |
779 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 779 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
780 | 780 | ||
781 | 781 | ||
782 | return combineKoreanChars( schar, mchar, echar); | 782 | return combineKoreanChars( schar, mchar, echar); |
783 | 783 | ||
784 | } | 784 | } |
785 | 785 | ||
786 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { | 786 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { |
787 | 787 | ||
788 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; | 788 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; |
789 | 789 | ||
790 | } | 790 | } |
791 | 791 | ||
792 | ushort Keyboard::constoe(const ushort c) { | 792 | ushort Keyboard::constoe(const ushort c) { |
793 | 793 | ||
794 | // converts schars to echars if possible | 794 | // converts schars to echars if possible |
795 | 795 | ||
796 | if (0x1100 <= c && c <= 0x1112) { // schar to echar | 796 | if (0x1100 <= c && c <= 0x1112) { // schar to echar |
797 | 797 | ||
798 | switch (c) { | 798 | switch (c) { |
799 | case 0x1100: return 0x11a8; | 799 | case 0x1100: return 0x11a8; |
800 | case 0x1101: return 0x11a9; | 800 | case 0x1101: return 0x11a9; |
801 | case 0x1102: return 0x11ab; | 801 | case 0x1102: return 0x11ab; |
802 | case 0x1103: return 0x11ae; | 802 | case 0x1103: return 0x11ae; |
803 | case 0x1105: return 0x11af; | 803 | case 0x1105: return 0x11af; |
804 | case 0x1106: return 0x11b7; | 804 | case 0x1106: return 0x11b7; |
805 | case 0x1107: return 0x11b8; | 805 | case 0x1107: return 0x11b8; |
806 | case 0x1109: return 0x11ba; | 806 | case 0x1109: return 0x11ba; |
807 | case 0x110a: return 0x11bb; | 807 | case 0x110a: return 0x11bb; |
808 | case 0x110b: return 0x11bc; | 808 | case 0x110b: return 0x11bc; |
809 | case 0x110c: return 0x11bd; | 809 | case 0x110c: return 0x11bd; |
810 | case 0x110e: return 0x11be; | 810 | case 0x110e: return 0x11be; |
811 | case 0x110f: return 0x11bf; | 811 | case 0x110f: return 0x11bf; |
812 | case 0x1110: return 0x11c0; | 812 | case 0x1110: return 0x11c0; |
813 | case 0x1111: return 0x11c1; | 813 | case 0x1111: return 0x11c1; |
814 | case 0x1112: return 0x11c2; | 814 | case 0x1112: return 0x11c2; |
815 | default: return 0; | 815 | default: return 0; |
816 | 816 | ||
817 | } | 817 | } |
818 | 818 | ||
819 | } else { //echar to schar | 819 | } else { //echar to schar |
820 | 820 | ||
821 | switch (c) { | 821 | switch (c) { |
822 | case 0x11a8: return 0x1100; | 822 | case 0x11a8: return 0x1100; |
823 | case 0x11a9: return 0x1101; | 823 | case 0x11a9: return 0x1101; |
824 | case 0x11ab: return 0x1102; | 824 | case 0x11ab: return 0x1102; |
825 | case 0x11ae: return 0x1103; | 825 | case 0x11ae: return 0x1103; |
826 | case 0x11af: return 0x1105; | 826 | case 0x11af: return 0x1105; |
827 | case 0x11b7: return 0x1106; | 827 | case 0x11b7: return 0x1106; |
828 | case 0x11b8: return 0x1107; | 828 | case 0x11b8: return 0x1107; |
829 | case 0x11ba: return 0x1109; | 829 | case 0x11ba: return 0x1109; |
830 | case 0x11bb: return 0x110a; | 830 | case 0x11bb: return 0x110a; |
831 | case 0x11bc: return 0x110b; | 831 | case 0x11bc: return 0x110b; |
832 | case 0x11bd: return 0x110c; | 832 | case 0x11bd: return 0x110c; |
833 | case 0x11be: return 0x110e; | 833 | case 0x11be: return 0x110e; |
834 | case 0x11bf: return 0x110f; | 834 | case 0x11bf: return 0x110f; |
835 | case 0x11c0: return 0x1110; | 835 | case 0x11c0: return 0x1110; |
836 | case 0x11c1: return 0x1111; | 836 | case 0x11c1: return 0x1111; |
837 | case 0x11c2: return 0x1112; | 837 | case 0x11c2: return 0x1112; |
838 | default: return 0; | 838 | default: return 0; |
839 | 839 | ||
840 | } | 840 | } |
841 | 841 | ||
842 | } | 842 | } |
843 | } | 843 | } |
844 | 844 | ||
845 | 845 | ||
846 | // Keys::Keys {{{1 | 846 | // Keys::Keys {{{1 |
847 | 847 | ||
848 | Keys::Keys() { | 848 | Keys::Keys() { |
849 | 849 | ||
850 | Config *config = new Config ("multikey"); | 850 | Config *config = new Config ("multikey"); |
851 | config->setGroup( "keymaps" ); | 851 | config->setGroup( "keymaps" ); |
852 | QString key_map = config->readEntry( "current" ); | 852 | QString key_map = config->readEntry( "current" ); |
853 | delete config; | 853 | delete config; |
854 | 854 | ||
855 | if (key_map.isNull()) { | 855 | if (key_map.isNull()) { |
856 | 856 | ||
857 | Config *config = new Config("locale"); | 857 | Config *config = new Config("locale"); |
858 | config->setGroup( "Language" ); | 858 | config->setGroup( "Language" ); |
859 | QString l = config->readEntry( "Language" , "en" ); | 859 | QString l = config->readEntry( "Language" , "en" ); |
860 | delete config; | 860 | delete config; |
861 | 861 | ||
862 | key_map = QPEApplication::qpeDir() + "/share/multikey/" | 862 | key_map = QPEApplication::qpeDir() + "/share/multikey/" |
863 | + l + ".keymap"; | 863 | + l + ".keymap"; |
864 | 864 | ||
865 | } | 865 | } |
866 | 866 | ||
867 | 867 | ||
868 | setKeysFromFile(key_map); | 868 | setKeysFromFile(key_map); |
869 | } | 869 | } |
870 | 870 | ||
871 | Keys::Keys(const char * filename) { | 871 | Keys::Keys(const char * filename) { |
872 | 872 | ||
873 | setKeysFromFile(filename); | 873 | setKeysFromFile(filename); |
874 | } | 874 | } |
875 | 875 | ||
876 | // Keys::setKeysFromFile {{{2 | 876 | // Keys::setKeysFromFile {{{2 |
877 | void Keys::setKeysFromFile(const char * filename) { | 877 | void Keys::setKeysFromFile(const char * filename) { |
878 | 878 | ||
879 | QFile f(filename); | 879 | QFile f(filename); |
880 | 880 | ||
881 | if (f.open(IO_ReadOnly)) { | 881 | if (f.open(IO_ReadOnly)) { |
882 | 882 | ||
883 | QTextStream t(&f); | 883 | QTextStream t(&f); |
884 | int row; | 884 | int row; |
885 | int qcode; | 885 | int qcode; |
886 | ushort unicode; | 886 | ushort unicode; |
887 | int width; | 887 | int width; |
888 | QString buf; | 888 | QString buf; |
889 | QString comment; | 889 | QString comment; |
890 | char * xpm[256]; //couldnt be larger than that... could it? | 890 | char * xpm[256]; //couldnt be larger than that... could it? |
891 | QPixmap *xpm2pix = 0; | 891 | QPixmap *xpm2pix = 0; |
892 | 892 | ||
893 | buf = t.readLine(); | 893 | buf = t.readLine(); |
894 | while (buf) { | 894 | while (buf) { |
895 | 895 | ||
896 | // key definition | 896 | // key definition |
897 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { | 897 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { |
898 | // no $1 type referencing!!! this implementation of regexp sucks | 898 | // no $1 type referencing!!! this implementation of regexp sucks |
899 | 899 | ||
900 | // dont know of any sscanf() type funcs in Qt lib | 900 | // dont know of any sscanf() type funcs in Qt lib |
901 | QTextStream tmp (buf, IO_ReadOnly); | 901 | QTextStream tmp (buf, IO_ReadOnly); |
902 | tmp >> row >> qcode >> unicode >> width >> comment; | 902 | tmp >> row >> qcode >> unicode >> width >> comment; |
903 | 903 | ||
904 | buf = t.readLine(); | 904 | buf = t.readLine(); |
905 | int xpmLineCount = 0; | 905 | int xpmLineCount = 0; |
906 | xpm2pix = 0; | 906 | xpm2pix = 0; |
907 | 907 | ||
908 | // erase blank space | 908 | // erase blank space |
909 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); | 909 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); |
910 | 910 | ||
911 | while (buf.contains(QRegExp("^\\s*\".*\""))) { | 911 | while (buf.contains(QRegExp("^\\s*\".*\""))) { |
912 | 912 | ||
913 | QString xpmBuf = buf.stripWhiteSpace(); | 913 | QString xpmBuf = buf.stripWhiteSpace(); |
914 | 914 | ||
915 | xpm[xpmLineCount] = new char [xpmBuf.length()]; | 915 | xpm[xpmLineCount] = new char [xpmBuf.length()]; |
916 | 916 | ||
917 | int j = 0; | 917 | int j = 0; |
918 | for (ushort i = 0; i < xpmBuf.length(); i++) { | 918 | for (ushort i = 0; i < xpmBuf.length(); i++) { |
919 | if (xpmBuf[i].latin1() != '"') { | 919 | if (xpmBuf[i].latin1() != '"') { |
920 | 920 | ||
921 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); | 921 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); |
922 | j++; | 922 | j++; |
923 | } | 923 | } |
924 | 924 | ||
925 | } | 925 | } |
926 | // have to close that facker up | 926 | // have to close that facker up |
927 | ((char *)xpm[xpmLineCount])[j] = '\0'; | 927 | ((char *)xpm[xpmLineCount])[j] = '\0'; |
928 | 928 | ||
929 | xpmLineCount++; | 929 | xpmLineCount++; |
930 | buf = t.readLine(); | 930 | buf = t.readLine(); |
931 | } | 931 | } |
932 | if (xpmLineCount) { | 932 | if (xpmLineCount) { |
933 | 933 | ||
934 | xpm2pix = new QPixmap((const char **)xpm); | 934 | xpm2pix = new QPixmap((const char **)xpm); |
935 | for (int i = 0; i < xpmLineCount; i++) | 935 | for (int i = 0; i < xpmLineCount; i++) |
936 | 936 | ||
937 | delete [] (xpm[i]); | 937 | delete [] (xpm[i]); |
938 | 938 | ||
939 | } | 939 | } |
940 | setKey(row, qcode, unicode, width, xpm2pix); | 940 | setKey(row, qcode, unicode, width, xpm2pix); |
941 | } | 941 | } |
942 | 942 | ||
943 | // shift map | 943 | // shift map |
944 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 944 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
945 | 945 | ||
946 | QTextStream tmp (buf, IO_ReadOnly); | 946 | QTextStream tmp (buf, IO_ReadOnly); |
947 | ushort lower, shift; | 947 | ushort lower, shift; |
948 | tmp >> lower >> shift; | 948 | tmp >> lower >> shift; |
949 | 949 | ||
950 | shiftMap.insert(lower, shift); | 950 | shiftMap.insert(lower, shift); |
951 | 951 | ||
952 | buf = t.readLine(); | 952 | buf = t.readLine(); |
953 | } | 953 | } |
954 | 954 | ||
955 | // other variables like lang & title | 955 | // other variables like lang & title |
956 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { | 956 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { |
957 | 957 | ||
958 | QTextStream tmp (buf, IO_ReadOnly); | 958 | QTextStream tmp (buf, IO_ReadOnly); |
959 | QString name, equals, value; | 959 | QString name, equals, value; |
960 | 960 | ||
961 | tmp >> name >> equals >> value; | 961 | tmp >> name >> equals >> value; |
962 | 962 | ||
963 | if (name == "lang") { | 963 | if (name == "lang") { |
964 | 964 | ||
965 | lang = value; | 965 | lang = value; |
966 | 966 | ||
967 | } | 967 | } |
968 | 968 | ||
969 | buf = t.readLine(); | 969 | buf = t.readLine(); |
970 | } | 970 | } |
971 | // comments | 971 | // comments |
972 | else if (buf.contains(QRegExp("^\\s*#"))) { | 972 | else if (buf.contains(QRegExp("^\\s*#"))) { |
973 | 973 | ||
974 | buf = t.readLine(); | 974 | buf = t.readLine(); |
975 | 975 | ||
976 | } else { // blank line, or garbage | 976 | } else { // blank line, or garbage |
977 | 977 | ||
978 | buf = t.readLine(); | 978 | buf = t.readLine(); |
979 | 979 | ||
980 | } | 980 | } |
981 | 981 | ||
982 | } | 982 | } |
983 | f.close(); | 983 | f.close(); |
984 | } | 984 | } |
985 | 985 | ||
986 | } | 986 | } |
987 | 987 | ||
988 | // Keys::setKey {{{2 | 988 | // Keys::setKey {{{2 |
989 | void Keys::setKey(const int row, const int qcode, const ushort unicode, | 989 | void Keys::setKey(const int row, const int qcode, const ushort unicode, |
990 | const int width, QPixmap *pix) { | 990 | const int width, QPixmap *pix) { |
991 | 991 | ||
992 | Key * key; | 992 | Key * key; |
993 | key = new Key; | 993 | key = new Key; |
994 | key->qcode = qcode; | 994 | key->qcode = qcode; |
995 | key->unicode = unicode; | 995 | key->unicode = unicode; |
996 | key->width = width; | 996 | key->width = width; |
997 | 997 | ||
998 | // share key->pressed between same keys | 998 | // share key->pressed between same keys |
999 | bool found = 0; | 999 | bool found = 0; |
1000 | for (int i = 1; i <= 5; i++) { | 1000 | for (int i = 1; i <= 5; i++) { |
1001 | for (unsigned int j = 0; j < keys[i].count(); j++) | 1001 | for (unsigned int j = 0; j < keys[i].count(); j++) |
1002 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { | 1002 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { |
1003 | 1003 | ||
1004 | key->pressed = keys[i].at(j)->pressed; | 1004 | key->pressed = keys[i].at(j)->pressed; |
1005 | found = 1; | 1005 | found = 1; |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | } | 1008 | } |
1009 | if (!found) { | 1009 | if (!found) { |
1010 | 1010 | ||
1011 | key->pressed = new bool; | 1011 | key->pressed = new bool; |
1012 | *(key->pressed) = 0; | 1012 | *(key->pressed) = 0; |
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | key->pix = pix; | 1015 | key->pix = pix; |
1016 | 1016 | ||
1017 | 1017 | ||
1018 | keys[row].append(key); | 1018 | keys[row].append(key); |
1019 | } | 1019 | } |
1020 | |||
1021 | // Keys::~Keys {{{2 | ||
1022 | Keys::~Keys() { | ||
1023 | |||
1024 | for (int i = 1; i <= 5; i++) | ||
1025 | for (unsigned int j = 0; j < keys[i].count(); j++) | ||
1026 | delete keys[i].at(j); | ||
1027 | |||
1028 | } | ||
1029 | |||
1020 | // Keys:: other functions {{{2 | 1030 | // Keys:: other functions {{{2 |
1021 | int Keys::width(const int row, const int col) { | 1031 | int Keys::width(const int row, const int col) { |
1022 | 1032 | ||
1023 | return keys[row].at(col)->width; | 1033 | return keys[row].at(col)->width; |
1024 | 1034 | ||
1025 | } | 1035 | } |
1026 | ushort Keys::uni(const int row, const int col) { | 1036 | ushort Keys::uni(const int row, const int col) { |
1027 | 1037 | ||
1028 | return keys[row].at(col)->unicode; | 1038 | return keys[row].at(col)->unicode; |
1029 | 1039 | ||
1030 | } | 1040 | } |
1031 | 1041 | ||
1032 | int Keys::qcode(const int row, const int col) { | 1042 | int Keys::qcode(const int row, const int col) { |
1033 | 1043 | ||
1034 | return keys[row].at(col)->qcode; | 1044 | return keys[row].at(col)->qcode; |
1035 | } | 1045 | } |
1036 | 1046 | ||
1037 | QPixmap *Keys::pix(const int row, const int col) { | 1047 | QPixmap *Keys::pix(const int row, const int col) { |
1038 | 1048 | ||
1039 | return keys[row].at(col)->pix; | 1049 | return keys[row].at(col)->pix; |
1040 | 1050 | ||
1041 | } | 1051 | } |
1042 | bool Keys::pressed(const int row, const int col) { | 1052 | bool Keys::pressed(const int row, const int col) { |
1043 | 1053 | ||
1044 | return *(keys[row].at(col)->pressed); | 1054 | return *(keys[row].at(col)->pressed); |
1045 | } | 1055 | } |
1046 | 1056 | ||
1047 | int Keys::numKeys(const int row) { | 1057 | int Keys::numKeys(const int row) { |
1048 | 1058 | ||
1049 | return keys[row].count(); | 1059 | return keys[row].count(); |
1050 | } | 1060 | } |
1051 | 1061 | ||
1052 | void Keys::setPressed(const int row, const int col, const bool pressed) { | 1062 | void Keys::setPressed(const int row, const int col, const bool pressed) { |
1053 | 1063 | ||
1054 | *(keys[row].at(col)->pressed) = pressed; | 1064 | *(keys[row].at(col)->pressed) = pressed; |
1055 | } | 1065 | } |
1056 | 1066 | ||
1057 | ushort Keys::shift(const ushort uni) { | 1067 | ushort Keys::shift(const ushort uni) { |
1058 | 1068 | ||
1059 | if (shiftMap[uni]) { | 1069 | if (shiftMap[uni]) { |
1060 | 1070 | ||
1061 | return shiftMap[uni]; | 1071 | return shiftMap[uni]; |
1062 | } | 1072 | } |
1063 | else | 1073 | else |
1064 | return 0; | 1074 | return 0; |
1065 | 1075 | ||
1066 | } | 1076 | } |
1067 | 1077 | ||
1068 | bool *Keys::pressedPtr(const int row, const int col) { | 1078 | bool *Keys::pressedPtr(const int row, const int col) { |
1069 | 1079 | ||
1070 | return keys[row].at(col)->pressed; | 1080 | return keys[row].at(col)->pressed; |
1071 | } | 1081 | } |
diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h index 8ca50ea..400edc0 100644 --- a/inputmethods/multikey/keyboard.h +++ b/inputmethods/multikey/keyboard.h | |||
@@ -1,157 +1,158 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qframe.h> | 20 | #include <qframe.h> |
21 | #include <qmap.h> | 21 | #include <qmap.h> |
22 | #include "../pickboard/pickboardcfg.h" | 22 | #include "../pickboard/pickboardcfg.h" |
23 | #include "../pickboard/pickboardpicks.h" | 23 | #include "../pickboard/pickboardpicks.h" |
24 | #include "configdlg.h" | 24 | #include "configdlg.h" |
25 | 25 | ||
26 | class QTimer; | 26 | class QTimer; |
27 | 27 | ||
28 | class KeyboardConfig : public DictFilterConfig | 28 | class KeyboardConfig : public DictFilterConfig |
29 | { | 29 | { |
30 | public: | 30 | public: |
31 | KeyboardConfig(PickboardPicks* p) : DictFilterConfig(p), backspaces(0) { nrows = 1; } | 31 | KeyboardConfig(PickboardPicks* p) : DictFilterConfig(p), backspaces(0) { nrows = 1; } |
32 | virtual void generateText(const QString &s); | 32 | virtual void generateText(const QString &s); |
33 | void decBackspaces() { if (backspaces) backspaces--; } | 33 | void decBackspaces() { if (backspaces) backspaces--; } |
34 | void incBackspaces() { backspaces++; } | 34 | void incBackspaces() { backspaces++; } |
35 | void resetBackspaces() { backspaces = 0; } | 35 | void resetBackspaces() { backspaces = 0; } |
36 | private: | 36 | private: |
37 | int backspaces; | 37 | int backspaces; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | 40 | ||
41 | class KeyboardPicks : public PickboardPicks | 41 | class KeyboardPicks : public PickboardPicks |
42 | { | 42 | { |
43 | Q_OBJECT | 43 | Q_OBJECT |
44 | public: | 44 | public: |
45 | KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0) | 45 | KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0) |
46 | : PickboardPicks(parent, name, f) { } | 46 | : PickboardPicks(parent, name, f) { } |
47 | void initialise(); | 47 | void initialise(); |
48 | virtual QSize sizeHint() const; | 48 | virtual QSize sizeHint() const; |
49 | KeyboardConfig *dc; | 49 | KeyboardConfig *dc; |
50 | }; | 50 | }; |
51 | 51 | ||
52 | 52 | ||
53 | class Keys { | 53 | class Keys { |
54 | public: | 54 | public: |
55 | 55 | ||
56 | Keys(); | 56 | Keys(); |
57 | Keys(const char * filename); | 57 | Keys(const char * filename); |
58 | ~Keys(); | ||
58 | ushort uni(const int row, const int col); | 59 | ushort uni(const int row, const int col); |
59 | int qcode(const int row, const int col); | 60 | int qcode(const int row, const int col); |
60 | int width(const int row, const int col); | 61 | int width(const int row, const int col); |
61 | bool pressed(const int row, const int col); | 62 | bool pressed(const int row, const int col); |
62 | bool *pressedPtr(const int row, const int col); | 63 | bool *pressedPtr(const int row, const int col); |
63 | ushort shift(const ushort); | 64 | ushort shift(const ushort); |
64 | QPixmap *pix(const int row, const int col); | 65 | QPixmap *pix(const int row, const int col); |
65 | int numKeys(const int row); | 66 | int numKeys(const int row); |
66 | void setKeysFromFile(const char *filename); | 67 | void setKeysFromFile(const char *filename); |
67 | void setKey(const int row, const int qcode, const ushort unicode, | 68 | void setKey(const int row, const int qcode, const ushort unicode, |
68 | const int width, QPixmap *pix); | 69 | const int width, QPixmap *pix); |
69 | void setPressed(const int row, const int col, const bool pressed); | 70 | void setPressed(const int row, const int col, const bool pressed); |
70 | QString lang; | 71 | QString lang; |
71 | QString title; | 72 | QString title; |
72 | 73 | ||
73 | private: | 74 | private: |
74 | 75 | ||
75 | typedef struct Key { | 76 | typedef struct Key { |
76 | int qcode; // are qt key codes just unicode values? | 77 | int qcode; // are qt key codes just unicode values? |
77 | ushort unicode; | 78 | ushort unicode; |
78 | int width; // not pixels but relative key width. normal key is 2 | 79 | int width; // not pixels but relative key width. normal key is 2 |
79 | 80 | ||
80 | // only needed for keys like ctrl that can have multiple keys pressed at once | 81 | // only needed for keys like ctrl that can have multiple keys pressed at once |
81 | bool *pressed; | 82 | bool *pressed; |
82 | QPixmap *pix; | 83 | QPixmap *pix; |
83 | }; | 84 | }; |
84 | 85 | ||
85 | QList<Key> keys[6]; | 86 | QList<Key> keys[6]; |
86 | QMap<ushort,ushort> shiftMap; | 87 | QMap<ushort,ushort> shiftMap; |
87 | 88 | ||
88 | }; | 89 | }; |
89 | 90 | ||
90 | class Keyboard : public QFrame | 91 | class Keyboard : public QFrame |
91 | { | 92 | { |
92 | Q_OBJECT | 93 | Q_OBJECT |
93 | public: | 94 | public: |
94 | Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 ); | 95 | Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 ); |
95 | ~Keyboard(); | 96 | ~Keyboard(); |
96 | 97 | ||
97 | void resetState(); | 98 | void resetState(); |
98 | 99 | ||
99 | void mousePressEvent(QMouseEvent*); | 100 | void mousePressEvent(QMouseEvent*); |
100 | void mouseReleaseEvent(QMouseEvent*); | 101 | void mouseReleaseEvent(QMouseEvent*); |
101 | void resizeEvent(QResizeEvent*); | 102 | void resizeEvent(QResizeEvent*); |
102 | void paintEvent(QPaintEvent* e); | 103 | void paintEvent(QPaintEvent* e); |
103 | //void timerEvent(QTimerEvent* e); | 104 | //void timerEvent(QTimerEvent* e); |
104 | void drawKeyboard( QPainter &p, int row = -1, int col = -1); | 105 | void drawKeyboard( QPainter &p, int row = -1, int col = -1); |
105 | 106 | ||
106 | QSize sizeHint() const; | 107 | QSize sizeHint() const; |
107 | 108 | ||
108 | signals: | 109 | signals: |
109 | void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool ); | 110 | void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool ); |
110 | 111 | ||
111 | private slots: | 112 | private slots: |
112 | void repeat(); | 113 | void repeat(); |
113 | void togglePickboard(bool on_off); | 114 | void togglePickboard(bool on_off); |
114 | void setMapToDefault(); | 115 | void setMapToDefault(); |
115 | void setMapToFile(QString file); | 116 | void setMapToFile(QString file); |
116 | 117 | ||
117 | private: | 118 | private: |
118 | int getKey( int &w, int j = -1 ); | 119 | int getKey( int &w, int j = -1 ); |
119 | void clearHighlight(); | 120 | void clearHighlight(); |
120 | 121 | ||
121 | bool *shift; | 122 | bool *shift; |
122 | bool *lock; | 123 | bool *lock; |
123 | bool *ctrl; | 124 | bool *ctrl; |
124 | bool *alt; | 125 | bool *alt; |
125 | uint useLargeKeys:1; | 126 | uint useLargeKeys:1; |
126 | uint usePicks:1; | 127 | uint usePicks:1; |
127 | 128 | ||
128 | int pressedKeyRow; | 129 | int pressedKeyRow; |
129 | int pressedKeyCol; | 130 | int pressedKeyCol; |
130 | 131 | ||
131 | KeyboardPicks *picks; | 132 | KeyboardPicks *picks; |
132 | 133 | ||
133 | int keyHeight; | 134 | int keyHeight; |
134 | int defaultKeyWidth; | 135 | int defaultKeyWidth; |
135 | int xoffs; | 136 | int xoffs; |
136 | 137 | ||
137 | int unicode; | 138 | int unicode; |
138 | int qkeycode; | 139 | int qkeycode; |
139 | int modifiers; | 140 | int modifiers; |
140 | 141 | ||
141 | int pressTid; | 142 | int pressTid; |
142 | bool pressed; | 143 | bool pressed; |
143 | 144 | ||
144 | Keys *keys; | 145 | Keys *keys; |
145 | 146 | ||
146 | /* for korean input */ | 147 | /* for korean input */ |
147 | ushort schar, mchar, echar; | 148 | ushort schar, mchar, echar; |
148 | ushort parseKoreanInput(ushort c); | 149 | ushort parseKoreanInput(ushort c); |
149 | ushort combineKoreanChars(const ushort s, const ushort m, const ushort e); | 150 | ushort combineKoreanChars(const ushort s, const ushort m, const ushort e); |
150 | ushort constoe(const ushort c); | 151 | ushort constoe(const ushort c); |
151 | 152 | ||
152 | QTimer *repeatTimer; | 153 | QTimer *repeatTimer; |
153 | 154 | ||
154 | ConfigDlg *configdlg; | 155 | ConfigDlg *configdlg; |
155 | }; | 156 | }; |
156 | 157 | ||
157 | 158 | ||