File indexing completed on 2025-01-05 05:23:47

0001 /*
0002     This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009 Alex Richardson <alex.richardson@gmx.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "structureviewsettingswidget.hpp"
0010 
0011 #include "structureviewpreferences.hpp"
0012 #include <structureslogging.hpp>
0013 
0014 #include <KLocalizedString>
0015 
0016 StructureViewSettingsWidget::StructureViewSettingsWidget()
0017 {
0018     ui.setupUi(this);
0019     ui.combo_CharDisplayBase->setEnabled(ui.kcfg_ShowCharNumericalValue->isChecked());
0020 
0021     // no need for a hidden spinbox with byteOrder, since it is a simple sequential enum
0022 
0023     // setup the hidden spin boxes for the display bases
0024     // these are needed since KConfigXT always uses the combo box index as the value
0025     // we want the UserData of the current index instead
0026     // maybe there is a nicer solution, but this works
0027     ui.kcfg_CharDisplayBase->setValue(Kasten::StructureViewPreferences::charDisplayBase());
0028     ui.kcfg_CharDisplayBase->setHidden(true);
0029     ui.kcfg_SignedDisplayBase->setValue(Kasten::StructureViewPreferences::signedDisplayBase());
0030     ui.kcfg_SignedDisplayBase->setHidden(true);
0031     ui.kcfg_UnsignedDisplayBase->setValue(Kasten::StructureViewPreferences::unsignedDisplayBase());
0032     ui.kcfg_UnsignedDisplayBase->setHidden(true);
0033     setupBasesCombo(ui.combo_SignedDisplayBase, Kasten::StructureViewPreferences::self()->signedDisplayBaseItem(),
0034                     Kasten::StructureViewPreferences::signedDisplayBase(), SLOT(setSignedDisplay(int)));
0035     setupBasesCombo(ui.combo_UnsignedDisplayBase, Kasten::StructureViewPreferences::self()->unsignedDisplayBaseItem(),
0036                     Kasten::StructureViewPreferences::unsignedDisplayBase(), SLOT(setUnsignedDisplay(int)));
0037     setupBasesCombo(ui.combo_CharDisplayBase, Kasten::StructureViewPreferences::self()->charDisplayBaseItem(),
0038                     Kasten::StructureViewPreferences::charDisplayBase(), SLOT(setCharDisplay(int)));
0039 }
0040 
0041 StructureViewSettingsWidget::~StructureViewSettingsWidget() = default;
0042 
0043 void StructureViewSettingsWidget::setupBasesCombo(QComboBox* box, KConfigSkeletonItem* configItem,
0044                                                   int currentValue, const char* slot)
0045 {
0046     Q_ASSERT(box->count() == 0);
0047     Q_ASSERT(currentValue == 2 || currentValue == 8 || currentValue == 10 || currentValue == 16);
0048     qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "current value:" << configItem->property() << "vs" << currentValue;
0049     box->addItem(i18nc("@item:inlistbox", "Binary"), 2);
0050     box->addItem(i18nc("@item:inlistbox", "Octal"), 8);
0051     box->addItem(i18nc("@item:inlistbox", "Decimal"), 10);
0052     box->addItem(i18nc("@item:inlistbox", "Hexadecimal"), 16);
0053 
0054     box->setCurrentIndex(currentValue == 2 ? 0 : (currentValue == 8 ? 1 : (currentValue == 16 ? 3 : 2)));
0055 
0056     box->setToolTip(configItem->toolTip());
0057     connect(box, SIGNAL(activated(int)), this, slot);
0058 }
0059 
0060 void StructureViewSettingsWidget::handleMapping(int index, QComboBox* box, QSpinBox* spin)
0061 {
0062     QVariant currentValue = box->itemData(index);
0063     qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "box changed to " << index << "value = " << currentValue;
0064     if (spin->value() != currentValue.toInt()) {
0065         spin->setValue(currentValue.toInt());
0066     }
0067 }
0068 
0069 void StructureViewSettingsWidget::setCharDisplay(int index)
0070 {
0071     qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "byteOrder changed to " << index;
0072     handleMapping(index, ui.combo_CharDisplayBase, ui.kcfg_CharDisplayBase);
0073 }
0074 
0075 void StructureViewSettingsWidget::setSignedDisplay(int index)
0076 {
0077     qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "byteOrder changed to " << index;
0078     handleMapping(index, ui.combo_SignedDisplayBase, ui.kcfg_SignedDisplayBase);
0079 }
0080 
0081 void StructureViewSettingsWidget::setUnsignedDisplay(int index)
0082 {
0083     qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "byteOrder changed to " << index;
0084     handleMapping(index, ui.combo_UnsignedDisplayBase, ui.kcfg_UnsignedDisplayBase);
0085 }
0086 
0087 #include "moc_structureviewsettingswidget.cpp"