diff --git a/curconvd/converter.cpp b/curconvd/converter.cpp index 6179e9b..bc5bfae 100644 --- a/curconvd/converter.cpp +++ b/curconvd/converter.cpp @@ -1,115 +1,114 @@ /*************************************************************************** converter.cpp - d-bus service ------------------- begin : lun nov 13 11:22:05 CET 2006 copyright : (C) 2006-2018 by Éric Bischoff email : ebischoff@nerim.net ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include #include #include #include #include "converter.h" -#include "converter.moc" #include "table.h" // Constructor CurrencyConverter::CurrencyConverter() : QObject(), serialNumber(0) { QDBusConnection::sessionBus().registerService("org.kde.curconvd"); QDBusConnection::sessionBus().registerObject("/CurrencyConverter", this, QDBusConnection::ExportScriptableSlots); printf( "%s\n", (const char *) i18n("curconvd: waiting for D-Bus requests").toUtf8() ); } // Destructor CurrencyConverter::~CurrencyConverter() { QDBusConnection::sessionBus().unregisterObject("/CurrencyConverter"); QDBusConnection::sessionBus().unregisterService("org.kde.curconvd"); printf( "%s\n", (const char *) i18n("curconvd: stopped waiting for D-Bus requests").toUtf8() ); } // List available data sources QStringList CurrencyConverter::DataSources() { QStringList dataSources; printf( "curconvd: /CurrencyConverter/DataSources()\n" ); dataSources << QString("(fixed)"); dataSources << QString("http://www.ecb.int"); // dataSources << QString("http://www.newyorkfed.org"); dataSources << QString("http://rss.timegenie.com"); return dataSources; } // List available rounding methods QStringList CurrencyConverter::RoundingMethods() { QStringList roundingMethods; printf( "curconvd: /CurrencyConverter/RoundingMethods()\n" ); roundingMethods << QString("none"); roundingMethods << QString("official rules"); roundingMethods << QString("smallest coin"); return roundingMethods; } // Gives the reference currency for a data source QString CurrencyConverter::ReferenceCurrency(const QString &dataSource) { QString reference; printf( "curconvd: /CurrencyConverter/ReferenceCurrency(\"%s\")\n", dataSource.toUtf8().data() ); if (dataSource == "(fixed)") reference = "EUR"; else if (dataSource == "http://www.ecb.int") reference = "EUR"; // else if (dataSource == "http://www.newyorkfed.org") // reference = "USD"; else if (dataSource == "http://rss.timegenie.com") reference = "USD"; else reference = ""; return reference; } // Load currencies from data source QString CurrencyConverter::LoadSource(const QString &dataSource, const QString &roundingMethod) { QString tablePath; CurrencyTable *table; printf( "curconvd: /CurrencyConverter/LoadSource(\"%s\", \"%s\")\n", dataSource.toUtf8().data(), roundingMethod.toUtf8().data() ); tablePath = QString( "/CurrencyConverter/tables/%1" ).arg( ++serialNumber ); table = new CurrencyTable(tablePath); table->loadSource(dataSource, roundingMethod); return tablePath; } diff --git a/curconvd/table.cpp b/curconvd/table.cpp index b5fe1ae..6f8340d 100644 --- a/curconvd/table.cpp +++ b/curconvd/table.cpp @@ -1,245 +1,244 @@ /*************************************************************************** table.cpp - conversion table ------------------- begin : jeu nov 23 21:03:30 CET 2006 copyright : (C) 2006-2018 by Éric Bischoff email : ebischoff@nerim.net ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include #include #include #include #include "table.h" -#include "table.moc" // Constructor CurrencyTable::CurrencyTable(const QString &tablePath) : Currencies(), path( tablePath ), rounding( NO_ROUNDING ) { QDBusConnection::sessionBus().registerObject(path, this, QDBusConnection::ExportScriptableSlots); printf( "curconvd: table \"%s\" created\n", path.toUtf8().data()); } // Destructor CurrencyTable::~CurrencyTable() { QDBusConnection::sessionBus().unregisterObject(path); printf( "curconvd: table \"%s\" destroyed\n", path.toUtf8().data()); } // Load currencies from data source void CurrencyTable::loadSource(const QString &dataSource, const QString &roundingMethod) { if ( !readCurrencies( "currencies.xml" ) ) { fprintf(stderr, "Cannot load currencies.xml" ); exit(1); // TODO: Less violent exit } clearRates(); if (roundingMethod == "official rules") rounding = OFFICIAL_RULES; else if (roundingMethod == "smallest coin") rounding = SMALLEST_COIN; else rounding = NO_ROUNDING; if (dataSource == "(fixed)") { addFixedRates( rounding ); // endDownload is called here } else if (dataSource == "http://www.ecb.int") { addFixedRates( rounding, true ); // endDownload is called here for the first time addECBRates( rounding ); // endDowload is called again when completed } // else if (dataSource == "http://www.newyorkfed.org") // { // addNY_FRBRates( rounding ); // // endDowload is called when completed // } else if (dataSource == "http://rss.timegenie.com") { addFixedRates( rounding, true ); // endDownload is called here for the first time addECBRates( rounding ); // endDowload is called again when completed } } // Download has ended void CurrencyTable::endDownload(int defaultCurrency, const QString &date) { printf("Here\n"); // TODO: if defaultCurrency is not null, inform that a result is available } // List currencies handled QStringList CurrencyTable::AvailableCurrencies() { QStringList codes; printf( "curconvd: %s/AvailableCurrencies()\n", path.toUtf8().data()); for (int num = 0; num < number(); num++) if ( position(num) == -2 ) codes << QString(code(num)); return codes; } // Gives the everyday symbol for a given currency code QString CurrencyTable::Symbol(const QString ¤cyCode) { QString currencySymbol; int num; printf( "curconvd: %s/Symbol(\"%s\")\n", path.toUtf8().data(), currencyCode.toUtf8().data()); for (num = 0; num < number(); num++) if ( code(num) == currencyCode ) break; if (num == number()) currencySymbol = ""; // TODO: return an error code here else currencySymbol = symbol(num); return currencySymbol; } // Gives the description for a given currency code QString CurrencyTable::Name(const QString ¤cyCode) { QString currencyName; int num; printf( "curconvd: %s/Name(\"%s\")\n", path.toUtf8().data(), currencyCode.toUtf8().data()); for (num = 0; num < number(); num++) if ( code(num) == currencyCode ) break; if (num == number()) currencyName = ""; // TODO: return an error code here else currencyName = name(num); return currencyName; } // Convert an amount expressed in the reference currency double CurrencyTable::ConvertFromReference(const QString ¤cyCode, double referenceValue) { double currencyValue; int num; printf( "curconvd: %s/ConvertFromReference(\"%s\", %g)\n", path.toUtf8().data(), currencyCode.toUtf8().data(), referenceValue); for (num = 0; num < number(); num++) if ( code(num) == currencyCode ) break; if (num == number()) currencyValue = 0.0; // TODO: return an error code here else { double currencyRate, currencyPrecision; currencyRate = rate(num); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = officialRulesPrecision(num); currencyValue = floor(referenceValue * currencyRate * 100.0 + 0.5) / 100.0 * currencyPrecision; break; case SMALLEST_COIN: currencyPrecision = smallestCoinPrecision(num); currencyValue = floor(referenceValue * currencyRate * 100.0 + 0.5) / 100.0 * currencyPrecision; break; default: currencyValue = referenceValue * currencyRate; } } return currencyValue; } // Convert an amount expressed in the given currency double CurrencyTable::ConvertToReference(const QString ¤cyCode, double currencyValue) { double referenceValue; int num; printf( "curconvd: %s/ConvertToReference(\"%s\", %g)\n", path.toUtf8().data(), currencyCode.toUtf8().data(), currencyValue); for (num = 0; num < number(); num++) if ( code(num) == currencyCode ) break; if (num == number()) referenceValue = 0.0; // TODO: return an error code here else { double currencyRate, currencyPrecision; currencyRate = rate(num); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = officialRulesPrecision(num); referenceValue = floor( currencyValue / currencyRate / currencyPrecision * 100.0 + 0.5) / 100.0; break; case SMALLEST_COIN: currencyPrecision = smallestCoinPrecision(num); referenceValue = floor( currencyValue / currencyRate / currencyPrecision * 100.0 + 0.5) / 100.0; break; default: referenceValue = currencyValue / currencyRate; } } return referenceValue; } // Unload this currencies table void CurrencyTable::Unload() { printf( "curconvd: %s/Unload()\n", path.toUtf8().data()); delete this; } diff --git a/currencies/currencies.cpp b/currencies/currencies.cpp index bb91f5b..b48c3fc 100644 --- a/currencies/currencies.cpp +++ b/currencies/currencies.cpp @@ -1,370 +1,369 @@ /*************************************************************************** currencies.cpp - list of currencies ------------------- begin : sam déc 1 23:40:19 CET 2001 copyright : (C) 2001-2018 by Éric Bischoff email : ebischoff@nerim.net ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include #include #include #include #include #include "currencies.h" -#include "currencies.moc" static const char *urlECB = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml", // *urlNY_FRB = "http://www.newyorkfed.org/markets/fxrates/FXtoXML.cfm?FEXdate=%04d-%02d-%02d&FEXtime=1200", *urlTG = "http://rss.timegenie.com/forex2.xml"; // Constructor Currencies::Currencies() : QObject(), variableRates() { currency = 0; } // Denstructor Currencies::~Currencies() { if (currency) delete [] currency; } // Read currencies list bool Currencies::readCurrencies( const char *filename ) { QDomDocument document( "currencies" ); QFile file( QStandardPaths::locate(QStandardPaths::AppDataLocation, filename) ); if ( !file.open( QIODevice::ReadOnly ) ) return false; if ( !document.setContent( &file ) ) { file.close(); return false; } file.close(); QDomNodeList currenciesList = document.elementsByTagName( "currency" ); int num; QString name; numCurrencies = currenciesList.count(); if (currency) delete [] currency; currency = new currencyStruc[numCurrencies]; for (num = 0; num < numCurrencies; num++) { QDomElement elt = currenciesList.item(num).toElement(); if ( !elt.hasAttribute( "symbol" ) ) return false; currency[num].symbol = elt.attribute( "symbol" ); if ( !elt.hasAttribute( "code" ) ) return false; currency[num].code = elt.attribute( "code" ); if ( currency[num].code == "USD" ) dollarCurrency = num; else if ( currency[num].code == "EUR" ) euroCurrency = num; if ( !elt.hasAttribute( "official-rules-precision" ) ) return false; currency[num].officialRulesPrecision = elt.attribute( "official-rules-precision" ).toDouble(); if ( !elt.hasAttribute( "smallest-coin-precision" ) ) return false; currency[num].smallestCoinPrecision = elt.attribute( "smallest-coin-precision" ).toDouble(); if ( !elt.hasAttribute( "name" ) ) return false; name = elt.attribute( "name" ); currency[num].name = i18n( name.toUtf8().data() ); if ( elt.hasAttribute( "new-york-name" ) ) currency[num].newYorkName = elt.attribute( "new-york-name" ); else currency[num].newYorkName = "N/A"; if ( elt.hasAttribute( "fixed-rate" ) ) currency[num].fixedRate = elt.attribute( "fixed-rate" ).toDouble(); else currency[num].fixedRate = 0.0; currency[num].rate = 1.0; currency[num].position = -1; } return true; } // Clear rates void Currencies::clearRates() { int num; for (num = 0; num < numCurrencies; num++) { currency[num].rate = 1.0; currency[num].position = -1; } } // Add fixed rates void Currencies::addFixedRates( int rounding, bool someMoreToCome ) { int num; double currencyPrecision; QString blank(""); for (num = 0; num < numCurrencies; num++) if ( currency[num].fixedRate ) { switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currency[num].officialRulesPrecision; break; case SMALLEST_COIN: currencyPrecision = currency[num].smallestCoinPrecision; break; default: currencyPrecision = 1.0; } currency[num].rate = currency[num].fixedRate / currencyPrecision; currency[num].position = -2; } endDownload( someMoreToCome? 0: euroCurrency, blank ); } // Add variable rates from European Central Bank void Currencies::addECBRates( int rounding ) { KIO::TransferJob *job; roundingMethod = rounding; job = KIO::get( QUrl( urlECB ), KIO::Reload, KIO::HideProgressInfo ); connect( job, SIGNAL(data(KIO::Job *, const QByteArray &)), this, SLOT(httpDataECB(KIO::Job *, const QByteArray &)) ); } // Add variable rates from New York Federal Reserve Bank //void Currencies::addNY_FRBRates( int rounding ) //{ // char url[128]; // QDate yesterday; // KIO::TransferJob *job; // // roundingMethod = rounding; // // yesterday = QDate::currentDate().addDays(-1); // // This is suboptimal: we should guess the date of latest working day at 12:00 in New York local time // // Or much better: use a URL that does not depend on that date... // sprintf(url, urlNY_FRB, yesterday.year(), yesterday.month(), yesterday.day()); // job = KIO::get( QUrl( url ), KIO::Reload, KIO::HideProgressInfo ); // connect( job, SIGNAL(data(KIO::Job *, const QByteArray &)), // this, SLOT(httpDataNY_FRB(KIO::Job *, const QByteArray &)) // ); //} // Add variable rates from Time Genie foreign exchange void Currencies::addTGRates( int rounding ) { KIO::TransferJob *job; roundingMethod = rounding; job = KIO::get( QUrl( urlTG ), KIO::Reload, KIO::HideProgressInfo ); connect( job, SIGNAL(data(KIO::Job *, const QByteArray &)), this, SLOT(httpDataTG(KIO::Job *, const QByteArray &)) ); } // Exchange rates received from European Central Bank void Currencies::httpDataECB(KIO::Job *job, const QByteArray &array) { job = 0; // Unused parameter if ( array.size() ) { variableRates += QString(array); } else { QDomDocument document( "rates" ); document.setContent( variableRates, true ); QDomNodeList ratesList = document.elementsByTagName( "Cube" ); QString date; int num; double currencyPrecision; for (int i = 0; i < ratesList.count(); i++) { QDomElement elt = ratesList.item(i).toElement(); if ( elt.hasAttribute( "time" ) ) date = elt.attribute( "time" ); else if ( elt.hasAttribute( "currency" ) && elt.hasAttribute( "rate" ) ) { QString code(elt.attribute( "currency" )); for (num = 0; num < numCurrencies; num++) if ( code == currency[num].code ) break; if ( num < numCurrencies ) { switch (roundingMethod) { case OFFICIAL_RULES: currencyPrecision = currency[num].officialRulesPrecision; break; case SMALLEST_COIN: currencyPrecision = currency[num].smallestCoinPrecision; break; default: currencyPrecision = 1.0; } currency[num].rate = elt.attribute( "rate" ).toDouble() / currencyPrecision; currency[num].position = -2; } } } variableRates = ""; endDownload( euroCurrency, date ); } } // Exchange rates received from New York Federal Reserve Bank //void Currencies::httpDataNY_FRB(KIO::Job *job, const QByteArray &array) //{ // static const char *frbny = "http://www.newyorkfed.org/xml/schemas/FX/utility"; // // job = 0; // Unused parameter // // if ( array.size() ) // { // variableRates += QString(array); // } // else // { // QDomDocument document( "rates" ); // // document.setContent( variableRates, true ); // // QDomNodeList ratesList = document.elementsByTagNameNS( frbny, "Series" ); // QString date; // int num; // double currencyPrecision; // // for (int i = 0; i < ratesList.count(); i++) // { // QDomElement elt = ratesList.item(i).toElement(); // QDomNodeList dateElements = elt.elementsByTagNameNS( frbny, "TIME_PERIOD" ), // currencyElements = elt.elementsByTagNameNS( frbny, "CURR" ), // valueElements = elt.elementsByTagNameNS( frbny, "OBS_VALUE" ); // if (dateElements.count() == 1 && currencyElements.count() == 1 && valueElements.count() == 1) // { // QDomElement dateElement = dateElements.item(0).toElement(), // currencyElement = currencyElements.item(0).toElement(), // valueElement = valueElements.item(0).toElement(); // QString code( // elt.attribute( "UNIT" ) == "USD" ? // currencyElement.text(): // elt.attribute( "UNIT" ) // ); // for (num = 0; num < numCurrencies; num++) // if ( code == currency[num].code ) // break; // if ( num < numCurrencies ) // { // switch (roundingMethod) // { // case OFFICIAL_RULES: // currencyPrecision = currency[num].officialRulesPrecision; // break; // case SMALLEST_COIN: // currencyPrecision = currency[num].smallestCoinPrecision; // break; // default: // currencyPrecision = 1.0; // } // if ( elt.attribute( "UNIT" ) != "USD" ) // currency[num].rate = // valueElement.text().toDouble() / currencyPrecision; // else currency[num].rate = // ( 1.0 / valueElement.text().toDouble() ) / currencyPrecision; // currency[num].position = -2; // if ( date.isNull() ) // date = dateElement.text(); // } // } // } // variableRates = ""; // endDownload( dollarCurrency, date ); // } //} // Exchange rates received from Time Genie foreign exchange void Currencies::httpDataTG(KIO::Job *job, const QByteArray &array) { job = 0; // Unused parameter if ( array.size() ) { variableRates += QString(array); } else { QDomDocument document( "forex" ); document.setContent( variableRates, true ); QDomNodeList ratesList = document.elementsByTagName( "currency" ); QString date; int num; double currencyPrecision; for (int i = 0; i < ratesList.count(); i++) { QDomElement elt = ratesList.item(i).toElement(); if ( elt.hasAttribute( "code" ) && elt.hasAttribute( "rate" ) ) { QString code(elt.attribute( "code" )); for (num = 0; num < numCurrencies; num++) if ( code == currency[num].code ) break; if ( num < numCurrencies ) { switch (roundingMethod) { case OFFICIAL_RULES: currencyPrecision = currency[num].officialRulesPrecision; break; case SMALLEST_COIN: currencyPrecision = currency[num].smallestCoinPrecision; break; default: currencyPrecision = 1.0; } currency[num].rate = elt.attribute( "rate" ).toDouble() / currencyPrecision; currency[num].position = -2; } } } variableRates = ""; endDownload( euroCurrency, date ); } } diff --git a/keurocalc/keurocalc.cpp b/keurocalc/keurocalc.cpp index fc8287d..cfba22f 100644 --- a/keurocalc/keurocalc.cpp +++ b/keurocalc/keurocalc.cpp @@ -1,1331 +1,1330 @@ /*************************************************************************** keurocalc.cpp - main widget ------------------- begin : sam déc 1 23:40:19 CET 2001 copyright : (C) 2001-2018 by Éric Bischoff email : ebischoff@nerim.net ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "keurocalc.h" #include "ui_calculator.h" -#include "keurocalc.moc" #include "preferences.h" static const char *euroSymbol = " €"; // *dollarSymbol = " $"; // Constructor KEuroCalc::KEuroCalc(QWidget *parent) : QDialog(parent), Ui::Calculator(), currencies() { int position; QPalette palette; setupUi(this); QDBusConnection::sessionBus().registerObject ("/KEuroCalc", this, QDBusConnection::ExportScriptableSlots); connect( ¤cies, SIGNAL(endDownload(int, const QString &)), this, SLOT(endDownload(int, const QString &)) ); c_locale = newlocale(LC_NUMERIC_MASK, "C", NULL); isSimpleValue = false; simpleValue = 0.0; referenceValue = 0.0; currencyValue = 0.0; memorySet = false; isSimpleMemory = false; simpleMemory = 0.0; referenceMemory = 0.0; if ( !currencies.readCurrencies( "currencies.xml" ) ) { KMessageBox::error( 0, i18n( "Cannot load currencies.xml" ) ); exit(1); } readOptions( reference, currencyNum, rounding, displayColor, splashScreen ); displayNewCurrency(); displayNewResult(); resetInput(); initButtons(); startDownload(); position = currencies.position(currencyNum); if (position < 0) position = 0; CurrencyList->setCurrentIndex( position ); palette.setColor( backgroundRole(), displayColor ); ResultDisplay->setPalette( palette ); InputDisplay->setPalette( palette ); OperatorDisplay->setPalette( palette ); setFocusPolicy( Qt::StrongFocus ); } // Destructor KEuroCalc::~KEuroCalc() { freelocale(c_locale); } // Is splash screen to be displayed ? bool KEuroCalc::readSplashScreen() const { KConfigGroup config(KSharedConfig::openConfig(), "General"); QString option; option = config.readEntry("SplashScreen", "yes"); return option == "yes"; } // Read options from preferences file void KEuroCalc::readOptions(int &oldReference, int &oldCurrency, int &oldRounding, QColor &oldDisplayColor, bool &oldSplashScreen) const { KConfigGroup config(KSharedConfig::openConfig(), "General"); QString option; option = config.readEntry("Reference", "EURO_ECB"); if (option == "EURO_FIXED") oldReference = EURO_FIXED; else if (option == "EURO_ECB") oldReference = EURO_ECB; // else if (option == "DOLLAR_NY_FRB") // oldReference = DOLLAR_NY_FRB; else if (option == "EURO_TG") oldReference = EURO_TG; else oldReference = EURO_ECB; option = config.readEntry("Currency", "USD"); for (oldCurrency = 0; oldCurrency < currencies.number(); oldCurrency++) if ( option == currencies.code(oldCurrency) ) break; if ( oldCurrency == currencies.number() ) oldCurrency = currencies.dollar(); option = config.readEntry("Rounding", "OFFICIAL_RULES"); if (option == "OFFICIAL_RULES") oldRounding = OFFICIAL_RULES; else if (option == "SMALLEST_COIN") oldRounding = SMALLEST_COIN; else if (option == "NO_ROUNDING") oldRounding = NO_ROUNDING; else oldRounding = OFFICIAL_RULES; option = config.readEntry("DiplayColor", "#C0FFFF"); oldDisplayColor.setNamedColor(option); option = config.readEntry("SplashScreen", "yes"); oldSplashScreen = option == "yes"; } // Write options to preferences file void KEuroCalc::writeOptions(int newReference, int newCurrency, int newRounding, const QColor &newDisplayColor, bool newSplashScreen) { KConfigGroup config(KSharedConfig::openConfig(), "General"); switch (newReference) { case EURO_FIXED: config.writeEntry("Reference", "EURO_FIXED"); break; case EURO_ECB: config.writeEntry("Reference", "EURO_ECB"); break; // case DOLLAR_NY_FRB: // config.writeEntry("Reference", "DOLLAR_NY_FRB"); // break; case EURO_TG: config.writeEntry("Reference", "EURO_TG"); } config.writeEntry("Currency", currencies.code(newCurrency) ); switch (newRounding) { case OFFICIAL_RULES: config.writeEntry("Rounding", "OFFICIAL_RULES"); break; case SMALLEST_COIN: config.writeEntry("Rounding", "SMALLEST_COIN"); break; case NO_ROUNDING: config.writeEntry("Rounding", "NO_ROUNDING"); } config.writeEntry("DiplayColor", newDisplayColor.name()); config.writeEntry("SplashScreen", newSplashScreen? "yes": "no"); config.sync(); } // Set new preferences dialog void KEuroCalc::setPreferences(int newReference, int newCurrency, int newRounding, const QColor &newDisplayColor, bool newSplashScreen) { reference = newReference; currencyNum = newCurrency; rounding = newRounding; displayColor = newDisplayColor; splashScreen = newSplashScreen; CurrencyList->clear(); initButtons(); startDownload(); Reset(); } // Handle key press events void KEuroCalc::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_Period: case Qt::Key_Comma: inputDigit('.'); break; case Qt::Key_0: ZeroButton->animateClick(); break; case Qt::Key_1: OneButton->animateClick(); break; case Qt::Key_2: TwoButton->animateClick(); break; case Qt::Key_3: ThreeButton->animateClick(); break; case Qt::Key_4: FourButton->animateClick(); break; case Qt::Key_5: FiveButton->animateClick(); break; case Qt::Key_6: SixButton->animateClick(); break; case Qt::Key_7: SevenButton->animateClick(); break; case Qt::Key_8: EightButton->animateClick(); break; case Qt::Key_9: NineButton->animateClick(); break; case Qt::Key_Plus: PlusButton->animateClick(); break; case Qt::Key_Minus: MinusButton->animateClick(); break; case Qt::Key_Asterisk: AsteriskButton->animateClick(); break; case Qt::Key_Slash: SlashButton->animateClick(); break; case Qt::Key_Backspace: BackspaceButton->animateClick(); break; case Qt::Key_E: case Qt::Key_Dollar: ReferenceButton->animateClick(); break; case Qt::Key_Percent: PercentButton->animateClick(); break; case Qt::Key_Enter: case Qt::Key_Return: SimpleValueButton->animateClick(); break; case Qt::Key_S: PlusMinusButton->animateClick(); break; case Qt::Key_Shift: case Qt::Key_Control: case Qt::Key_Meta: case Qt::Key_Alt: case Qt::Key_CapsLock: case Qt::Key_NumLock: case Qt::Key_ScrollLock: break; default: CurrencyButton->animateClick(); break; } } // Dot button or key pressed void KEuroCalc::InputDot() { inputDigit('.'); } // Zero button or key pressed void KEuroCalc::InputZero() { inputDigit('0'); } // One button or key pressed void KEuroCalc::InputOne() { inputDigit('1'); } // Two button or key pressed void KEuroCalc::InputTwo() { inputDigit('2'); } // Three button or key pressed void KEuroCalc::InputThree() { inputDigit('3'); } // Four button or key pressed void KEuroCalc::InputFour() { inputDigit('4'); } // Five button or key pressed void KEuroCalc::InputFive() { inputDigit('5'); } // Six button or key pressed void KEuroCalc::InputSix() { inputDigit('6'); } // Seven button or key pressed void KEuroCalc::InputSeven() { inputDigit('7'); } // Eight button or key pressed void KEuroCalc::InputEight() { inputDigit('8'); } // Nine button or key pressed void KEuroCalc::InputNine() { inputDigit('9'); } // Plus button or key pressed void KEuroCalc::InputPlus() { inputOperator('+'); } // Minus button or key pressed void KEuroCalc::InputMinus() { inputOperator('-'); } // Multiply button or key pressed void KEuroCalc::InputAsterisk() { inputOperator('x'); } // Divide button or key pressed void KEuroCalc::InputSlash() { inputOperator('/'); } // Correct last entered digit void KEuroCalc::InputBackspace() { inputCorrect(); } // Convert to currency, and add or substract too if needed void KEuroCalc::ValidateReference() { double inputValue, currencyRate, currencyPrecision; inputValue = strtod_l( inputDisplay, NULL, c_locale ); currencyRate = currencies.rate(currencyNum); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currencies.officialRulesPrecision(currencyNum); break; case SMALLEST_COIN: currencyPrecision = currencies.smallestCoinPrecision(currencyNum); break; default: currencyPrecision = 1.0; } if ( inputDisplay[10] == ' ' ) { if ( isSimpleValue && *operatorDisplay == ' ' ) { isSimpleValue = false; referenceValue = simpleValue; currencyValue = referenceValue * currencyRate * currencyPrecision; displayNewResult(); } else QApplication::beep(); return; } switch ( *operatorDisplay ) { case ' ': isSimpleValue = false; referenceValue = inputValue; currencyValue = referenceValue * currencyRate * currencyPrecision; break; case '+': if ( isSimpleValue ) { QApplication::beep(); return; } referenceValue += inputValue; currencyValue = referenceValue * currencyRate * currencyPrecision; break; case '-': if ( isSimpleValue ) { QApplication::beep(); return; } referenceValue -= inputValue; currencyValue = referenceValue * currencyRate * currencyPrecision; break; case 'x': if ( isSimpleValue ) { isSimpleValue = false; referenceValue = simpleValue * inputValue; currencyValue = referenceValue * currencyRate * currencyPrecision; } else { QApplication::beep(); return; } break; case '/': if ( !isSimpleValue && inputValue != 0.0 ) { isSimpleValue = true; simpleValue = referenceValue / inputValue; } else { QApplication::beep(); return; } } resetInput(); displayNewResult(); displayMemoryButtons(); } // Convert to reference, and add or substract too if needed void KEuroCalc::ValidateCurrency() { double inputValue, currencyRate, currencyPrecision; inputValue = strtod_l( inputDisplay, NULL, c_locale ); currencyRate = currencies.rate(currencyNum); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currencies.officialRulesPrecision(currencyNum); break; case SMALLEST_COIN: currencyPrecision = currencies.smallestCoinPrecision(currencyNum); break; default: currencyPrecision = 1.0; } if ( inputDisplay[10] == ' ' ) { if ( isSimpleValue && *operatorDisplay == ' ' ) { isSimpleValue = false; currencyValue = simpleValue; referenceValue = currencyValue / currencyRate / currencyPrecision; displayNewResult(); } else QApplication::beep(); return; } switch ( *operatorDisplay ) { case ' ': isSimpleValue = false; currencyValue = inputValue; referenceValue = currencyValue / currencyRate / currencyPrecision; break; case '+': if ( isSimpleValue ) { QApplication::beep(); return; } currencyValue += inputValue; referenceValue = currencyValue / currencyRate / currencyPrecision; break; case '-': if ( isSimpleValue ) { QApplication::beep(); return; } currencyValue -= inputValue; referenceValue = currencyValue / currencyRate / currencyPrecision; break; case 'x': if ( isSimpleValue ) { isSimpleValue = false; currencyValue = simpleValue * inputValue; referenceValue = currencyValue / currencyRate / currencyPrecision; } else { QApplication::beep(); return; } break; case '/': if ( !isSimpleValue && inputValue != 0.0 ) { isSimpleValue = true; simpleValue = currencyValue / inputValue; } else { QApplication::beep(); return; } } resetInput(); displayNewResult(); displayMemoryButtons(); } // Apply percentage, and add or substract too if needed void KEuroCalc::ValidatePercent() { double inputValue, currencyRate, currencyPrecision; inputValue = strtod_l( inputDisplay, NULL, c_locale ); currencyRate = currencies.rate(currencyNum); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currencies.officialRulesPrecision(currencyNum); break; case SMALLEST_COIN: currencyPrecision = currencies.smallestCoinPrecision(currencyNum); break; default: currencyPrecision = 1.0; } if ( inputDisplay[10] == ' ' ) { QApplication::beep(); return; } switch ( *operatorDisplay ) { case ' ': if ( isSimpleValue ) simpleValue = (inputValue * simpleValue) / 100.0; else { referenceValue = (inputValue * referenceValue) / 100.0; currencyValue = referenceValue * currencyRate * currencyPrecision; } break; case '+': if ( isSimpleValue ) simpleValue = ((100.0 + inputValue) * simpleValue) / 100.0; else { referenceValue = ((100.0 + inputValue) * referenceValue) / 100.0; currencyValue = referenceValue * currencyRate * currencyPrecision; } break; case '-': if ( isSimpleValue ) simpleValue = ((100.0 - inputValue) * simpleValue) / 100.0; else { referenceValue = ((100.0 - inputValue) * referenceValue) / 100.0; currencyValue = referenceValue * currencyRate * currencyPrecision; } break; case 'x': case '/': QApplication::beep(); return; } resetInput(); displayNewResult(); } // Enter a simple value, and multiply or divide too if needed. void KEuroCalc::ValidateSimpleValue() { double inputValue, currencyRate, currencyPrecision; inputValue = strtod_l( inputDisplay, NULL, c_locale ); currencyRate = currencies.rate(currencyNum); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currencies.officialRulesPrecision(currencyNum); break; case SMALLEST_COIN: currencyPrecision = currencies.smallestCoinPrecision(currencyNum); break; default: currencyPrecision = 1.0; } if ( inputDisplay[10] == ' ' ) { QApplication::beep(); return; } switch ( *operatorDisplay ) { case ' ': isSimpleValue = true; simpleValue = inputValue; break; case '+': if ( isSimpleValue ) simpleValue += inputValue; else { QApplication::beep(); return; } break; case '-': if ( isSimpleValue ) simpleValue -= inputValue; else { QApplication::beep(); return; } break; case 'x': if ( isSimpleValue ) simpleValue *= inputValue; else { referenceValue *= inputValue; currencyValue = referenceValue * currencyRate * currencyPrecision; } break; case '/': if ( inputValue == 0.0 ) { QApplication::beep(); return; } if ( isSimpleValue ) simpleValue /= inputValue; else { referenceValue /= inputValue; currencyValue = referenceValue * currencyRate * currencyPrecision; } break; default: QApplication::beep(); return; } resetInput(); displayNewResult(); displayMemoryButtons(); } // Change the sign of the result void KEuroCalc::ChangeSign() { double currencyRate, currencyPrecision; currencyRate = currencies.rate(currencyNum); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currencies.officialRulesPrecision(currencyNum); break; case SMALLEST_COIN: currencyPrecision = currencies.smallestCoinPrecision(currencyNum); break; default: currencyPrecision = 1.0; } if ( isSimpleValue ) simpleValue = -simpleValue; else { referenceValue = -referenceValue; currencyValue = referenceValue * currencyRate * currencyPrecision; } displayNewResult(); } // Tranfer from display to memory void KEuroCalc::MemoryInput() { memorySet = true; isSimpleMemory = isSimpleValue; simpleMemory = simpleValue; referenceMemory = referenceValue; displayMemoryButtons(); } // Transfer from memory to display void KEuroCalc::MemoryRecall() { double currencyRate, currencyPrecision; currencyRate = currencies.rate(currencyNum); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currencies.officialRulesPrecision(currencyNum); break; case SMALLEST_COIN: currencyPrecision = currencies.smallestCoinPrecision(currencyNum); break; default: currencyPrecision = 1.0; } if ( !memorySet ) { QApplication::beep(); return; } switch ( *operatorDisplay ) { case ' ': isSimpleValue = isSimpleMemory; if ( isSimpleMemory ) simpleValue = simpleMemory; else { referenceValue = referenceMemory; currencyValue = referenceValue * currencyRate * currencyPrecision; } break; case '+': if ( isSimpleValue != isSimpleMemory ) { QApplication::beep(); return; } if ( isSimpleMemory ) simpleValue += simpleMemory; else { referenceValue += referenceMemory; currencyValue = referenceValue * currencyRate * currencyPrecision; } break; case '-': if ( isSimpleValue != isSimpleMemory ) { QApplication::beep(); return; } if ( isSimpleMemory ) simpleValue -= simpleMemory; else { referenceValue -= referenceMemory; currencyValue = referenceValue * currencyRate * currencyPrecision; } break; case 'x': if ( isSimpleMemory ) { if ( isSimpleValue ) simpleValue *= simpleMemory; else { referenceValue *= simpleMemory; currencyValue = referenceValue * currencyRate * currencyPrecision; } } else { if ( isSimpleValue ) { isSimpleValue = false; referenceValue = simpleValue * referenceMemory; currencyValue = referenceValue * currencyRate * currencyPrecision; } else { QApplication::beep(); return; } } break; case '/': if ( isSimpleMemory ) { if ( simpleMemory == 0.0 ) { QApplication::beep(); return; } if ( isSimpleValue ) simpleValue /= simpleMemory; else { referenceValue /= simpleMemory; currencyValue = referenceValue * currencyRate * currencyPrecision; } } else { if ( !isSimpleValue && referenceMemory != 0.0 ) { isSimpleValue = true; simpleValue = referenceValue / referenceMemory; } else { QApplication::beep(); return; } } } resetInput(); displayNewResult(); displayMemoryButtons(); } // Add memory to display void KEuroCalc::MemoryPlus() { if ( !memorySet || (isSimpleValue != isSimpleMemory) ) { QApplication::beep(); return; } if ( isSimpleMemory ) simpleMemory += simpleValue; else referenceMemory += referenceValue; } // Substract memory from display void KEuroCalc::MemoryMinus() { if ( !memorySet || (isSimpleValue != isSimpleMemory) ) { QApplication::beep(); return; } if ( isSimpleMemory ) simpleMemory -= simpleValue; else referenceMemory -= referenceValue; } // Reset both input, result and memory void KEuroCalc::Reset() { resetInput(); isSimpleValue = false; simpleValue = 0.0; referenceValue = 0.0; currencyValue = 0.0; displayNewResult(); memorySet = false; isSimpleMemory = false; simpleMemory = 0.0; referenceMemory = 0.0; displayMemoryButtons(); } // Display "about" page void KEuroCalc::DisplayAbout() { KAboutApplicationDialog *d = new KAboutApplicationDialog(KAboutData::applicationData(), this); d->exec(); delete d; AboutButton->setDown( false ); } // Display help pages void KEuroCalc::DisplayHelp() { KHelpClient::invokeHelp(); } // Display settings pages void KEuroCalc::DisplaySettings() { Preferences *d = new Preferences(this, ¤cies); d->exec(); delete d; SettingsButton->setDown( false ); } // Select currency accordingly to drop down list position void KEuroCalc::SelectCurrency(int position) { int num; double currencyRate, currencyPrecision; for (num = 0; num < currencies.number(); num++) if (currencies.position(num) == position) break; if ( num == currencies.number() ) return; currencyNum = num; displayNewCurrency(); currencyRate = currencies.rate(currencyNum); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currencies.officialRulesPrecision(currencyNum); break; case SMALLEST_COIN: currencyPrecision = currencies.smallestCoinPrecision(currencyNum); break; default: currencyPrecision = 1.0; } currencyValue = referenceValue * currencyRate * currencyPrecision; displayNewResult(); setFocus(); } // Initialize the buttons without translation and the buttons with UTF-8 // text not correctly handled by uic void KEuroCalc::initButtons() { switch ( reference ) { case EURO_FIXED: SourceLabel->setText( i18n( "Fixed" ) ); DateLabel->setText( "" ); break; case EURO_ECB: SourceLabel->setText( i18n( "ECB" ) ); DateLabel->setText( i18n( "Loading..." ) ); break; // case DOLLAR_NY_FRB: // SourceLabel->setText( i18n( "NY FRB" ) ); // DateLabel->setText( i18n( "Loading..." ) ); // break; case EURO_TG: SourceLabel->setText( i18n( "TG" ) ); DateLabel->setText( i18n( "Loading..." ) ); } switch ( rounding ) { case OFFICIAL_RULES: RoundingLabel->setText( i18n( "Official rules" ) ); break; case SMALLEST_COIN: RoundingLabel->setText( i18n( "Smallest coin" ) ); break; case NO_ROUNDING: RoundingLabel->setText( i18n( "No rounding" ) ); } DotButton->setText( QLocale().decimalPoint() ); ZeroButton->setText( QString::fromUtf8( "0" ) ); OneButton->setText( QString::fromUtf8( "1" ) ); TwoButton->setText( QString::fromUtf8( "2" ) ); ThreeButton->setText( QString::fromUtf8( "3" ) ); FourButton->setText( QString::fromUtf8( "4" ) ); FiveButton->setText( QString::fromUtf8( "5" ) ); SixButton->setText( QString::fromUtf8( "6" ) ); SevenButton->setText( QString::fromUtf8( "7" ) ); EightButton->setText( QString::fromUtf8( "8" ) ); NineButton->setText( QString::fromUtf8( "9" ) ); BackspaceButton->setText( QString::fromUtf8( "<-" ) ); MInputButton->setText( QString::fromUtf8( "Min" ) ); MRecallButton->setText( QString::fromUtf8( "MR" ) ); MMinusButton->setText( QString::fromUtf8( "M-" ) ); MPlusButton->setText( QString::fromUtf8( "M+" ) ); SlashButton->setText( QString::fromUtf8( "/" ) ); AsteriskButton->setText( QString::fromUtf8( "X" ) ); MinusButton->setText( QString::fromUtf8( "-" ) ); PlusButton->setText( QString::fromUtf8( "+" ) ); // ReferenceButton->setText( QString::fromUtf8( reference == DOLLAR_NY_FRB? dollarSymbol: euroSymbol ) ); ReferenceButton->setText( QString::fromUtf8( euroSymbol ) ); PercentButton->setText( QString::fromUtf8( "%" ) ); PlusMinusButton->setText( QString::fromUtf8( "+/-" ) ); } // Start dowloading rates void KEuroCalc::startDownload() { currencies.clearRates(); switch (reference) { case EURO_FIXED: currencies.addFixedRates( rounding ); // endDownload is called here break; case EURO_ECB: currencies.addFixedRates( rounding, true ); // endDownload is called here for the first time CurrencyList->addItem( "--------------------------------------------" ); currencies.addECBRates( rounding ); // endDowload is called again when completed break; // case DOLLAR_NY_FRB: // currencies.addNY_FRBRates( rounding ); // // endDowload is called when completed // break; case EURO_TG: currencies.addFixedRates( rounding, true ); // endDownload is called here for the first time CurrencyList->addItem( "--------------------------------------------" ); currencies.addTGRates( rounding ); // endDowload is called again when completed break; } } // Download has ended void KEuroCalc::endDownload(int defaultCurrency, const QString &date) { int position, num; position = CurrencyList->count(); for (num = 0; num < currencies.number(); num++) if (currencies.position(num) == -2) { currencies.setPosition(num, position); CurrencyList->addItem ( currencies.code(num) + " - " + currencies.name(num) ); position++; } DateLabel->setText( date.isNull()? i18n( "Not loaded" ): date ); if ( defaultCurrency ) newRatesList( defaultCurrency ); } // The rates list has changed, refresh the display void KEuroCalc::newRatesList(int defaultCurrency) { int position; position = currencies.position(currencyNum); if (position < 0) // If current currency does not exist in new rates list, change current currency { for (currencyNum = 0; currencyNum < currencies.number(); currencyNum++) { position = currencies.position(currencyNum); if (position == 0) break; } if ( currencyNum == currencies.number() ) // Handle case of empty list (no currencies at all) { currencyNum = defaultCurrency; currencies.setRate(currencyNum, 1.0); position = 0; currencies.setPosition(currencyNum, 0); CurrencyList->addItem ( currencies.code(currencyNum) + " - " + currencies.name(currencyNum) ); } } CurrencyList->setCurrentIndex( position ); displayNewCurrency(); displayNewResult(); } // Input a digit ('0' to '9' or '.') void KEuroCalc::inputDigit(char c) { const char *s; char *d; switch ( inputPos ) { case atUnits: inputDisplay[10] = c; switch ( c ) { case '.': inputDisplay[9] = '0'; inputPos = afterUnits; break; case '0': break; default: inputPos = beforeUnits; } break; case beforeUnits: if ( inputDisplay[0] != ' ' ) { QApplication::beep(); return; } s = inputDisplay + 1; d = inputDisplay; while ( d < inputDisplay + 10 ) *d++ = *s++; *d = c; if ( c == '.' ) inputPos = afterUnits; break; case afterUnits: if ( inputDisplay[0] != ' ' ) { QApplication::beep(); return; } if ( c == '.' ) { QApplication::beep(); return; } s = inputDisplay + 1; d = inputDisplay; while ( d < inputDisplay + 10 ) *d++ = *s++; *d = c; break; } displayNewInput(); } // Remove last entered digit void KEuroCalc::inputCorrect() { const char *s; char *d; switch ( inputPos ) { case atUnits: if ( inputDisplay[10] == ' ' ) *operatorDisplay = ' '; break; case beforeUnits: case afterUnits: s = inputDisplay + 9; d = inputDisplay + 10; while ( d > inputDisplay) *d-- = *s--; *d = ' '; break; } inputPos = inputDisplay[10] == ' '? atUnits: (QString(inputDisplay).indexOf('.') == -1? beforeUnits: afterUnits); displayNewInput(); } // Input an operator ('+', '-', 'x' or '/') void KEuroCalc::inputOperator(char c) { if ( inputDisplay[10] != ' ' ) ValidateSimpleValue(); *operatorDisplay = c; displayNewInput(); } // Reset input area void KEuroCalc::resetInput() { strcpy(operatorDisplay, " "); strcpy( inputDisplay, " " ); inputPos = atUnits; OperatorDisplay->setText( operatorDisplay ); InputDisplay->setText( inputDisplay ); } // Display current input in input area void KEuroCalc::displayNewInput() { QString display(inputDisplay); normalize( display ); OperatorDisplay->setText( operatorDisplay ); InputDisplay->setText( display ); } // Display latest computed value in results area void KEuroCalc::displayNewResult() { if ( isSimpleValue ) { QString simpleDisplay; simpleDisplay.setNum( simpleValue ); normalize( simpleDisplay ); ResultDisplay->setText( simpleDisplay ); } else { double currencyPrecision; float roundedReferenceValue, roundedCurrencyValue; QString referenceDisplay, currencyDisplay; QString referenceSymbol, currencySymbol; if (rounding != NO_ROUNDING) { roundedReferenceValue = floor(referenceValue * 100.0 + 0.5) / 100.0; referenceDisplay.setNum( roundedReferenceValue, 'f', 2 ); } else referenceDisplay.setNum( referenceValue ); normalize( referenceDisplay ); // referenceSymbol = QString::fromUtf8( reference == DOLLAR_NY_FRB ? dollarSymbol: euroSymbol ); referenceSymbol = QString::fromUtf8( euroSymbol ); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currencies.officialRulesPrecision(currencyNum); roundedCurrencyValue = floor(currencyValue * 100.0 / currencyPrecision + 0.5) / 100.0 * currencyPrecision; currencyDisplay.setNum( roundedCurrencyValue, 'f', currencyPrecision < 100.0? 2: 0 ); break; case SMALLEST_COIN: currencyPrecision = currencies.smallestCoinPrecision(currencyNum); roundedCurrencyValue = floor(currencyValue * 100.0 / currencyPrecision + 0.5) / 100.0 * currencyPrecision; currencyDisplay.setNum( roundedCurrencyValue, 'f', currencyPrecision < 100.0? 2: 0 ); break; default: currencyDisplay.setNum( currencyValue ); } normalize( currencyDisplay ); currencySymbol = currencies.symbol(currencyNum); ResultDisplay->setText( referenceDisplay + referenceSymbol + "\n" + currencyDisplay + " " + currencySymbol ); } } // Update the currency button accordingly to new currency void KEuroCalc::displayNewCurrency() { QString referenceSymbol, currencySymbol; currencySymbol = currencies.symbol(currencyNum); CurrencyButton->setText( currencySymbol ); if ( currencies.position(currencyNum) >= 0 ) { double currencyRate, currencyPrecision; QString rate; currencyRate = currencies.rate(currencyNum); switch (rounding) { case OFFICIAL_RULES: currencyPrecision = currencies.officialRulesPrecision(currencyNum); break; case SMALLEST_COIN: currencyPrecision = currencies.smallestCoinPrecision(currencyNum); break; default: currencyPrecision = 1.0; } rate.setNum( currencyRate * currencyPrecision ); // referenceSymbol = QString::fromUtf8( reference == DOLLAR_NY_FRB ? dollarSymbol: euroSymbol ); referenceSymbol = QString::fromUtf8( euroSymbol ); RateLabel->setText ( "1" + referenceSymbol + " = " + rate + " " + currencySymbol ); } else RateLabel->setText( "" ); } // Display the memory Plus and Minus buttons void KEuroCalc::displayMemoryButtons() { bool recallEnabled = memorySet, sumsEnabled = memorySet && (isSimpleValue == isSimpleMemory); MRecallButton->setEnabled( recallEnabled ); MMinusButton->setEnabled( sumsEnabled ); MPlusButton->setEnabled( sumsEnabled ); } // Normalize the display of a number void KEuroCalc::normalize( QString &numberDisplay ) { int dotPos = numberDisplay.indexOf('.'), unitPos = (dotPos == -1? numberDisplay.length(): dotPos) - 3; if ( dotPos != -1 ) numberDisplay.replace( dotPos, 1, QLocale().decimalPoint() ); while (unitPos > 0) { numberDisplay.insert( unitPos, " "); unitPos -= 3; } } diff --git a/keurocalc/preferences.cpp b/keurocalc/preferences.cpp index c85ca2d..2bc805e 100644 --- a/keurocalc/preferences.cpp +++ b/keurocalc/preferences.cpp @@ -1,113 +1,112 @@ /*************************************************************************** preferences.cpp - preferences widget ------------------- begin : lun avr 12 18:25:02 CET 2004 copyright : (C) 2001-2018 by Éric Bischoff email : ebischoff@nerim.net ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include #include #include #include "preferences.h" -#include "preferences.moc" #include "keurocalc.h" // Constructor Preferences::Preferences(KEuroCalc *parent, const Currencies *currencies) : QDialog(parent), Ui::SettingsDialog() { int oldReference, oldCurrency, oldRounding; QColor oldDisplayColor; QPalette palette; bool oldSplashScreen; setupUi(this); // TODO: The following should move to the ui file! referenceGroup = new QButtonGroup(); referenceGroup->addButton( radioButtonEuroFixed, EURO_FIXED ); referenceGroup->addButton( radioButtonEuroECB, EURO_ECB ); // referenceGroup->addButton( radioButtonDollarNYFRB, DOLLAR_NY_FRB ); referenceGroup->addButton( radioButtonEuroTG, EURO_TG ); roundingGroup = new QButtonGroup(); roundingGroup->addButton( radioButtonOfficialRules, OFFICIAL_RULES ); roundingGroup->addButton( radioButtonSmallestCoin, SMALLEST_COIN ); roundingGroup->addButton( radioButtonNoRounding, NO_ROUNDING ); parent->readOptions( oldReference, oldCurrency, oldRounding, oldDisplayColor, oldSplashScreen ); referenceGroup->button( oldReference )->setChecked( true ); for (int num = 0; num < currencies->number(); num++) defaultCurrencyList->addItem ( currencies->code(num) + " - " + currencies->name(num) ); defaultCurrencyList->setCurrentRow( oldCurrency ); roundingGroup->button( oldRounding )->setChecked( true ); palette.setColor( backgroundRole(), oldDisplayColor ); displayColorResult->setPalette( palette ); checkBoxSplashScreen->setChecked( oldSplashScreen ); } // Destructor Preferences::~Preferences() { } // OK button pressed void Preferences::ok() { KEuroCalc *calc = (KEuroCalc *) parentWidget(); int newReference = referenceGroup->checkedId(), newCurrency = defaultCurrencyList->currentRow(), newRounding = roundingGroup->checkedId(); QPalette palette = displayColorResult->palette(); QColor newDisplayColor = palette.color( backgroundRole() ); bool newSplashScreen = checkBoxSplashScreen->isChecked(); calc->writeOptions( newReference, newCurrency, newRounding, newDisplayColor, newSplashScreen ); calc->setPreferences( newReference, newCurrency, newRounding, newDisplayColor, newSplashScreen ); calc->ResultDisplay->setPalette( palette ); calc->InputDisplay->setPalette( palette ); calc->OperatorDisplay->setPalette( palette ); close(); } // Cancel button pressed void Preferences::cancel() { close(); } // Change display color button pressed void Preferences::changeDisplayColor() { QPalette palette = displayColorResult->palette(); QColor myColor; myColor = QColorDialog::getColor ( palette.color( backgroundRole() ) ); if ( myColor.isValid() ) { QPalette palette; palette.setColor( backgroundRole(), myColor ); displayColorResult->setPalette( palette ); } }