Skip to content

Commit

Permalink
Add live conversions between numerical bases
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.kde.org/D24213
  • Loading branch information
umanovskis authored and Rolf Eike Beer committed Oct 15, 2019
1 parent 10a073a commit 1015fa9
Show file tree
Hide file tree
Showing 3 changed files with 373 additions and 209 deletions.
25 changes: 25 additions & 0 deletions kcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ KCalculator::KCalculator(QWidget *parent) :
base_choose_group_->addButton(binRadio, BinMode);
connect(base_choose_group_, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &KCalculator::slotBaseSelected);

base_conversion_labels_ = { binDisplay, hexDisplay, decDisplay, octDisplay };

angle_choose_group_ = new QButtonGroup(this);
angle_choose_group_->setExclusive(true);
angle_choose_group_->addButton(degRadio, DegMode);
Expand Down Expand Up @@ -1869,6 +1871,19 @@ void KCalculator::slotSetNumeralMode() {
KCalcSettings::setCalculatorMode(KCalcSettings::EnumCalculatorMode::numeral);
}

//------------------------------------------------------------------------------
// Name: slotBaseModeAmountChanged
// Desc: updates numerical base conversions
//------------------------------------------------------------------------------
void KCalculator::slotBaseModeAmountChanged(KNumber number) {
quint64 n = number.toUint64();

decDisplay->setText(QString::number(n, 10));
binDisplay->setText(QString::number(n, 2));
octDisplay->setText(QString::number(n, 8));
hexDisplay->setText(QString::number(n, 16).toUpper());
}

//------------------------------------------------------------------------------
// Name: showMemButtons
// Desc: hides or shows the memory buttons
Expand Down Expand Up @@ -1960,6 +1975,11 @@ void KCalculator::showLogicButtons(bool toggled) {
btn->show();
}

for (QLabel* lbl : base_conversion_labels_) {
lbl->show();
}
connect(calc_display, &KCalcDisplay::changedAmount, this, &KCalculator::slotBaseModeAmountChanged);

for (int i = 10; i < 16; ++i) {
(num_button_group_->button(i))->show();
}
Expand All @@ -1979,6 +1999,11 @@ void KCalculator::showLogicButtons(bool toggled) {
btn->hide();
}

for (QLabel* lbl : base_conversion_labels_) {
lbl->hide();
}
connect(calc_display, &KCalcDisplay::changedAmount, this, &KCalculator::slotBaseModeAmountChanged);

statusBar()->setBaseIndicatorVisible(false);
calc_display->setStatusText(BaseField, QString());
for (int i = 10; i < 16; ++i) {
Expand Down
4 changes: 4 additions & 0 deletions kcalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ protected Q_SLOTS:
void slotBitsetChanged(quint64);
void slotUpdateBitset(const KNumber &);

void slotBaseModeAmountChanged(KNumber number);

private:
enum StatusField {
ShiftField = 0,
Expand Down Expand Up @@ -265,6 +267,8 @@ protected Q_SLOTS:
QList<QAbstractButton*> stat_buttons_;
QList<QAbstractButton*> const_buttons_;

std::array<QLabel*, 4> base_conversion_labels_;

KToggleAction *action_bitset_show_;
KToggleAction *action_constants_show_;

Expand Down
Loading

0 comments on commit 1015fa9

Please sign in to comment.