bool InputWidget::eventFilter(QObject *watched, QEvent *event) { if (event->type() != QEvent::KeyPress) return false; QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); // keys from BufferView should be sent to (and focus) the input line BufferView *view = qobject_cast<BufferView *>(watched); if (view) { if (keyEvent->text().length() == 1 && !(keyEvent->modifiers() & (Qt::ControlModifier ^ Qt::AltModifier))) { // normal key press QChar c = keyEvent->text().at(0); if (c.isLetterOrNumber() || c.isSpace() || c.isPunct() || c.isSymbol()) { setFocus(); QCoreApplication::sendEvent(inputLine(), keyEvent); return true; } } return false; } else if (watched == ui.inputEdit) { if (keyEvent->matches(QKeySequence::Find)) { QAction *act = GraphicalUi::actionCollection()->action("ToggleSearchBar"); if (act) { act->toggle(); return true; } } return false; } return false; }
QString KStringHandler::preProcessWrap(const QString &text) { const QChar zwsp(0x200b); QString result; result.reserve(text.length()); for (int i = 0; i < text.length(); i++) { const QChar c = text[i]; bool openingParens = (c == QLatin1Char('(') || c == QLatin1Char('{') || c == QLatin1Char('[')); bool singleQuote = (c == QLatin1Char('\'') ); bool closingParens = (c == QLatin1Char(')') || c == QLatin1Char('}') || c == QLatin1Char(']')); bool breakAfter = (closingParens || c.isPunct() || c.isSymbol()); bool nextIsSpace = (i == (text.length() - 1) || text[i + 1].isSpace()); bool prevIsSpace = (i == 0 || text[i - 1].isSpace() || result[result.length() - 1] == zwsp); // Provide a breaking opportunity before opening parenthesis if (openingParens && !prevIsSpace) result += zwsp; // Provide a word joiner before the single quote if (singleQuote && !prevIsSpace) result += QChar(0x2060); result += c; if (breakAfter && !openingParens && !nextIsSpace && !singleQuote) result += zwsp; } return result; }
static int qt_mac_get_key(int modif, const QChar &key, int virtualKey) { #ifdef DEBUG_KEY_BINDINGS qDebug("**Mapping key: %d (0x%04x) - %d (0x%04x)", key.unicode(), key.unicode(), virtualKey, virtualKey); #endif if (key == kClearCharCode && virtualKey == 0x47) return Qt::Key_Clear; if (key.isDigit()) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %d", __LINE__, key.digitValue()); #endif return key.digitValue() + Qt::Key_0; } if (key.isLetter()) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %d", __LINE__, (key.toUpper().unicode() - 'A')); #endif return (key.toUpper().unicode() - 'A') + Qt::Key_A; } if (key.isSymbol()) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %d", __LINE__, (key.unicode())); #endif return key.unicode(); } for (int i = 0; qt_mac_keyboard_symbols[i].qt_code; i++) { if (qt_mac_keyboard_symbols[i].mac_code == key) { /* To work like Qt for X11 we issue Backtab when Shift + Tab are pressed */ if (qt_mac_keyboard_symbols[i].qt_code == Qt::Key_Tab && (modif & Qt::ShiftModifier)) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: Qt::Key_Backtab", __LINE__); #endif return Qt::Key_Backtab; } #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %s", __LINE__, qt_mac_keyboard_symbols[i].desc); #endif return qt_mac_keyboard_symbols[i].qt_code; } } //last ditch try to match the scan code for (int i = 0; qt_mac_keyvkey_symbols[i].qt_code; i++) { if (qt_mac_keyvkey_symbols[i].mac_code == virtualKey) { #ifdef DEBUG_KEY_BINDINGS qDebug("%d: got key: %s", __LINE__, qt_mac_keyvkey_symbols[i].desc); #endif return qt_mac_keyvkey_symbols[i].qt_code; } } // check if they belong to key codes in private unicode range if (key >= 0xf700 && key <= 0xf747) { if (key >= 0xf704 && key <= 0xf726) { return Qt::Key_F1 + (key.unicode() - 0xf704) ; } for (int i = 0; qt_mac_private_unicode[i].qt_code; i++) { if (qt_mac_private_unicode[i].mac_code == key) { return qt_mac_private_unicode[i].qt_code; } } } //oh well #ifdef DEBUG_KEY_BINDINGS qDebug("Unknown case.. %s:%d %d[%d] %d", __FILE__, __LINE__, key.unicode(), key.toLatin1(), virtualKey); #endif return Qt::Key_unknown; }
double DoubleSpinBox::valueFromText( const QString & text ) const { DoubleSpinbox_qDebug() << Q_FUNC_INFO << "text = " << text; KLocale * locale = KGlobal::locale(); // Fetch the characters that we don't want to discard const QString exclude = locale->decimalSymbol() + locale->thousandsSeparator() + locale->positiveSign() + locale->negativeSign(); QString textToStrip( text ); QString numberToRead = textToStrip.remove( QRegExp("[^"+exclude+"\\d]") ); bool ok; double value = locale->readNumber( numberToRead, &ok ); if (!ok) { DoubleSpinbox_qDebug() << Q_FUNC_INFO << "numberToRead = |" << numberToRead << "| NOT OK"; value = 0; } DoubleSpinbox_qDebug() << Q_FUNC_INFO << "numberToRead = " << numberToRead << ", value = " << value; if ( value > maximum() ) { value = maximum(); } else if ( value < minimum() ) { value = minimum(); } if ( std::abs(value) < m_minAbsValue*0.9999 ) { value = 0.0; } double multiplier = 1.0; //updateSuffix( value ); QString textForSuffix( text ); if ( textForSuffix.length() != 0 ) { if ( textForSuffix.endsWith( m_unit, false ) ) { textForSuffix = textForSuffix.remove( textForSuffix.length() - m_unit.length(), m_unit.length() ); } textForSuffix.stripWhiteSpace(); QChar siExp = textForSuffix[ textForSuffix.length()-1 ]; DoubleSpinbox_qDebug() << Q_FUNC_INFO << "SI exp = " << siExp; if ( siExp.isLetter() || siExp.isSymbol() ) { multiplier = CNItem::getMultiplier( QString(siExp) ); } else { multiplier = 1; } } DoubleSpinbox_qDebug() << Q_FUNC_INFO << "multiplier = " << multiplier; //value /= Item::getMultiplier( value ); value *= multiplier; DoubleSpinbox_qDebug() << Q_FUNC_INFO << "value = " << value; return value; }
static inline bool isWordSeparator(const QChar character) { return character.isSpace() || character.isMark() || character.isPunct() || character.isSymbol(); }