diff --git a/demos/ff7tkWidgetGallery/mainwindow.cpp b/demos/ff7tkWidgetGallery/mainwindow.cpp index c5c17105b..c95b32b57 100644 --- a/demos/ff7tkWidgetGallery/mainwindow.cpp +++ b/demos/ff7tkWidgetGallery/mainwindow.cpp @@ -83,6 +83,13 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWin auto itemlistLayout = new QVBoxLayout (); itemlistLayout->addWidget(itemlistView); ui->itemListView_Box->setLayout(itemlistLayout); + + hexLineEdit = new HexLineEdit(this); + auto hexLineEditLayout = new QVBoxLayout(); + hexLineEditLayout->addWidget(hexLineEdit); + ui->hexLineEdit_Box->setLayout(hexLineEditLayout); + ui->sb_hexEditLine_maxlen->setValue(hexLineEdit->maxLength()); + } MainWindow::~MainWindow() @@ -112,6 +119,7 @@ void MainWindow::on_combo_widget_currentIndexChanged(int index) case 10: ui->locListBox->setVisible(1); break; case 11: ui->ChocoboManagerBox->setVisible(1); break; case 12: ui->AchievementEditor_Box->setVisible(1); break; + case 13: ui->hexLineEdit_group->setVisible(1); break; } this->adjustSize(); } @@ -246,6 +254,7 @@ void MainWindow::hideAllBoxes(void) ui->locListBox->setVisible(0); ui->ChocoboManagerBox->setVisible(0); ui->AchievementEditor_Box->setVisible(0); + ui->hexLineEdit_group->setVisible(0); } void MainWindow::on_btn_loadAchievement_clicked() @@ -286,3 +295,9 @@ void MainWindow::on_sb_itemListViewMaxQty_editingFinished() { itemlistView->setMaximumItemQty(ui->sb_itemListViewMaxQty->value()); } + +void MainWindow::on_sb_hexEditLine_maxlen_valueChanged(double arg1) +{ + hexLineEdit->setMaxLength(arg1 * 2); +} + diff --git a/demos/ff7tkWidgetGallery/mainwindow.h b/demos/ff7tkWidgetGallery/mainwindow.h index 63ebe36fc..fe1ad89e7 100644 --- a/demos/ff7tkWidgetGallery/mainwindow.h +++ b/demos/ff7tkWidgetGallery/mainwindow.h @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace Ui @@ -67,6 +68,8 @@ private slots: void on_cb_itemSelectionDeleageEditable_toggled(bool checked); void on_sb_itemListViewMaxQty_editingFinished(); + void on_sb_hexEditLine_maxlen_valueChanged(double arg1); + private: Ui::MainWindow *ui = nullptr; @@ -81,4 +84,5 @@ private slots: ChocoboManager *chocoboManager = nullptr; AchievementEditor *achievementEditor = nullptr; ItemListView *itemlistView = nullptr; + HexLineEdit *hexLineEdit = nullptr; }; diff --git a/demos/ff7tkWidgetGallery/mainwindow.ui b/demos/ff7tkWidgetGallery/mainwindow.ui index a906cf08d..6dc1f6db4 100644 --- a/demos/ff7tkWidgetGallery/mainwindow.ui +++ b/demos/ff7tkWidgetGallery/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 175 - 32 + 117 + 31 @@ -88,6 +88,11 @@ AchievementEditor + + + HexLineEdit + + @@ -580,6 +585,46 @@ + + + + HexLineEdit + + + + + + + + MaxLength + + + + + + + 0 + + + 20000000000000000426408380189087937446025157425359298935486676992.000000000000000 + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + diff --git a/src/widgets/common/HexLineEdit.cpp b/src/widgets/common/HexLineEdit.cpp index e20d8e426..570f17ba8 100644 --- a/src/widgets/common/HexLineEdit.cpp +++ b/src/widgets/common/HexLineEdit.cpp @@ -15,17 +15,18 @@ /****************************************************************************/ /****************************************************************************/ #include +#include HexLineEdit::HexLineEdit(QWidget *parent) : QLineEdit(parent) , _noEmit(false) { + setValidator(new QRegularExpressionValidator(QRegularExpression(_hexRegEx), this)); connect(this, &HexLineEdit::textEdited, this, &HexLineEdit::emitDataEdited); } HexLineEdit::HexLineEdit(const QByteArray &contents, QWidget *parent) - : QLineEdit(parent) - , _noEmit(false) + : HexLineEdit(parent) { setData(contents); } @@ -39,7 +40,6 @@ void HexLineEdit::setData(const QByteArray &contents) { _noEmit = true; setMaxLength(contents.size() * 2); - setInputMask(QString(contents.size() * 2, 'H')); _noEmit = false; setText(QString::fromLatin1(contents.toHex())); Q_EMIT dataChanged(contents); @@ -67,7 +67,3 @@ void HexLineEdit::setMaxLength(int maxLength) QLineEdit::setMaxLength(maxLength); } -void HexLineEdit::setInputMask(const QString &inputMask) -{ - QLineEdit::setInputMask(inputMask); -} diff --git a/src/widgets/common/HexLineEdit.h b/src/widgets/common/HexLineEdit.h index 6fc8f6301..cc0f4911e 100644 --- a/src/widgets/common/HexLineEdit.h +++ b/src/widgets/common/HexLineEdit.h @@ -26,6 +26,7 @@ class FF7TKQTWIDGETS_EXPORT HexLineEdit : public QLineEdit explicit HexLineEdit(QWidget *parent = nullptr); explicit HexLineEdit(const QByteArray &contents, QWidget *parent = nullptr); QByteArray data() const; + void setMaxLength(int maxLength); public slots: void setData(const QByteArray &contents); signals: @@ -33,9 +34,9 @@ public slots: void dataEdited(const QByteArray &data); private: QString text() const; - void setMaxLength(int maxLength); void setInputMask(const QString &inputMask); bool _noEmit; + QString _hexRegEx = QStringLiteral("([A-F]|[0-9]|[a-f])*"); private slots: void emitDataEdited(); void setText(const QString &);