Index: kcalcdisplay.cpp =================================================================== --- kcalcdisplay.cpp (revision 568278) +++ kcalcdisplay.cpp (working copy) @@ -286,6 +286,7 @@ } setText(display_str); + emit changedAmount(_display_amount); return true; } @@ -415,7 +416,7 @@ default: return false; } - + emit changedAmount(_display_amount); return true; } Index: kcalc.cpp =================================================================== --- kcalc.cpp (revision 568278) +++ kcalc.cpp (working copy) @@ -71,9 +71,9 @@ #include "constants.h" #include #include "kcalc_settings.h" +#include "kcalc_bitset.h" - static const char description[] = I18N_NOOP("KDE Calculator"); static const char version[] = KCALCVERSION; @@ -121,11 +121,6 @@ "Octal-Switch"); QToolTip::add(pbBaseChoose[2], i18n("Switch base to octal.")); - pbBaseChoose[3] = new QRadioButton(i18n("&Bin"), BaseChooseGroup, - "Binary-Switch"); - QToolTip::add(pbBaseChoose[3], i18n("Switch base to binary.")); - - // Create Button to select AngleMode pbAngleChoose = new QPushButton(i18n("&Angle"), central, "ChooseAngleMode-Button"); @@ -151,6 +146,10 @@ pbInv, SLOT(slotSetAccelDisplayMode(bool))); pbInv->setToggleButton(true); + // Create Bitset Display + mBitset = new KCalcBitset(central); + QToolTip::add(mBitset, i18n("Click on a Bit to toggle it.")); + // // Create Calculator Buttons // @@ -237,16 +236,20 @@ mInternalSpacing); QHBoxLayout *topLayout = new QHBoxLayout(); + QHBoxLayout *mdlLayout = new QHBoxLayout(); QHBoxLayout *btnLayout = new QHBoxLayout(); + // bring them all together QVBoxLayout *mainLayout = new QVBoxLayout(central, mInternalSpacing, mInternalSpacing); mainLayout->addLayout(topLayout); + mainLayout->addLayout(mdlLayout); mainLayout->addLayout(btnLayout); // button layout + mdlLayout->addWidget(mBitset, 0, AlignTop); btnLayout->addWidget(mSmallPage, 0, AlignTop); btnLayout->addSpacing(2*mInternalSpacing); btnLayout->addWidget(mNumericPage, 0, AlignTop); @@ -1123,11 +1126,6 @@ // set display & statusbar (if item exist in statusbar) switch(base) { - case 3: - current_base = calc_display->setBase(NumBase(2)); - if (statusBar()->hasItem(1)) statusBar()->changeItem("BIN",1); - calc_display->setStatusText(1, "Bin"); - break; case 2: current_base = calc_display->setBase(NumBase(8)); if (statusBar()->hasItem(1)) statusBar()->changeItem("OCT",1); @@ -1993,7 +1991,13 @@ { if(toggled) { - pbLogic["AND"]->show(); + mBitset->show(); + connect(mBitset, SIGNAL(valueChanged(unsigned long long)), + this, SLOT(slotBitsetChanged(unsigned long long))); + connect(calc_display, SIGNAL(changedAmount(const KNumber &)), + SLOT(slotUpdateBitset(const KNumber &))); + + pbLogic["AND"]->show(); pbLogic["OR"]->show(); pbLogic["XOR"]->show(); pbLogic["One-Complement"]->show(); @@ -2010,7 +2014,12 @@ } else { - pbLogic["AND"]->hide(); + mBitset->hide(); + disconnect(mBitset, SIGNAL(valueChanged(unsigned long long)), + this, SLOT(slotBitsetChanged(unsigned long long))); + disconnect(calc_display, SIGNAL(changedAmount(const KNumber &)), + this, SLOT(slotUpdateBitset(const KNumber &))); + pbLogic["AND"]->hide(); pbLogic["OR"]->hide(); pbLogic["XOR"]->hide(); pbLogic["One-Complement"]->hide(); @@ -2087,6 +2096,15 @@ if(actionConstantsShow->isChecked()) actionConstantsShow->activate(); } +void KCalculator::slotBitsetChanged(unsigned long long value) { + calc_display->setAmount(value); + UpdateDisplay(false); +} + +void KCalculator::slotUpdateBitset(const KNumber &nr) { + mBitset->setValue(nr); +} + void KCalculator::updateSettings() { changeButtonNames(); Index: kcalc_bitset.cpp =================================================================== --- kcalc_bitset.cpp (revision 0) +++ kcalc_bitset.cpp (revision 0) @@ -0,0 +1,102 @@ +/* + Copyright (C) 2006 Michel Marti + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include +#include + +#include "kcalc_bitset.h" + +KCalcBitset::KCalcBitset( QWidget *parent, const char *name ) + : QFrame(parent, name), mValue(0) +{ + setFrameStyle( QFrame::Panel | QFrame::Sunken ); + QGridLayout *layout = new QGridLayout(this, 4, 8, 2, 0); + + for( int i=0, r=0; r<3; r+=2 ) + { + for(int c=0; c<8; c++) + { + // Labels on column 0, 4, 7 + if(c==0 || c ==4 || c==7) + { + QLabel *label = new QLabel(this); + int bn = 63-i; + if(c==7) + { + label->setAlignment(Qt::AlignRight); + bn-=3; + } + label->setText(QString::number(bn)); + label->setPaletteForegroundColor(QColor(0,0,255)); + layout->addWidget(label, r+1,c); + } + QHBox *box = new QHBox(this); + layout->addWidget(box, r, c); + for( int b=0; b<4; b++ ) + { + mBits[i]=new QLabel(box, QString::number(i).ascii()); + mBits[i]->installEventFilter(this); + mBits[i]->setText("0"); + i++; + } + if(c != 7 ) + { + // Add a "spacer" + QLabel *sp = new QLabel(box); + sp->setMinimumWidth(5); + } + } + } + +} + + +void KCalcBitset::setValue(unsigned long long value) +{ + mValue=value; + for(int i=0; i<64; i++) + { + mBits[63-i]->setText(value&1?"1":"0"); + value>>=1; + } +} + +unsigned long long KCalcBitset::getValue() +{ + return mValue; +} + +bool KCalcBitset::eventFilter( QObject *o, QEvent *e ) +{ + if(e->type() == QEvent::MouseButtonPress && o->isA("QLabel") ) + { + QString name(o->name()); + bool ok; + int bit = 63-name.toInt(&ok); + if(ok) + { + unsigned long long nv = getValue()^(1LL< /* @@ -157,6 +158,9 @@ void slotChooseScientificConst4(int option); void slotChooseScientificConst5(int option); + void slotBitsetChanged(unsigned long long); + void slotUpdateBitset(const KNumber &); + private: bool inverse; bool hyp_mode; @@ -172,12 +176,14 @@ private: + QWidget *mSmallPage; QWidget *mLargePage; QWidget *mNumericPage; + KCalcBitset *mBitset; DispLogic* calc_display; // for historic reasons in "dlabel.h" - QRadioButton* pbBaseChoose[4]; + QRadioButton* pbBaseChoose[3]; QPushButton* pbAngleChoose; QDict pbStat; QDict pbScientific; Index: Makefile.am =================================================================== --- Makefile.am (revision 568278) +++ Makefile.am (working copy) @@ -8,7 +8,7 @@ kcalc_la_SOURCES = kcalc.cpp kcalc_button.cpp kcalc_const_button.cpp \ kcalc_const_menu.cpp kcalc_core.cpp kcalcdisplay.cpp \ - dlabel.cpp stats.cpp colors.ui general.ui \ + dlabel.cpp stats.cpp kcalc_bitset.cpp colors.ui general.ui \ constants.ui kcalc_settings.kcfgc @@ -16,7 +16,7 @@ noinst_HEADERS = kcalc.h kcalc_button.h kcalc_const_button.h \ kcalc_const_menu.h kcalc_core.h kcalcdisplay.h \ - kcalctype.h dlabel.h stats.h + kcalctype.h dlabel.h stats.h kcalc_bitset.h kcalc_la_LDFLAGS = $(all_libraries) -module -avoid-version kcalc_la_LIBADD = $(LIB_KDEUI) knumber/libknumber.la Index: kcalc_bitset.h =================================================================== --- kcalc_bitset.h (revision 0) +++ kcalc_bitset.h (revision 0) @@ -0,0 +1,43 @@ +/* + Copyright (C) 2006 Michel Marti + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ +#ifndef _KCALC_BITSET_H_ +#define _KCALC_BITSET_H_ + +#include +#include + +class KCalcBitset : public QFrame +{ +Q_OBJECT +public: + KCalcBitset( QWidget *parent=0, const char *name=0 ); + unsigned long long getValue(); +public slots: + void setValue( unsigned long long value ); +signals: + void valueChanged( unsigned long long value ); +protected: + bool eventFilter( QObject *o, QEvent *e ); +private: + QLabel *mBits[64]; + unsigned long long mValue; +}; + +#endif +