void VariableDoubleSpinBox::stepBy(int steps)
{
    double oldValue = value();
	
	// Default new value
	int i = -99;
	double newValue = oldValue + singleStep() * steps;

	// If a single digit is selected, increment or decrement that digit
	if (lineEdit()->hasSelectedText())
	{
		if (lineEdit()->selectedText().length() == 1)
		{
			if (lineEdit()->selectedText()[0].isDigit())
			{
				i = cleanText().length() - lineEdit()->selectionStart();
				int j = cleanText().length() - lineEdit()->selectionStart() - decimals();
				if (decimals() > 0)
				{
					j--;
				}
				if (j >= 0)
				{
					j--;
				}
				newValue = oldValue + pow(10.0, j) * steps;
			}
		}
	}

	// Check for out of bounds and set the new value
	if (newValue < minimum())
	{
		return;
	}
	else if (newValue > maximum())
	{
		return;
	}
	setValue(newValue);

	// For unknown reasons, after the new value is set the selected text changes in unpredictable ways
	// Fix it
	if (i == -99)
	{
		lineEdit()->selectAll();
	}
	else
	{
		i = cleanText().length() - i;
		if (i < 0)
		{
			i = 0;
		}
		lineEdit()->setSelection(i, 1);
	}
}
示例#2
0
int KDoubleSpinBox::mapTextToValue( bool * ok ) {
  double value;
  if ( acceptLocalizedNumbers() )
    value = KGlobal::locale()->readNumber( cleanText(), ok );
  else
    value = cleanText().toDouble( ok );
  if ( !*ok ) return 0;
  if ( value > maxValue() )
    value = maxValue();
  else if ( value < minValue() )
    value = minValue();
  return d->mapToInt( value, ok );
}
示例#3
0
QString KisDoubleParseSpinBox::textFromValue(double val) const
{

    if (!boolLastValid) {
        emit errorWhileParsing(lastExprParsed);
        return lastExprParsed;
    }
    emit noMoreParsingError();

    double v = KisNumericParser::parseSimpleMathExpr(cleanText());
    v = QString("%1").arg(v, 0, 'f', decimals()).toDouble();
    if (hasFocus() && (v == value() || (v >= maximum() && value() == maximum()) || (v <= minimum() && value() == minimum())) ) { //solve a very annoying bug where the formula can collapse while editing. With this trick the formula is not lost until focus is lost.
        return cleanText();
    }

    return QDoubleSpinBox::textFromValue(val);
}
示例#4
0
QString KisIntParseSpinBox::textFromValue(int val) const
{

    if (!boolLastValid) {
        emit errorWhileParsing(*lastExprParsed);
        return *lastExprParsed;
    }

    emit noMoreParsingError();

    int v = KisNumericParser::parseIntegerMathExpr(cleanText());
    if (hasFocus() && (v == value() || (v >= maximum() && value() == maximum()) || (v <= minimum() && value() == minimum())) ) { //solve a very annoying bug where the formula can collapse while editing. With this trick the formula is not lost until focus is lost.
        return cleanText();
    }

    return QSpinBox::textFromValue(val);

}
示例#5
0
void BigNumDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
    auto spin = qobject_cast<BigNumSpin*>(editor);
    spin->interpretText();
    if (spin->cleanText().isEmpty())
        model->setData(index, QVariant(), Qt::EditRole);
    else
        model->setData(index, spin->value(), Qt::EditRole);
}
示例#6
0
int QDoubleSpinBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QAbstractSpinBox::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 3)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 3;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = prefix(); break;
        case 1: *reinterpret_cast< QString*>(_v) = suffix(); break;
        case 2: *reinterpret_cast< QString*>(_v) = cleanText(); break;
        case 3: *reinterpret_cast< int*>(_v) = decimals(); break;
        case 4: *reinterpret_cast< double*>(_v) = minimum(); break;
        case 5: *reinterpret_cast< double*>(_v) = maximum(); break;
        case 6: *reinterpret_cast< double*>(_v) = singleStep(); break;
        case 7: *reinterpret_cast< double*>(_v) = value(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setPrefix(*reinterpret_cast< QString*>(_v)); break;
        case 1: setSuffix(*reinterpret_cast< QString*>(_v)); break;
        case 3: setDecimals(*reinterpret_cast< int*>(_v)); break;
        case 4: setMinimum(*reinterpret_cast< double*>(_v)); break;
        case 5: setMaximum(*reinterpret_cast< double*>(_v)); break;
        case 6: setSingleStep(*reinterpret_cast< double*>(_v)); break;
        case 7: setValue(*reinterpret_cast< double*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
示例#7
0
QVariant pActionsModel::data( const QModelIndex& index, int role ) const
{
    QAction* action = this->action( index );

    if ( !action ) {
        return QVariant();
    }

    switch ( role ) {
        case Qt::DecorationRole:
            switch ( index.column() ) {
                case 0:
                    return action->icon();
                default:
                    break;
            }

            break;
        case Qt::DisplayRole:
        case Qt::ToolTipRole:
            switch ( index.column() ) {
                case pActionsModel::Action:
                    return cleanText( action->text() );
                case pActionsModel::Shortcut:
                    return action->shortcut().toString( QKeySequence::NativeText );
                case pActionsModel::DefaultShortcut:
                    return defaultShortcut( action ).toString( QKeySequence::NativeText );
            }

            break;

        case Qt::FontRole: {
            QFont font = action->font();

            if ( action->menu() ) {
                font.setBold( true );
            }

            return font;
        }

        /*case Qt::BackgroundRole:
            return action->menu() ? QBrush( QColor( 0, 0, 255, 20 ) ) : QVariant();*/

        case pActionsModel::MenuRole:
            return QVariant::fromValue( action->menu() );
        case pActionsModel::ActionRole:
            return QVariant::fromValue( action );
    }

    return QVariant();
}
void KSimBaseIntSpinBox::slotTextChanged(const QString & /*text*/)
{
//	KSIMDEBUG("KSimBaseIntSpinBox::slotTextChanged()")
	if (isTrackingEnabled())
	{
		bool ok;
		KSimBaseInt i = KSimBaseInt::convert(cleanText(), &ok);
		if (ok && (i >= minValue()) && (i <= maxValue()))
		{
			emit valueChangedTracking(i);
		}
	}
}
示例#9
0
DocInfo HTMLParser::parse(RICPNS::Document &document) {

	oneurl curl;
	string html;

	cleanText(document.getText(), html);
	GumboOutput* output = gumbo_parse(html.c_str());
	GumboNode* node = output->root;

	string docUrl = document.getURL();
	string content, pageTitle;
	list<pair<string, string> > links;

//	thread t1(&HTMLParser::extractContent, this, node, ref(content));
//	thread t2(&HTMLParser::extractPageTitle, this, node, ref(pageTitle));
//	thread t3(&HTMLParser::extractLinks, this, node, ref(links), ref(docUrl));

	extractContent(node, content);
	extractPageTitle(node, pageTitle);
	extractLinks(node, links, docUrl);

//	t1.join();
//	t2.join();
//	t3.join();

	gumbo_destroy_output(&kGumboDefaultOptions, output);

	DocInfo docInfo;
	docInfo.setContent(content);

	docInfo.setCanonicalUrl(
			curl.Parse(docUrl) ?
					curl.CNormalize(docUrl) : docUrl);

	docInfo.setUrl(docUrl);

	docInfo.setTitle(pageTitle);
	docInfo.setLinks(links);
	//	cout << docInfo.getUrl() << "  -  "<<  "   " << link << endl;

//	static int i=1;
//	cout << i++ << " - " << docInfo.getCanonicalUrl() << endl;
//
//
//	for(pair<string, string> link : links){
//		cout <<  " ------- " << link.first << endl;
//		cout <<  link.second << endl;
//	}

	return docInfo;
}
void KSimBaseIntSpinBox::initRmbMenu(QPopupMenu * popup)
{
	Q_CHECK_PTR(popup);

	bool ok;
	int id;

	KSimBaseInt i = KSimBaseInt::convert(cleanText(), &ok);

	QPopupMenu * convertPopup = new QPopupMenu(popup, "convertPopup");
	Q_CHECK_PTR(convertPopup);

	id = convertPopup->insertItem(i18n("integer base", "Binary"), this, SLOT(slotConvertToBinary()));
	convertPopup->setItemEnabled(id, (i.base() != KSimBaseInt::Binary));

	id = convertPopup->insertItem(i18n("integer base", "Octal"), this, SLOT(slotConvertToOctal()));
	convertPopup->setItemEnabled(id, (i.base() != KSimBaseInt::Octal));

	id = convertPopup->insertItem(i18n("integer base", "Decimal"), this, SLOT(slotConvertToDecimal()));
	convertPopup->setItemEnabled(id, (i.base() != KSimBaseInt::Decimal));

	id = convertPopup->insertItem(i18n("integer base", "Hexadecimal"), this, SLOT(slotConvertToHexadecimal()));
	convertPopup->setItemEnabled(id, (i.base() != KSimBaseInt::Hexadecimal));


//	popup->insertSeparator();
	id = popup->insertItem(i18n("integer base", "Convert into"), convertPopup);
	popup->setItemEnabled(id, ok);



	if (m_p->constantList().count())
	{
		QPopupMenu * constantPopup = new QPopupMenu(popup, "constantPopup");
		Q_CHECK_PTR(constantPopup);

		Private::ConstantList::Iterator it(m_p->constantList().begin());

		for(; it != m_p->constantList().end(); ++it)
		{
			if ((*it).name().isEmpty())
			{
				(*it).setName((*it).value().text());
			}
			id = constantPopup->insertItem((*it).name());
			(*it).setIndex(id);
		}
		popup->insertSeparator();
		popup->insertItem(i18n("integer base", "Constants"), constantPopup);
	}
}
int KSimBaseIntSpinBox::mapTextToValue(bool * ok)
{
	bool myOk;
	KSimBaseInt i = KSimBaseInt::convert(cleanText(), &myOk);

	if (!myOk)
	{
		i = value();
	}

	if (ok)
	{
		*ok = myOk;
	}

	return setValueInternal(i);
}
示例#12
0
int KIntSpinBox::mapTextToValue(bool* ok)
{
    return cleanText().toInt(ok, val_base);
}
示例#13
0
/******************************************************************************
 * Convert the user-entered text to a value in minutes.
 * The allowed formats are:
 *    [hour]:[minute], where minute must be non-blank, or
 *    hhmm, 4 digits, where hour < 24.
 */
int TimeSpinBox::mapTextToValue(bool* ok)
{
    QString text = cleanText();
    int colon = text.find(':');
    if (colon >= 0)
    {
        // [h]:m format for any time value
        QString hour   = text.left(colon).stripWhiteSpace();
        QString minute = text.mid(colon + 1).stripWhiteSpace();
        if (!minute.isEmpty())
        {
            bool okmin;
            bool okhour = true;
            int m = minute.toUInt(&okmin);
            int h = 0;
            if (!hour.isEmpty())
                h = hour.toUInt(&okhour);
            if (okhour  &&  okmin  &&  m < 60)
            {
                if (m12Hour)
                {
                    if (h == 0  ||  h > 12)
                        h = 100;     // error
                    else if (h == 12)
                        h = 0;       // convert 12:nn to 0:nn
                    if (mPm)
                        h += 12;     // convert to PM
                }
                int t = h * 60 + m;
                if (t >= mMinimumValue  &&  t <= maxValue())
                {
                    if (ok)
                        *ok = true;
                    return t;
                }
            }
        }
    }
    else if (text.length() == 4)
    {
        // hhmm format for time of day
        bool okn;
        int mins = text.toUInt(&okn);
        if (okn)
        {
            int m = mins % 100;
            int h = mins / 100;
            if (m12Hour)
            {
                if (h == 0  ||  h > 12)
                    h = 100;    // error
                else if (h == 12)
                    h = 0;      // convert 12:nn to 0:nn
                if (mPm)
                    h += 12;    // convert to PM
            }
            int t = h * 60 + m;
            if (h < 24  &&  m < 60  &&  t >= mMinimumValue  &&  t <= maxValue())
            {
                if (ok)
                    *ok = true;
                return t;
            }
        }

    }
    if (ok)
        *ok = false;
    return 0;
}