File indexing completed on 2025-01-19 05:20:18
0001 /* 0002 This file is part of the Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2009 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 "bytearraypatterngeneratorconfigeditor.hpp" 0010 0011 // lib 0012 #include <bytearraycombobox.hpp> 0013 // KF 0014 #include <KLocalizedString> 0015 // Qt 0016 #include <QSpinBox> 0017 #include <QFormLayout> 0018 // Std 0019 #include <limits> 0020 0021 namespace Kasten { 0022 0023 ByteArrayPatternGeneratorConfigEditor::ByteArrayPatternGeneratorConfigEditor(ByteArrayPatternGenerator* generator, QWidget* parent) 0024 : AbstractModelDataGeneratorConfigEditor(parent) 0025 , mGenerator(generator) 0026 { 0027 mSettings = mGenerator->settings(); 0028 0029 auto* pageLayout = new QFormLayout(this); 0030 pageLayout->setContentsMargins(0, 0, 0, 0); 0031 0032 // pattern 0033 const QString patternEditLabel = 0034 i18nc("@label:textbox", 0035 "Pattern:"); 0036 mPatternEdit = new Okteta::ByteArrayComboBox(this); 0037 mPatternEdit->setByteArray(mSettings.pattern); 0038 mPatternEdit->setFormat(static_cast<Okteta::ByteArrayComboBox::Coding>(mSettings.patternCoding)); 0039 connect(mPatternEdit, &Okteta::ByteArrayComboBox::byteArrayChanged, this, &ByteArrayPatternGeneratorConfigEditor::onSettingsChanged); 0040 connect(mPatternEdit, &Okteta::ByteArrayComboBox::byteArrayChanged, this, &ByteArrayPatternGeneratorConfigEditor::onPatternChanged); 0041 connect(mPatternEdit, &Okteta::ByteArrayComboBox::formatChanged, this, &ByteArrayPatternGeneratorConfigEditor::onSettingsChanged); 0042 const QString inputWhatsThis = 0043 i18nc("@info:whatsthis", 0044 "Enter a pattern to search for, or select a previous pattern from the list."); 0045 mPatternEdit->setWhatsThis(inputWhatsThis); 0046 0047 pageLayout->addRow(patternEditLabel, mPatternEdit); 0048 0049 // number 0050 const QString numberInputLabel = 0051 i18nc("@label:spinbox number of times to insert the pattern", 0052 "&Number:"); 0053 mNumberInput = new QSpinBox(this); 0054 mNumberInput->setRange(1, std::numeric_limits<int>::max()); 0055 mNumberInput->setValue(mSettings.count); 0056 connect(mNumberInput, qOverload<int>(&QSpinBox::valueChanged), 0057 this, &ByteArrayPatternGeneratorConfigEditor::onSettingsChanged); 0058 const QString numberWhatsThis = 0059 i18nc("@info:whatsthis", 0060 "Enter the number of times the pattern should be inserted."); 0061 mNumberInput->setWhatsThis(numberWhatsThis); 0062 0063 pageLayout->addRow(numberInputLabel, mNumberInput); 0064 } 0065 0066 ByteArrayPatternGeneratorConfigEditor::~ByteArrayPatternGeneratorConfigEditor() = default; 0067 0068 bool ByteArrayPatternGeneratorConfigEditor::isValid() const { return (!mSettings.pattern.isEmpty()); } 0069 0070 QString ByteArrayPatternGeneratorConfigEditor::name() const 0071 { 0072 return i18nc("@item name of the generated data", "Pattern"); 0073 } 0074 0075 // TODO: get char codec 0076 #if 0 0077 void InsertPatternDialog::setCharCodec(const QString& codecName) 0078 { 0079 mPatternEdit->setCharCodec(codecName); 0080 } 0081 #endif 0082 0083 void ByteArrayPatternGeneratorConfigEditor::onSettingsChanged() 0084 { 0085 mSettings.pattern = mPatternEdit->byteArray(); 0086 mSettings.patternCoding = static_cast<ByteArrayPatternGeneratorSettings ::Coding>(mPatternEdit->format()); 0087 mSettings.count = mNumberInput->value(); 0088 0089 mGenerator->setSettings(mSettings); 0090 } 0091 0092 void ByteArrayPatternGeneratorConfigEditor::onPatternChanged(const QByteArray& pattern) 0093 { 0094 Q_EMIT validityChanged(!pattern.isEmpty()); 0095 } 0096 0097 } 0098 0099 #include "moc_bytearraypatterngeneratorconfigeditor.cpp"