File indexing completed on 2024-04-28 13:43:56

0001 /***************************************************************************
0002                       preferences.cpp  -  preferences widget
0003                              -------------------
0004     begin                : lun avr 12 18:25:02 CET 2004
0005     copyright            : (C) 2001-2022 by Éric Bischoff
0006     email                : bischoff@kde.org
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "preferences.h"
0019 
0020 #include <QButtonGroup>
0021 #include <QCheckBox>
0022 #include <QColorDialog>
0023 
0024 #include "keurocalc.h"
0025 
0026 // Constructor
0027 Preferences::Preferences(KEuroCalc *parent, const Currencies *currencies)
0028     : QDialog(parent), Ui::SettingsDialog()
0029 {
0030     int oldReference, oldCurrency, oldRounding;
0031     QColor oldDisplayColor;
0032     QPalette palette;
0033     bool oldSplashScreen;
0034 
0035     setupUi(this);
0036 // TODO: The following should move to the ui file!
0037     referenceGroup = new QButtonGroup();
0038     referenceGroup->addButton( radioButtonEuroFixed, EURO_FIXED );
0039     referenceGroup->addButton( radioButtonEuroECB, EURO_ECB );
0040 //  referenceGroup->addButton( radioButtonDollarNYFRB, DOLLAR_NY_FRB );
0041     referenceGroup->addButton( radioButtonEuroTG, EURO_TG );
0042     roundingGroup = new QButtonGroup();
0043     roundingGroup->addButton( radioButtonOfficialRules, OFFICIAL_RULES );
0044     roundingGroup->addButton( radioButtonSmallestCoin, SMALLEST_COIN );
0045     roundingGroup->addButton( radioButtonNoRounding, NO_ROUNDING );
0046 
0047     parent->readOptions( oldReference, oldCurrency, oldRounding, oldDisplayColor, oldSplashScreen );
0048 
0049     referenceGroup->button( oldReference )->setChecked( true );
0050 
0051     for (int num = 0; num < currencies->number(); num++)
0052         defaultCurrencyList->addItem
0053             ( currencies->code(num) + " - " + currencies->name(num) );
0054     defaultCurrencyList->setCurrentRow( oldCurrency );
0055 
0056     roundingGroup->button( oldRounding )->setChecked( true );
0057 
0058     palette.setColor( backgroundRole(), oldDisplayColor );
0059     displayColorResult->setPalette( palette );
0060 
0061     checkBoxSplashScreen->setChecked( oldSplashScreen );
0062 
0063     connect(qPushButtonDisplayColor, &QAbstractButton::clicked, this, &Preferences::changeDisplayColor);
0064     connect(buttonBox, &QDialogButtonBox::rejected, this, &Preferences::cancel);
0065     connect(buttonBox, &QDialogButtonBox::accepted, this, &Preferences::ok);
0066 }
0067 
0068 // Destructor
0069 Preferences::~Preferences()
0070 {
0071 }
0072 
0073 // OK button pressed
0074 void Preferences::ok()
0075 {
0076     KEuroCalc *calc = (KEuroCalc *) parentWidget();
0077     int newReference = referenceGroup->checkedId(),
0078         newCurrency = defaultCurrencyList->currentRow(),
0079         newRounding = roundingGroup->checkedId();
0080     
0081     QPalette palette = displayColorResult->palette();
0082     QColor newDisplayColor = palette.color( backgroundRole() );
0083 
0084     bool newSplashScreen = checkBoxSplashScreen->isChecked();
0085 
0086     calc->writeOptions( newReference, newCurrency, newRounding, newDisplayColor, newSplashScreen );
0087     calc->setPreferences( newReference, newCurrency, newRounding, newDisplayColor, newSplashScreen );
0088 
0089     calc->ResultDisplay->setPalette( palette );
0090     calc->InputDisplay->setPalette( palette );
0091     calc->OperatorDisplay->setPalette( palette );
0092 
0093     close();
0094 }
0095 
0096 // Cancel button pressed
0097 void Preferences::cancel()
0098 {
0099     close();
0100 }
0101 
0102 // Change display color button pressed
0103 void Preferences::changeDisplayColor()
0104 {
0105     QPalette palette = displayColorResult->palette();
0106     QColor myColor;
0107 
0108     myColor = QColorDialog::getColor
0109         ( palette.color( backgroundRole() ) );
0110     if ( myColor.isValid() )
0111     {
0112         QPalette palette;
0113 
0114         palette.setColor( backgroundRole(), myColor );
0115         displayColorResult->setPalette( palette );
0116     }
0117 }
0118 
0119 #include "moc_preferences.cpp"