예제 #1
0
QWidget* PredictiveKeyboard::widget(QWidget*)
{
    if(!mKeyboard) {
        mKeyboard = new KeyboardWidget(createKeyboardConfig(), 0);
        //TODO: load layouts from config
        mKeyboard->addBoard("russian", QStringList() << "ЙЦУКЕНГШЩЗХЪ" << "ФЫВАПРОЛДЖЭ" << "ЯЧСМИТЬБЮ,", KeyboardWidget::UpperCase);
        mKeyboard->addBoard("russian", QStringList() << "йцукенгшщзхъ" << "фывапролджэ" << (QString("ячсмитьбю.") + QChar(0x21b5)), KeyboardWidget::LowerCase);

        mKeyboard->addBoard("english", QStringList() << "QWERTYUIOP" << "ASDFGHJKL" << "ZXCVBNM", KeyboardWidget::UpperCase);
        mKeyboard->addBoard("english", QStringList() << "qwertyuiop" << "asdfghjkl" << "zxcvbnm", KeyboardWidget::LowerCase);

        mKeyboard->addBoard("numeric", QStringList() << "12345" << "67890", KeyboardWidget::Numeric);
        mKeyboard->addBoard("symbol",  QStringList() << "^#@!$()*&%" << "|,.;:'?\\`" << (QString("[]+=-/~\"_") + QChar(0x21b5)), KeyboardWidget::NonAlphabet);

        mKeyboard->setDefaultLayout("russian");

        QObject::connect(mKeyboard, SIGNAL(preedit(QString)), this, SLOT(preedit(QString)));
        QObject::connect(mKeyboard, SIGNAL(commit(QString)), this, SLOT(submitWord(QString)));
        QObject::connect(mKeyboard, SIGNAL(commit(QString)), this, SLOT(checkMicroFocus()));
        QObject::connect(mKeyboard, SIGNAL(backspace()), this, SLOT(erase()));
        KeyboardWidget::instantiatePopupScreen();
    }

    return mKeyboard;
};
예제 #2
0
bool KeypadInputMethod::filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat) {
  if (!isPress) return false;

  switch (_state) {
    case UNFOCUSED:
      return false;

    case COMPOSING:
      if (isLetterKey(keycode)) {
        int n = getLetterKey(keycode);
        if (n != _lastNumber) {
          commit();
          _lastNumber = n;
          _presses = -1;
        }
        _presses = (_presses + 1) % _keyChars[_lastNumber].count;
        preedit();
        return true;
      } else if (keycode == Qt::Key_9) {
        commit();
        return true;
      } else if (keycode == Qt::Key_0) {
        commit();
        commit(" ");
        return true;
      } else if (keycode == Qt::Key_Back) {
        commit("");
        return true;
      } else if (keycode == Qt::Key_Return) {
        commit();
        return false; // handle event elsewhere.
      }
      break;

    case COMMITTED:
      if (isLetterKey(keycode)) {
        int n = getLetterKey(keycode);
        _lastNumber = n;
        _presses = 0;
        preedit();
        return true;
      } else if (keycode == Qt::Key_0) {
        commit(" ");
        return true;
      } else if (keycode == Qt::Key_9) {
        return true;
      } else if (keycode == Qt::Key_Back) {
        if (modifiers & Qt::AltModifier) {
          return false;
        }
        QWSServer::sendKeyEvent(8, Qt::Key_Backspace, 0, true, false);
        return true;
      } else if (keycode == Qt::Key_Return) {
        return false; // handle event elsewhere.
      }
      break;
  }
  return false;
}
예제 #3
0
void KeypadInputMethod::preedit(const QString &str) {
  if (str.isNull()) {
    preedit(QString(1, currentChar()));
  } else {
    sendPreeditString(str, str.size());
    _state = COMPOSING;
  }
}
예제 #4
0
void QtopiaInputDialogPrivate::init(const QString &title, QWidget* label, QWidget *input)
{
    Q_Q(QtopiaInputDialog);
    q->setWindowTitle(title);
    QVBoxLayout *vbox = new QVBoxLayout(q);
    //vbox->setSpacing(QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)/2);   //### use widget-specific numbers instead
    vbox->setContentsMargins(0,0,0,0);

    if (QLabel *qlabel = qobject_cast<QLabel*>(label)) {
        if (qlabel->text().isEmpty())
            label->hide();
    }

    vbox->addStretch(1);
    vbox->addWidget(label);
    if (qobject_cast<QSpinBox*>(input) || qobject_cast<QTimeEdit*>(input)) {
        QHBoxLayout *hbox = new QHBoxLayout;
        vbox->addLayout(hbox);
        hbox->addStretch(1);
        hbox->addWidget(input);
        hbox->addStretch(1);
    } else {
        vbox->addWidget(input);
    }
    vbox->addStretch(1);

    if (qobject_cast<QLineEdit*>(input) || qobject_cast<QTextEdit*>(input)
        || qobject_cast<QSpinBox*>(input) || qobject_cast<QTimeEdit*>(input)) {
        if(!m_input) {
            m_input = new KeyboardInputWidget;
            QObject::connect(m_input->keyboard, SIGNAL(preedit(QString)), q, SLOT(_q_preedit(QString)));
            QObject::connect(m_input->keyboard, SIGNAL(commit(QString)), q, SLOT(_q_submitWord(QString)));
            QObject::connect(m_input->keyboard, SIGNAL(backspace()), q, SLOT(_q_erase()));
            m_input->keyboard->setAcceptDest(QPoint(0,0));  //###
        }
        QString hint;
        if (qobject_cast<QSpinBox*>(input) || qobject_cast<QTimeEdit*>(input))
            hint = "int";
        else
            hint = stringForHint(QtopiaApplication::inputMethodHint(input), QtopiaApplication::inputMethodHintParam(input));
        m_input->keyboard->setHint(hint);

        vbox->addWidget(m_input);
        m_widget = input;
    }
}