Changeset View
Changeset View
Standalone View
Standalone View
kcalc.cpp
Show First 20 Lines • Show All 1535 Lines • ▼ Show 20 Line(s) | |||||
1536 | 1536 | | |||
1537 | //------------------------------------------------------------------------------ | 1537 | //------------------------------------------------------------------------------ | ||
1538 | // Name: slotConstclicked | 1538 | // Name: slotConstclicked | ||
1539 | // Desc: enters a constant | 1539 | // Desc: enters a constant | ||
1540 | //------------------------------------------------------------------------------ | 1540 | //------------------------------------------------------------------------------ | ||
1541 | void KCalculator::slotConstclicked(int button) { | 1541 | void KCalculator::slotConstclicked(int button) { | ||
1542 | 1542 | | |||
1543 | if(KCalcConstButton *btn = qobject_cast<KCalcConstButton*>(const_buttons_[button])) { | 1543 | if(KCalcConstButton *btn = qobject_cast<KCalcConstButton*>(const_buttons_[button])) { | ||
1544 | // Constants are stored in a C locale way to ensure they can be read correctly | ||||
1545 | // by instances of KCalc with different locale settings. | ||||
1546 | const QChar localeCDecimalPoint(QLatin1Char('.')); | ||||
1547 | const QChar localeCGroupSeparator(QLatin1Char(',')); | ||||
1548 | const bool groupSeparatorEnabled = KCalcSettings::groupDigits() && | ||||
1549 | !(QLocale().numberOptions() & QLocale::OmitGroupSeparator); | ||||
1550 | | ||||
1544 | if (!shift_mode_) { | 1551 | if (!shift_mode_) { | ||
1545 | // set the display to the configured value of constant button | 1552 | // set the display to the configured value of constant button | ||
1546 | // internally, we deal with C locale style numbers, we need to convert | | |||
1547 | QString val = btn->constant(); | 1553 | QString val = btn->constant(); | ||
1548 | val.replace(QLatin1Char('.'), KNumber::decimalSeparator()); | 1554 | if (groupSeparatorEnabled) | ||
1555 | val.remove(localeCGroupSeparator); | ||||
1556 | val.replace(localeCDecimalPoint, KNumber::decimalSeparator()); | ||||
1549 | calc_display->setAmount(KNumber(val)); | 1557 | calc_display->setAmount(KNumber(val)); | ||
1550 | | ||||
1551 | } else { | 1558 | } else { | ||
1552 | pbShift->setChecked(false); | 1559 | pbShift->setChecked(false); | ||
1553 | 1560 | | |||
1554 | // internally, we deal with C locale style numbers, we need to convert | | |||
1555 | QString val = calc_display->text(); | 1561 | QString val = calc_display->text(); | ||
1556 | val.replace(KNumber::decimalSeparator(), QLatin1String(".")); | 1562 | for (QChar &c : val) { | ||
1563 | if (c == KNumber::decimalSeparator()) | ||||
1564 | c = localeCDecimalPoint; | ||||
1565 | else if (groupSeparatorEnabled && (c == KNumber::groupSeparator())) | ||||
1566 | c = localeCGroupSeparator; | ||||
1567 | } | ||||
1557 | KCalcSettings::setValueConstant(button, val); | 1568 | KCalcSettings::setValueConstant(button, val); | ||
1558 | 1569 | | |||
1559 | // below set new tooltip | 1570 | // below set new tooltip | ||
1560 | btn->setLabelAndTooltip(); | 1571 | btn->setLabelAndTooltip(); | ||
1561 | 1572 | | |||
1562 | // work around: after storing a number, pressing a digit should start | 1573 | // work around: after storing a number, pressing a digit should start | ||
1563 | // a new number | 1574 | // a new number | ||
1564 | calc_display->setAmount(calc_display->getAmount()); | 1575 | calc_display->setAmount(calc_display->getAmount()); | ||
▲ Show 20 Lines • Show All 772 Lines • Show Last 20 Lines |