Esempio n. 1
0
    QString NumberFormat::sizeString(quint64 size)
    {
        if(size < 1000)
            return QObject::tr("%n byte(s)", "", size);

        return numberFormat(QStringList() << QObject::tr("KB") << QObject::tr("MB") << QObject::tr("GB") << QObject::tr("TB"), static_cast<double>(size));
    }
Esempio n. 2
0
void INDI_E::buildNumber  (INumber *inp)
{
    bool scale = false;
    char iNumber[32];

    name  = inp->name;
    label = i18nc(libindi_strings_context, inp->label);

    np = inp;

    if (label.isEmpty())
        label = i18nc(libindi_strings_context, inp->name);

    numberFormat(iNumber, np->format, np->value);
    text = iNumber;

    setupElementLabel();

    if (np->step != 0 && (np->max - np->min)/np->step <= 100)
        scale = true;

    switch (dataProp->getPermission())
    {
    case IP_RW:
        setupElementRead(ELEMENT_READ_WIDTH);
        if (scale)
            setupElementScale(ELEMENT_WRITE_WIDTH);
        else
            setupElementWrite(ELEMENT_WRITE_WIDTH);

        guiProp->addLayout(EHBox);
        break;

    case IP_RO:
        setupElementRead(ELEMENT_READ_WIDTH);
        guiProp->addLayout(EHBox);
        break;

    case IP_WO:
        if (scale)
            setupElementScale(ELEMENT_FULL_WIDTH);
        else
            setupElementWrite(ELEMENT_FULL_WIDTH);

        guiProp->addLayout(EHBox);

        break;
    }

}
Esempio n. 3
0
/*!
 * Returns whether the number format is probably a dateTime or not
 */
bool Format::isDateTimeFormat() const
{
    if (hasProperty(FormatPrivate::P_NumFmt_FormatCode)) {
        //Custom numFmt, so
        //Gauss from the number string
        return NumFormatParser::isDateTime(numberFormat());
    } else if (hasProperty(FormatPrivate::P_NumFmt_Id)){
        //Non-custom numFmt
        int idx = numberFormatIndex();

        //Is built-in date time number id?
        if ((idx >= 14 && idx <= 22) || (idx >= 45 && idx <= 47))
            return true;

        if ((idx >= 27 && idx <= 36) || (idx >= 50 && idx <= 58)) //Used in CHS\CHT\JPN\KOR
            return true;
    }

    return false;
}
Esempio n. 4
0
void INDI_E::syncNumber()
{

    char iNumber[32];
    if (np == NULL || read_w == NULL)
        return;

    numberFormat(iNumber, np->format, np->value);

    text = iNumber;

    read_w->setText(text);

    if (spin_w)
    {
        if (np->min != spin_w->minimum())
            setMin();
        if (np->max != spin_w->maximum())
            setMax();
    }

}
Esempio n. 5
0
void QalculateHighlighter::highlightBlock(const QString& text)
{
    if ( text.isEmpty() || text.trimmed().isEmpty() || text.startsWith(QLatin1String(">>> "))
            // filter error messages, they get highlighted via html
            || text.startsWith(i18n("ERROR") + QLatin1Char(':')) || text.startsWith(i18n("WARNING") + QLatin1Char(':')) ) {
        return;
    }

    int pos = 0;
    int count;
    ///TODO: Can't we use CALCULATOR->parse() or similar?
    ///      Question is how to get the connection between
    ///      MathStructur and position+length in @p text
    const QStringList& words = text.split(QRegExp(QLatin1String("\\b")), QString::SkipEmptyParts);

    qDebug() << "highlight block:" << text;

    CALCULATOR->beginTemporaryStopMessages();

    const QString decimalSymbol = QLocale().decimalPoint();

    for ( int i = 0; i < words.size(); ++i, pos += count ) {
        count = words[i].size();
        if ( words[i].trimmed().isEmpty() ) {
            continue;
        }

        qDebug() << "highlight word:" << words[i];

        QTextCharFormat format = errorFormat();

        if ( i < words.size() - 1 && words[i+1].trimmed() == QLatin1String("(") && CALCULATOR->getFunction(words[i].toUtf8().constData()) ) {
            // should be a function
            qDebug() << "function";
            format = functionFormat();
        } else if ( isOperatorAndWhitespace(words[i]) ) {
            // stuff like ") * (" is an invalid expression, but acutally OK

            // check if last number is actually a float
            bool isFloat = false;
            if ( words[i].trimmed() == decimalSymbol ) {
                if ( i > 0 ) {
                    // lookbehind
                    QString lastWord = words[i-1].trimmed();
                    if ( !lastWord.isEmpty() && lastWord.at(lastWord.size()-1).isNumber() ) {
                        qDebug() << "actually float";
                        isFloat = true;
                    }
                }
                if ( !isFloat && i < words.size() - 1 ) {
                    // lookahead
                    QString nextWord = words[i+1].trimmed();
                    if ( !nextWord.isEmpty() && nextWord.at(0).isNumber() ) {
                        qDebug() << "float coming";
                        isFloat = true;
                    }
                }
            }
            if ( !isFloat ) {
                qDebug() << "operator / whitespace";
                format = operatorFormat();
            } else {
                format = numberFormat();
            }
        } else {
            MathStructure expr = CALCULATOR->parse(words[i].toLatin1().constData());
            if ( expr.isNumber() || expr.isNumber_exp() ) {
                qDebug() << "number";
                format = numberFormat();
            } else if ( expr.isVariable() ) {
                qDebug() << "variable";
                format = variableFormat();
            } else if ( expr.isUndefined() ) {
                qDebug() << "undefined";
            } else if ( expr.isUnit() || expr.isUnit_exp() ) {
                qDebug() << "unit";
                format = keywordFormat();
            }
        }

        setFormat(pos, count, format);
    }

    CALCULATOR->endTemporaryStopMessages();

}