File indexing completed on 2025-01-05 05:23:52
0001 /* 0002 This file is part of the Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2008 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "bytearraysourcecodestreamencoderconfigeditor.hpp" 0010 0011 // lib 0012 #include "bytearraytextstreamencoderpreview.hpp" 0013 // KF 0014 #include <KLocalizedString> 0015 #include <KComboBox> 0016 // Qt 0017 #include <QSpinBox> 0018 #include <QFormLayout> 0019 #include <QCheckBox> 0020 #include <QLineEdit> 0021 0022 namespace Kasten { 0023 0024 ByteArraySourceCodeStreamEncoderConfigEditor::ByteArraySourceCodeStreamEncoderConfigEditor(ByteArraySourceCodeStreamEncoder* encoder, QWidget* parent) 0025 : AbstractModelStreamEncoderConfigEditor(parent) 0026 , mEncoder(encoder) 0027 { 0028 mSettings = mEncoder->settings(); 0029 0030 auto* pageLayout = new QFormLayout(this); 0031 pageLayout->setContentsMargins(0, 0, 0, 0); 0032 0033 // variable name 0034 const QString variableNameLabel = 0035 i18nc("@label:textbox name of the created variable", 0036 "Name of variable:"); 0037 0038 mVariableNameEdit = new QLineEdit(this); 0039 mVariableNameEdit->setClearButtonEnabled(true); 0040 mVariableNameEdit->setText(mSettings.variableName); 0041 connect(mVariableNameEdit, &QLineEdit::textChanged, this, &ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged); 0042 pageLayout->addRow(variableNameLabel, mVariableNameEdit); 0043 0044 // items per line 0045 const QString itemsPerLineLabel = 0046 i18nc("@label:textbox to define after how many items the list is wrapped", 0047 "Items per line:"); 0048 0049 mItemsPerLineEdit = new QSpinBox(this); 0050 mItemsPerLineEdit->setMinimum(1); 0051 mItemsPerLineEdit->setValue(mSettings.elementsPerLine); 0052 connect(mItemsPerLineEdit, qOverload<int>(&QSpinBox::valueChanged), 0053 this, &ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged); 0054 pageLayout->addRow(itemsPerLineLabel, mItemsPerLineEdit); 0055 0056 // data type 0057 const QString dataTypeLabel = 0058 i18nc("@label:listbox the type of the data: char, integer, etc.", 0059 "Data type:"); 0060 0061 mDataTypeSelect = new KComboBox(this); 0062 const char* const* dataTypeNames = mEncoder->dataTypeNames(); 0063 const int dataTypesCount = mEncoder->dataTypesCount(); 0064 QStringList dataTypeNameStrings; 0065 dataTypeNameStrings.reserve(dataTypesCount); 0066 for (int i = 0; i < dataTypesCount; ++i) { 0067 dataTypeNameStrings << QLatin1String(dataTypeNames[i]); 0068 } 0069 0070 mDataTypeSelect->addItems(dataTypeNameStrings); 0071 mDataTypeSelect->setCurrentIndex(static_cast<int>(mSettings.dataType)); 0072 connect(mDataTypeSelect, qOverload<int>(&KComboBox::activated), 0073 this, &ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged); 0074 pageLayout->addRow(dataTypeLabel, mDataTypeSelect); 0075 0076 // unsigned as hexadezimal 0077 const QString unsignedAsHexadecimalLabel = 0078 i18nc("@option:check Encode the values in hexadecimal instead of decimal, " 0079 "if the datatype has the property Unsigned", 0080 "Unsigned as hexadecimal:"); 0081 0082 mUnsignedAsHexadecimalCheck = new QCheckBox(this); 0083 mUnsignedAsHexadecimalCheck->setChecked(mSettings.unsignedAsHexadecimal); 0084 connect(mUnsignedAsHexadecimalCheck, &QCheckBox::toggled, this, &ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged); 0085 pageLayout->addRow(unsignedAsHexadecimalLabel, mUnsignedAsHexadecimalCheck); 0086 } 0087 0088 ByteArraySourceCodeStreamEncoderConfigEditor::~ByteArraySourceCodeStreamEncoderConfigEditor() = default; 0089 0090 bool ByteArraySourceCodeStreamEncoderConfigEditor::isValid() const 0091 { 0092 return true; // TODO: warn if not all selected bytes are used due to the data type length 0093 } 0094 0095 AbstractSelectionView* ByteArraySourceCodeStreamEncoderConfigEditor::createPreviewView() const 0096 { 0097 return new ByteArrayTextStreamEncoderPreview(mEncoder); 0098 } 0099 0100 void ByteArraySourceCodeStreamEncoderConfigEditor::onSettingsChanged() 0101 { 0102 mSettings.variableName = mVariableNameEdit->text(); 0103 mSettings.elementsPerLine = mItemsPerLineEdit->value(); 0104 mSettings.dataType = static_cast<SourceCodeStreamEncoderSettings::PrimitiveDataType>(mDataTypeSelect->currentIndex()); 0105 mSettings.unsignedAsHexadecimal = mUnsignedAsHexadecimalCheck->isChecked(); 0106 mEncoder->setSettings(mSettings); 0107 } 0108 0109 } 0110 0111 #include "moc_bytearraysourcecodestreamencoderconfigeditor.cpp"