Qt to write a Chinese-language double-spell input method for skin-changing

Source: Internet
Author: User

Time passes really fast, imperceptible already to 2015, the Lunar New Year is passed in the blink of an hour, correct state to pack up the mood to start.

There was a time, I have a very persistent dream, I want to director out a huge curtain of the unprecedented. But the reality mercilessly crushed my dream, but also pushed me to the bottom of life.

I began to think, a lot of ideas I used to avoid the problem, in a time of thinking, I can feel I am going to a strange place, the future is just dark can not speculate, I found that I bet, the bet is a lifetime of remorse or life.

But when I see the sun in my side, only to find that I was so naïve, I always find excuses or not excuse the excuse to shirk the responsibility of the born, in the bizarre reality find a secluded place to hope that the clouds light wind lighter days. I am wrong, I have enough ability but dare not wanton, I have amazing talent but fear this is just nankeyimeng, or this is a dream, wake up is no trace and endless attachment.

Once upon a time a classmate asked me if I had imagined some special experiences that would befall me, and I laughed but didn't know what to say.

I think I am contradictory, I think my existence is related to everything in the world, but I can not find enough evidence to prove that I have the identity of the Savior. So I once doubted whether I was a untimely or a jealous genius.

I am in the reincarnation of waiting for a chance, perhaps a troubled times, perhaps the peace, I do not have the so-called skills, only domineering pride and tide wash tide roll of the bosom. Only laugh's aloof and drew way. I think I should not belittle myself, even if it is a matter of course not to add the slightest modification of the natural.

I like this sentence: if I will mediocre life, the earth will stop turning, the earth stopped turning it? No, then I will not mediocre life.

At a particular time, in a particular environment, in a particular place, there is a particular person who will dominate everything! I will be useful when I am born! The classic tacit, but unfortunately his arrogance but not enough ability to do the base pad.

I think I am right, doomed is forever can not change, the past is just a hasty glimpse, the future is just fleeting, again and again reincarnation in exchange for the numbness of the rules, so the world needs a person----change.

Split Line-----------------------------------------------------------------------

High school and university like literature, especially during the university, in any information to fill in the interests of personal data in the column filled with literature and programming, which is like my left hand and right hand, indispensable.

Ok, so to speak, to say Qt write a skin-changing Chinese pinyin input method. On arm, if using QT development application, basically will encounter a problem, need to input Chinese characters in the application, this is more troublesome, even if the physical keyboard, can only enter letters and numbers, to Chinese helpless, for this need to use QT to achieve one.

Baidu A search, there are many predecessors have written similar input method, but basically are used qwsinputmethod related mechanisms, I think this is a bit inappropriate, most of the interface is ugly, only support a single Chinese character input, and basically does not support the physical keyboard and virtual keyboard synchronization input.

Run:











Characteristics:

1: Each QT version (qt4.6-qt5.4), the operating system (Windows, Linux, embedded linux-arm) all compiled run through, the interface is consistent.

2: Support lowercase, uppercase, Chinese three modes of input, free to switch.

3: Support single and double phrase input, most of the web only support a single Chinese character input.

4: Intelligent Paging algorithm, you can turn the page to view the Chinese character phrase.

5: In addition to support mouse click Soft Keyboard input, but also support the physical keyboard synchronization input, the code is mapped processing, the corresponding entity keyboard keys will react to the soft keyboard processing.

6: Seven sets of exquisite skin style selection, the right mouse button any skin change.

7: Code optimization to the extreme, including comments and all the integrity of the code processing in a total of less than 500 lines.

8: In addition to clicking on the soft keyboard and the number on the physical keyboard to select the corresponding Chinese characters, but also support the mouse click on the Chinese character display to select Chinese characters.

9: No border form, drag to move.

The 10:sqlite database stores Chinese character fonts, and can freely add custom phrases.

11: Refer to the physical keyboard layout, more realistic.

12: interface layout, font algorithm, interface switch 100% first processing, and any online QT Input method processing and layout is very different.

Core approach:

1: Gets the current focus control.

QT encapsulated a focuschanged signal, providing two parameters qwidget *oldwidget, Qwidget *nowwidget, so that the processing of input methods has brought great convenience.

Bind global Change focus signal slot connect (Qapp, SIGNAL (focuschanged (Qwidget *, Qwidget *)), this            , slot (focuschanged (Qwidget *, Qwidget *)); void Frminput::focuschanged (Qwidget *oldwidget, Qwidget *nowwidget) {    //qdebug () << "Oldwidget:" < < Oldwidget << "Nowwidget:" << nowwidget;    if (nowwidget! = 0 &&!this->isancestorof (nowwidget)) {        if (nowwidget->inherits ("Qlineedit")) {            Currentlineedit = (Qlineedit *) Nowwidget;            This->setvisible (True);        } else {            Currentlineedit = 0;            This->setvisible (false);            The input method needs to be switched to the original initial state-lowercase            currenttype= "min";            ChangeType (Currenttype);}}}    

2: Three mode toggle in lowercase, uppercase, and Chinese.

void Frminput::changetype (QString type) {if (type = = "Max") {Changeletter (true);        Ui->btntype->settext ("uppercase");        Ui->widgettop->setvisible (FALSE);    This->setgeometry (This->geometry (). x (), This->geometry (). Y (), 550, 160);        } else if (type = = "Min") {Changeletter (false);        Ui->btntype->settext ("lowercase");        Ui->widgettop->setvisible (FALSE);    This->setgeometry (This->geometry (). x (), This->geometry (). Y (), 550, 160);        } else {Changeletter (false);        Ui->btntype->settext ("Chinese");        Ui->widgettop->setvisible (TRUE);        This->setgeometry (This->geometry (). x (), This->geometry (). Y (), 550, 215);        Each time you switch to the Chinese display, the information Clearchinese () is executed before the Chinese mode is emptied.    Ui->labpy->settext (""); }}void Frminput::changeletter (bool isupper) {Qlist<qpushbutton *> btn = This->findchildren<qpushbutton *&G    t; (); foreach (Qpushbutton * b, BTN) {if (b->Property ("Btnletter"). Tobool ()) {if (isupper) {B->settext (B->text (). ToUpper ());            } else {B->settext (B->text (). ToLower ()); }        }    }}

3: Soft Keyboard button click event Handling.

void frminput::btn_clicked () {Qpushbutton *btn = (Qpushbutton *) sender ();    QString objectName = Btn->objectname ();        if (ObjectName = = "Btntype") {if (Currenttype = = "Min") {currenttype = "max";        } else if (Currenttype = = "Max") {Currenttype = "Chinese";        } else if (Currenttype = = "Chinese") {currenttype = "min";    } changetype (Currenttype);        } else if (ObjectName = = "Btndelete" | | objectName = = "Btndeletemin") {//If the current Chinese mode, then delete the corresponding pinyin, delete the pinyin after the text input box to delete the contents of the corresponding            if (Currenttype = = "Chinese") {QString txt = ui->labpy->text ();            int len = Txt.length ();                if (Len > 0) {ui->labpy->settext (Txt.left (len-1));            Selectchinese ();                } else {if (Currentlineedit! = 0) {currentlineedit->backspace ();            }}} and else {if (Currentlineedit! = 0) {    Currentlineedit->backspace ();  }}} and Else if (ObjectName = = "Btnpre") {if (Currentpy_index >=) {if (currentpy_index%            = = 0) {Currentpy_index-= 20;            } else {currentpy_index = currentpy_count-(currentpy_count% 10)-10;        }} else {currentpy_index = 0;    } Showchinese ();        } else if (ObjectName = = "Btnnext") {if (Currentpy_index < currentpy_count-1) {Showchinese ();        }} else {QString value = Btn->text (); If it is the & button, because the corresponding & is filtered, so the real text is to remove the previous & character if (ObjectName = = "BtnOther7") {value = Value.right (1        );                }//Is not currently in Chinese mode, click the button corresponding to text for pass parameter if (currenttype! = "Chinese") {if (Currentlineedit! = 0) {            Currentlineedit->insert (value); }} else {if (Currentlineedit! = 0) {//Chinese mode, do not allow input of special characters, singleClick the corresponding number button to get the current index of the kanji if (btn->property ("Btnother"). Tobool ()) {if (Ui->labpy->text (                    ). Length () = = 0) {Currentlineedit->insert (value);  }} else if (Btn->property ("Btnnum"). Tobool ()) {if (Ui->labpy->text (). Length ()                    = = 0) {Currentlineedit->insert (value);                    } else if (ObjectName = = "Btn0") {Setchinese (0);                    } else if (ObjectName = = "Btn1") {Setchinese (1);                    } else if (ObjectName = = "Btn2") {Setchinese (2);                    } else if (ObjectName = = "Btn3") {Setchinese (3);                    } else if (ObjectName = = "Btn4") {Setchinese (4);                    } else if (ObjectName = = "Btn5") {Setchinese (5); } else if (objectName= = "Btn6") {Setchinese (6);                    } else if (ObjectName = = "Btn7") {Setchinese (7);                    } else if (ObjectName = = "Btn8") {Setchinese (8);                    } else if (ObjectName = = "Btn9") {Setchinese (9); }} else if (Btn->property ("Btnletter"). Tobool ()) {Ui->labpy->settext (ui->l                    Abpy->text () + value);                Selectchinese (); }            }        }    }}

4: Kanji list click Select.

Event filter for recognizing mouse click Chinese character tag to get corresponding kanji bool Frminput::eventfilter (qobject *obj, qevent *event) {if (event->type () = = Qevent::mo        usebuttonpress) {if (obj = = ui->labch0) {setchinese (0);        } else if (obj = = ui->labch1) {Setchinese (1);        } else if (obj = = ui->labch2) {Setchinese (2);        } else if (obj = = Ui->labch3) {Setchinese (3);        } else if (obj = = ui->labch4) {Setchinese (4);        } else if (obj = = ui->labch5) {Setchinese (5);        } else if (obj = = Ui->labch6) {Setchinese (6);        } else if (obj = = Ui->labch7) {Setchinese (7);        } else if (obj = = ui->labch8) {Setchinese (8);        } else if (obj = = ui->labch9) {Setchinese (9);    } return false; } else if (event->type () = = qevent::keypress) {//If in Chinese mode, the current button needs to be reflected to the input interface on the IF (Currenttype = = "Chinese ") {qkeyevent *keyeveNT = static_cast<qkeyevent *> (event);            if (keyevent->key () = = Qt::key_backspace) {Ui->btndelete->click ();                } else {QString key = Keyevent->text ();                Qlist<qpushbutton *> btn = This->findchildren<qpushbutton *> ();                        foreach (Qpushbutton * b, BTN) {if (b->text () = = key) {B->click ();                    Break        }}} return true;    } return false; } return Qobject::eventfilter (obj, event);}

5: Intelligent Paging algorithm for Chinese characters.

void Frminput::selectchinese () {Clearchinese ();    Qsqlquery query;    QString currentpy = Ui->labpy->text ();    QString sql = "SELECT [Word] from [pinyin] where [pinyin]= '" + currentpy + "';";    Query.exec (SQL);        Add the queried word one by one to the kanji queue while (Query.next ()) {QString result = Query.value (0). toString ();            if (App::P ytype = = "Danpin") {allpy.append (result);        currentpy_count++;            } else {qstringlist text = Result.split ("");                    foreach (QString txt, text) {if (txt.length () > 0) {allpy.append (TXT);                currentpy_count++; }}}} Showchinese ();}    void Frminput::showchinese () {//each layout displays a maximum of 10 kanji int count = 0;    Currentpy.clear ();    for (int i = 0; i < i++) {Labch[i]->settext ("");        } for (int i = Currentpy_index; i < Currentpy_count; i++) {if (count = = ten) {break; } qstring txt = QString ("%1.%2"). Arg (count). Arg (Allpy[currentpy_index]);        Currentpy.append (Allpy[currentpy_index]);        Labch[count]->settext (TXT);        count++;    currentpy_index++; }//qdebug () << "Currentpy_index:" << currentpy_index << "Currentpy_count:" << currentpy_count; }

Customizable skin style and input method layout, contact qq:517216493

Executable file: http://pan.baidu.com/s/1sjHPM8l

Core code: HTTP://PAN.BAIDU.COM/S/1HQU16M4

Note:

Core code Open source, I hope everyone mouth mercy, 10 yuan for sale of the complete project, we welcome a lot of suggestions!

Thank you!

After compiling, copy the two database files from the file directory under the source code to the bin directory.

Qt to write a Chinese-language double-spell input method for skin-changing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.