Exemple #1
0
void TextBase::endHexState(EditData& ed)
      {
      TextEditData* ted = static_cast<TextEditData*>(ed.getData(this));
      TextCursor* _cursor = &ted->cursor;

      if (hexState >= 0) {
            if (hexState > 0) {
                  int c2 = _cursor->column();
                  int c1 = c2 - (hexState + 1);

                  TextBlock& t = _layout[_cursor->row()];
                  QString ss   = t.remove(c1, hexState + 1);
                  bool ok;
                  int code     = ss.mid(1).toInt(&ok, 16);
                  _cursor->setColumn(c1);
                  _cursor->clearSelection();
                  if (ok)
                        editInsertText(_cursor, QString(code));
                  else
                        qDebug("cannot convert hex string <%s>, state %d (%d-%d)",
                           qPrintable(ss.mid(1)), hexState, c1, c2);
                  }
            hexState = -1;
            }
      }
Exemple #2
0
void TextBase::inputTransition(EditData& ed, QInputMethodEvent* ie)
      {
      TextEditData* ted = static_cast<TextEditData*>(ed.getData(this));
      TextCursor* _cursor = &ted->cursor;

      // remove preedit string
      int n = preEdit.size();
      while (n--) {
            if (_cursor->movePosition(QTextCursor::Left)) {
                  TextBlock& l  = _cursor->curLine();
                   l.remove(_cursor->column());
                  _cursor->text()->triggerLayout();
                  _cursor->text()->setTextInvalid();
                  }
            }

      qDebug("<%s><%s> len %d start %d, preEdit size %d",
         qPrintable(ie->commitString()),
         qPrintable(ie->preeditString()),
         ie->replacementLength(), ie->replacementStart(), preEdit.size());

      if (!ie->commitString().isEmpty()) {
            _cursor->format()->setPreedit(false);
            score()->startCmd();
            insertText(ed, ie->commitString());
            score()->endCmd();
            preEdit.clear();
            }
      else  {
            preEdit = ie->preeditString();
            if (!preEdit.isEmpty()) {
#if 0
                  for (auto a : ie->attributes()) {
                        switch(a.type) {
                              case QInputMethodEvent::TextFormat:
                                    {
                                    qDebug("   attribute TextFormat: %d-%d", a.start, a.length);
                                    QTextFormat tf = a.value.value<QTextFormat>();
                                    }
                                    break;
                              case QInputMethodEvent::Cursor:
                                    qDebug("   attribute Cursor at %d", a.start);
                                    break;
                              default:
                                    qDebug("   attribute %d", a.type);
                              }
                        }
#endif
                  _cursor->format()->setPreedit(true);
                  _cursor->updateCursorFormat();
                  editInsertText(_cursor, preEdit);
                  setTextInvalid();
                  layout1();
                  score()->update();
                  }
            }
      ie->accept();
      }