Beispiel #1
0
bool InputMask::isValidInput( QChar key, QChar mask ) const
{
    switch ( mask )
    {
    case 'A':
        if ( key.isLetter() && key != m_blank )
            return TRUE;
        break;
    case 'a':
        if ( key.isLetter() || key == m_blank )
            return TRUE;
        break;
    case 'N':
        if ( key.isLetterOrNumber() && key != m_blank )
            return TRUE;
        break;
    case 'n':
        if ( key.isLetterOrNumber() || key == m_blank )
            return TRUE;
        break;
    case 'X':
        if ( key.isPrint() && key != m_blank )
            return TRUE;
        break;
    case 'x':
        if ( key.isPrint() || key == m_blank )
            return TRUE;
        break;
    case '9':
        if ( key.isNumber() && key != m_blank )
            return TRUE;
        break;
    case '0':
        if ( key.isNumber() || key == m_blank )
            return TRUE;
        break;
    case 'D':
        if ( key.isNumber() && key.digitValue() > 0 && key != m_blank )
            return TRUE;
        break;
    case 'd':
        if ( ( key.isNumber() && key.digitValue() > 0 ) || key == m_blank )
            return TRUE;
        break;
    case '#':
        if ( key.isNumber() || key == '+' || key == '-' || key == m_blank )
            return TRUE;
        break;
    default:
        break;
    }
    return FALSE;
}
Beispiel #2
0
void CalculatorDialog::expressionChanged(bool validExpression, bool validPointer, int_t value)
{
    if(!validExpression)
    {
        ui->txtBin->setText("");
        ui->txtSignedDec->setText("");
        ui->txtUnsignedDec->setText("");
        ui->txtHex->setText("");
        ui->txtOct->setText("");
        ui->txtAscii->setText("");
        ui->txtUnicode->setText("");
        ui->txtExpression->setStyleSheet("border: 2px solid red");
        emit validAddress(false);
    }
    else
    {
        ui->txtExpression->setStyleSheet("");
        ui->txtHex->setText(inFormat(value, N_HEX));
        ui->txtSignedDec->setText(inFormat(value, N_SDEC));
        ui->txtUnsignedDec->setText(inFormat(value, N_UDEC));
        int cursorpos = ui->txtBin->cursorPosition();
        ui->txtBin->setText(inFormat(value, N_BIN));
        ui->txtBin->setCursorPosition(cursorpos);
        ui->txtOct->setText(inFormat(value, N_OCT));
        if((value == (value & 0xFF)))
        {
            QChar c = QChar::fromLatin1((char)value);
            if(c.isPrint())
                ui->txtAscii->setText("'" + QString(c) + "'");
            else
                ui->txtAscii->setText("???");
        }
        else
            ui->txtAscii->setText("???");
        ui->txtAscii->setCursorPosition(1);
        if((value == (value & 0xFFF)))  //UNICODE?
        {
            QChar c = QChar::fromLatin1((wchar_t)value);
            if(c.isPrint())
                ui->txtUnicode->setText("L'" + QString(c) + "'");
            else
                ui->txtUnicode->setText("????");
        }
        else
        {
            ui->txtUnicode->setText("????");
        }
        ui->txtUnicode->setCursorPosition(2);
        emit validAddress(validPointer);
    }
}
int AccelString::stripAccelerator(QString &text)
{
  // Note: this code is derived from QAccel::shortcutKey
  int p = 0;

  while (p >= 0)
  {
    p = text.indexOf('&', p)+1;

    if (p <= 0 || p >= (int)text.length())
      break;

    if (text[p] != '&')
    {
      QChar c = text[p];
      if (c.isPrint())
      {
        text.remove(p-1,1);
	return p-1;
      }
    }

    p++;
  }

  return -1;
}
Beispiel #4
0
//-----------------------------------------------------------------------------
QString FontHelper::escapeControlChars(const QString &value)
{
    QString result;

    for (int i = 0; i < value.length(); i++)
    {
        QChar c = value.at(i);

        if (c.isNull() || !c.isPrint())
        {
            quint16 code = c.unicode();
            result.append(QString("\\x%1").arg(code, 4, 16, QChar('0')));
        }
        else if (c == QChar('@'))
        {
            result.append(QString("\\x0040"));
        }
        else if (c == QChar(QChar::Nbsp))
        {
            result.append(QString("\\x00a0"));
        }
        else
        {
            result.append(c);
        }
    }

    return result;
}
Beispiel #5
0
bool UITextEditor::HandleTextInput(QKeyEvent *Event)
{
    if (!Event)
        return false;

    // For consistency with UIActions::GetActionFromKey, only handle KeyPress
    if (Event->type() == QEvent::KeyRelease)
        return false;

    LOG(VB_GUI, LOG_DEBUG, QString("KeyPress %1 (%2)")
        .arg(Event->key(), 0, 16).arg(Event->text()));

    // Event must produce printable text and, in the case of simulated kepresses,
    // must be marked as printable. For a typical basic remote, this *should* mean
    // that only 0-9 are handled here..
    // As ever, this approach will probably need re-visiting to handle remapping
    // and remote input methods where printable/non-printable cannot be flagged
    if (Event->modifiers() == TORC_KEYEVENT_MODIFIERS)
        return false;

    QString text = Event->text();
    if (text.isEmpty())
        return false;

    QChar character = text.at(0);
    if (!character.isPrint())
        return false;

    QString newtext(m_text);
    newtext.insert(m_cursorPosition, text);
    m_cursorPosition += text.size();
    SetText(newtext);

    return true;
}
/*
    \internal
    Matches the current intermediate key sequence + the latest
    keyevent, with and AccelItem. Returns Identical,
    PartialMatch or NoMatch, and fills \a temp with the
    resulting key sequence.
*/
Qt::SequenceMatch QAccelManager::match( QKeyEvent *e, QAccelItem* item, QKeySequence& temp )
{
    SequenceMatch result = Qt::NoMatch;
    int index = intermediate.count();
    temp = intermediate;

    int modifier = translateModifiers( e->state() );

    if ( e->key() && e->key() != Key_unknown) {
	int key = e->key()  | modifier;
	if ( e->key() == Key_BackTab ) {
	    /*
	    In QApplication, we map shift+tab to shift+backtab.
	    This code here reverts the mapping in a way that keeps
	    backtab and shift+tab accelerators working, in that
	    order, meaning backtab has priority.*/
	    key &= ~SHIFT;

	    temp.setKey( key, index );
	    if ( Qt::NoMatch != (result = temp.matches( item->key )) )
		return result;
	    if ( e->state() & ShiftButton )
		key |= SHIFT;
	    key = Key_Tab | ( key & MODIFIER_MASK );
	    temp.setKey( key, index );
	    if ( Qt::NoMatch != (result = temp.matches( item->key )) )
		return result;
	} else {
	    temp.setKey( key, index );
	    if ( Qt::NoMatch != (result = temp.matches( item->key )) )
		return result;
	}

	if ( key == Key_BackTab ) {
	    if ( e->state() & ShiftButton )
		key |= SHIFT;
	    temp.setKey( key, index );
	    if ( Qt::NoMatch != (result = temp.matches( item->key )) )
		return result;
	}
    }
    if ( !e->text().isEmpty() ) {
        QChar c = e->text()[0];
        // be in accordance with accoQAccel::shortcutKey()
        if ( modifier != 0 && c.isPrint() )
            c = c.upper();
	temp.setKey( (int)c.unicode() | UNICODE_ACCEL | modifier, index );
	result = temp.matches( item->key );
    }
    return result;
}
Beispiel #7
0
// Function: CLEAN
Value func_clean(valVector args, ValueCalc *calc, FuncExtra *)
{
    QString str(calc->conv()->asString(args[0]).asString());
    QString result;
    QChar   c;
    int     i;
    int     l = str.length();

    for (i = 0; i < l; ++i) {
        c = str[i];
        if (c.isPrint())
            result += c;
    }

    return Value(result);
}
QString CharDataInformation::valueString(quint8 value)
{
    QChar qchar = QChar::fromLatin1(value);
    qchar = qchar.isPrint() ? qchar : QChar(QChar::ReplacementCharacter);
    QString charStr = QLatin1Char('\'') + qchar + QLatin1Char('\'');
    if (Kasten2::StructViewPreferences::showCharNumericalValue())
    {
        int base = displayBase();
        QString num = QString::number(value, base);
        if (base == 16)
            num.prepend(QLatin1String("0x"));
        if (base == 10 && Kasten2::StructViewPreferences::localeAwareDecimalFormatting())
            num = KGlobal::locale()->formatNumber(num, false, 0);
        charStr += QLatin1String(" (") + num + QLatin1Char(')');
    }
    return charStr;
}
Beispiel #9
0
int QAccel::shortcutKey( const QString &str )
{
    int p = 0;
    while ( p >= 0 ) {
        p = str.find( '&', p ) + 1;
        if ( p <= 0 || p >= (int)str.length() )
            return 0;
        if ( str[p] != '&' ) {
            QChar c = str[p];
            if ( c.isPrint() ) {
                c = c.upper();
                return c.unicode() + ALT + UNICODE_ACCEL;
            }
        }
        p++;
    }
    return 0;
}
Beispiel #10
0
//-----------------------------------------------------------------------------
QSize FontHelper::getCharacterSize(const QFontMetrics &metrics, QChar value)
{
    int charWidth = metrics.width(value);
    int charHeight = metrics.height();

    // fix width of italic style
    QRect r = metrics.boundingRect(QString(value));
    charWidth = qMax(qMax(r.left(), r.right()) + 1, charWidth);

    // check for abnormal size
    if ((charWidth > charHeight * 100) || (charWidth == 0))
    {
        if (value.isNull() || !value.isPrint())
        {
            charWidth = 1;
        }
    }

    return QSize(charWidth, charHeight);
}
Beispiel #11
0
/**
 * Convert Qt key input into Neovim key-notation
 *
 * see QKeyEvent
 */
QString InputConv::convertKey(const QString& text, int k, Qt::KeyboardModifiers mod)
{
	if (specialKeys.contains(k)) {
		return QString("<%1%2>").arg(modPrefix(mod)).arg(specialKeys.value(k));
	} else if (text.isEmpty()) {
		// This is a special key we can't handle
		return QString();
	}

	// Escape < and backslash
	if (text == "<") {
		return QString("<%1%2>").arg(modPrefix(mod)).arg("lt");
	}
	if (text == "\\") {
		return QString("<%1%2>").arg(modPrefix(mod)).arg("Bslash");
	}

	QChar c = text.at(0);
	// Remove SHIFT
	if (c.unicode() < 0x100 && !c.isLetterOrNumber() && c.isPrint()) {
		mod &= ~Qt::ShiftModifier;
	}

	// Remove CTRL empty characters at the start of the ASCII range
	if (c.unicode() < 0x20) {
		mod &= ~Qt::ControlModifier;
	}

	// Format with prefix if necessary
	QString prefix = modPrefix(mod);
	if (!prefix.isEmpty()) {
		return QString("<%1%2>").arg(prefix).arg(text);
	}

	return text;
}
Beispiel #12
0
/**
 * Convert Qt key input into Neovim key-notation
 *
 * see QKeyEvent
 */
QString InputConv::convertKey(const QString& text, int k, Qt::KeyboardModifiers mod)
{
    if ( mod & Qt::KeypadModifier ) {
		switch (k) {
		case Qt::Key_Home:
			return QString("<%1kHome>").arg(modPrefix(mod));
		case Qt::Key_End:
			return QString("<%1kEnd>").arg(modPrefix(mod));
		case Qt::Key_PageUp:
			return QString("<%1kPageUp>").arg(modPrefix(mod));
		case Qt::Key_PageDown:
			return QString("<%1kPageDown>").arg(modPrefix(mod));
		case Qt::Key_Plus:
			return QString("<%1kPlus>").arg(modPrefix(mod));
		case Qt::Key_Minus:
			return QString("<%1kMinus>").arg(modPrefix(mod));
		case Qt::Key_multiply:
			return QString("<%1kMultiply>").arg(modPrefix(mod));
		case Qt::Key_division:
			return QString("<%1kDivide>").arg(modPrefix(mod));
		case Qt::Key_Enter:
			return QString("<%1kEnter>").arg(modPrefix(mod));
		case Qt::Key_Period:
			return QString("<%1kPoint>").arg(modPrefix(mod));
		case Qt::Key_0:
			return QString("<%1k0>").arg(modPrefix(mod));
		case Qt::Key_1:
			return QString("<%1k1>").arg(modPrefix(mod));
		case Qt::Key_2:
			return QString("<%1k2>").arg(modPrefix(mod));
		case Qt::Key_3:
			return QString("<%1k3>").arg(modPrefix(mod));
		case Qt::Key_4:
			return QString("<%1k4>").arg(modPrefix(mod));
		case Qt::Key_5:
			return QString("<%1k5>").arg(modPrefix(mod));
		case Qt::Key_6:
			return QString("<%1k6>").arg(modPrefix(mod));
		case Qt::Key_7:
			return QString("<%1k7>").arg(modPrefix(mod));
		case Qt::Key_8:
			return QString("<%1k8>").arg(modPrefix(mod));
		case Qt::Key_9:
			return QString("<%1k9>").arg(modPrefix(mod));
		}
    }

	if (specialKeys.contains(k)) {
		return QString("<%1%2>").arg(modPrefix(mod)).arg(specialKeys.value(k));
	}

	QChar c;
	// Escape < and backslash
	if (text == "<") {
		return QString("<%1%2>").arg(modPrefix(mod)).arg("lt");
	} else if (text == "\\") {
		return QString("<%1%2>").arg(modPrefix(mod)).arg("Bslash");
	} else if (text.isEmpty()) {
		// on macs, text is empty for ctrl+key and cmd+key combos (with or without alt)
		if (mod & ControlModifier || mod & CmdModifier) {
			// ignore ctrl, alt and cmd key combos by themselves
			QList<Qt::Key> keys = { Key_Control, Key_Alt, Key_Cmd };
			if (keys.contains((Qt::Key)k)) {
				return QString();
			} else if (mod & ShiftModifier) {
				// Ignore event for Ctrl-Shift
				// Fixes issue #344, C-S- being treated as C-Space
				return QString();
			} else {
				// key code will be the value of the char (hopefully)
				c = QChar(k);
			}
		} else {
			// This is a special key we can't handle
			return QString();
		}
	} else {
		// Key event compression is disabled, text has one char
		c = text.at(0);
	}

	// Remove SHIFT
	if (c.unicode() >= 0x80 || (!c.isLetterOrNumber() && c.isPrint())) {
		mod &= ~ShiftModifier;
	}

	// Remove CTRL empty characters at the start of the ASCII range
	if (c.unicode() < 0x20) {
		mod &= ~ControlModifier;
	}

	// Format with prefix if necessary
	QString prefix = modPrefix(mod);
	if (!prefix.isEmpty()) {
		return QString("<%1%2>").arg(prefix).arg(c);
	}

	return QString(c);
}
Beispiel #13
0
bool ShortcutEdit::eventFilter(QObject* watched, QEvent* event)
{
    if ((watched == m_edit) && (event->type() == QEvent::KeyPress)) {
        QKeyEvent* key_event = static_cast<QKeyEvent*>(event);

        Qt::KeyboardModifiers modifiers = key_event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier);
        int key = key_event->key();

        switch (key) {
        // Don't do anything if they only press a modifier
        case Qt::Key_Shift:
        case Qt::Key_Control:
        case Qt::Key_Meta:
        case Qt::Key_Alt:
            return true;

        // Clear on backspace unless modifier is used
        case Qt::Key_Backspace:
        case Qt::Key_Delete:
            if (modifiers == Qt::NoModifier) {
                clear();
                return true;
            }
            break;

        // Allow tab to change focus
        case Qt::Key_Tab:
        case Qt::Key_Backtab:
            return false;

        default:
            break;
        }

        // Add modifiers; only allow shift if it is not required for key of shortcut
        if ((modifiers & Qt::ShiftModifier) && !key_event->text().isEmpty()) {
            QChar c = key_event->text().at(0);
            if (c.isPrint() && !c.isLetterOrNumber() && !c.isSpace()) {
                key |= Qt::SHIFT;
            }
        }
        if (modifiers & Qt::ControlModifier) {
            key |= Qt::CTRL;
        }
        if (modifiers & Qt::MetaModifier) {
            key |= Qt::META;
        }
        if (modifiers & Qt::AltModifier) {
            key |= Qt::ALT;
        }

        // Change shortcut
        m_shortcut = QKeySequence(key);
        setText();
        emit changed();

        return true;
    } else {
        return QWidget::eventFilter(watched, event);
    }
}
Beispiel #14
0
void MainWidget::keyPressEvent(QKeyEvent *event) {
    QChar c = event->text()[0];
    if (c.isPrint()) {
        undo->push(new Text_Command(this, lastx, lasty, c));
        if (++lastx >= xasc) {
            lastx = 0;
            if (++lasty >= yasc) {
                lasty = 0;
            }
        }
        update(pixelRect(lastx, lasty));
        emit somethingChanged(true);
    } else if (event->key() == Qt::Key_Delete) {
        undo->push(new Text_Command(this, lastx, lasty, QChar()));
        emit somethingChanged(true);
    } else if (event->key() == Qt::Key_Backspace) {
        int oldx = lastx;
        int oldy = lasty;
        if (--lastx < 0) {
            lastx = xasc-1;
            if (--lasty < 0) {
                lasty = yasc-1;
            }
        }
        undo->push(new Text_Command(this, lastx, lasty, QChar()));
        update(pixelRect(oldx, oldy));
        emit somethingChanged(true);
    } else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
        int oldx = lastx;
        int oldy = lasty;
        lastx = 0;
        if (++lasty >= yasc) {
            lasty = 0;
        }
        update(pixelRect(oldx, oldy).united(pixelRect(lastx, lasty)));
    } else if (event->key() == Qt::Key_Up) {
        int oldy = lasty;
        if (--lasty < 0) {
            lasty = oldy;
        }
        update(pixelRect(lastx, oldy).united(pixelRect(lastx, lasty)));
    } else if (event->key() == Qt::Key_Down) {
        int oldy = lasty;
        if (++lasty >= yasc) {
            lasty = oldy;
        }
        update(pixelRect(lastx, oldy).united(pixelRect(lastx, lasty)));
    } else if (event->key() == Qt::Key_Left) {
        int oldx = lastx;
        if (--lastx < 0) {
            lastx = oldx;
        }
        update(pixelRect(oldx, lasty).united(pixelRect(lastx, lasty)));
    } else if (event->key() == Qt::Key_Right) {
        int oldx = lastx;
        if (++lastx >= xasc) {
            lastx = oldx;
        }
        update(pixelRect(oldx, lasty).united(pixelRect(lastx, lasty)));
    } else {
        QWidget::keyPressEvent(event);
    }
}