File indexing completed on 2022-11-22 12:51:03

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003 */
0004 
0005 #include "isotopetablesettingsdialog.h"
0006 
0007 #include <QGridLayout>
0008 
0009 #include <KLocalizedString>
0010 
0011 IsotopeTableSettingsDialog::IsotopeTableSettingsDialog(QWidget *parent)
0012     : QWidget(parent)
0013 {
0014     m_mode = Prefs::isotopeTableMode();
0015 
0016     auto card0 = new IsotopeTableSettingsCard(this, 0);
0017     card0->setZoom(0.07);
0018     card0->setText(i18n("One part to the side of the other"));
0019     card0->setRadioButtonObjectName("isotopeTableMode_0");
0020     m_cards.append(card0);
0021     auto card1 = new IsotopeTableSettingsCard(this, 1);
0022     card1->setZoom(0.04);
0023     card1->setText(i18n("Both parts continuous"));
0024     card0->setRadioButtonObjectName("isotopeTableMode_1");
0025     m_cards.append(card1);
0026     auto card2 = new IsotopeTableSettingsCard(this, 2);
0027     card2->setZoom(0.04);
0028     card2->setText(i18n("Horizontally"));
0029     card0->setRadioButtonObjectName("isotopeTableMode_2");
0030     m_cards.append(card2);
0031     auto card3 = new IsotopeTableSettingsCard(this, 3);
0032     card3->setZoom(0.05);
0033     card3->setText(i18n("Horizontally (shifted)"));
0034     card0->setRadioButtonObjectName("isotopeTableMode_3");
0035     m_cards.append(card3);
0036 
0037     m_cards[m_mode]->setChecked(true);
0038 
0039     connect(card0, &IsotopeTableSettingsCard::checked, this, &IsotopeTableSettingsDialog::setMode);
0040     connect(card1, &IsotopeTableSettingsCard::checked, this, &IsotopeTableSettingsDialog::setMode);
0041     connect(card2, &IsotopeTableSettingsCard::checked, this, &IsotopeTableSettingsDialog::setMode);
0042     connect(card3, &IsotopeTableSettingsCard::checked, this, &IsotopeTableSettingsDialog::setMode);
0043 
0044     auto layout = new QGridLayout(this);
0045     layout->addWidget(card0, 0, 0);
0046     layout->addWidget(card1, 0, 1);
0047     layout->addWidget(card2, 1, 0);
0048     layout->addWidget(card3, 1, 1);
0049 
0050     setLayout(layout);
0051 }
0052 
0053 IsotopeTableSettingsDialog::~IsotopeTableSettingsDialog() = default;
0054 
0055 bool IsotopeTableSettingsDialog::hasChanged() const
0056 {
0057     return m_mode != Prefs::isotopeTableMode();
0058 }
0059 
0060 bool IsotopeTableSettingsDialog::isDefault() const
0061 {
0062     return m_mode == 0;
0063 }
0064 
0065 void IsotopeTableSettingsDialog::setMode(int mode)
0066 {
0067     m_mode = mode;
0068     unsigned short i = 0;
0069     for (auto card : std::as_const(m_cards)) {
0070         if (i != m_mode)
0071             card->setChecked(false);
0072         i++;
0073     }
0074     m_cards[m_mode]->setChecked(true);
0075     Q_EMIT modeChanged(m_mode);
0076 }