From 4cfaa055214fc7410f384520c0db5501f823b8e4 Mon Sep 17 00:00:00 2001 From: kvazar Date: Sat, 30 Mar 2024 07:19:38 +0200 Subject: [PATCH] add key/value colored counter, give name to labels #7 --- src/qt/forms/kevaaddkeydialog.ui | 56 +++++++++++++++++++++++------ src/qt/kevaaddkeydialog.cpp | 60 +++++++++++++++++++++++++++++--- 2 files changed, 101 insertions(+), 15 deletions(-) diff --git a/src/qt/forms/kevaaddkeydialog.ui b/src/qt/forms/kevaaddkeydialog.ui index 2508d6c71..66d7f1ffc 100644 --- a/src/qt/forms/kevaaddkeydialog.ui +++ b/src/qt/forms/kevaaddkeydialog.ui @@ -15,16 +15,33 @@ - - - Key - - + + + + + Key + + + Qt::AlignLeft + + + + + + + + + + Qt::AlignRight + + + + - New value + New key @@ -42,11 +59,28 @@ - - - Value - - + + + + + Value + + + Qt::AlignLeft + + + + + + + + + + Qt::AlignRight + + + + diff --git a/src/qt/kevaaddkeydialog.cpp b/src/qt/kevaaddkeydialog.cpp index 3c32d9a56..9877fb2a0 100644 --- a/src/qt/kevaaddkeydialog.cpp +++ b/src/qt/kevaaddkeydialog.cpp @@ -49,16 +49,68 @@ void KevaAddKeyDialog::cancel() void KevaAddKeyDialog::onKeyChanged(const QString& key) { - bool enabled = key.length() > 0 && ui->valueText->toPlainText().length() > 0 && - key.length() <= 255 && ui->valueText->toPlainText().length() < MAX_SCRIPT_ELEMENT_SIZE + 1; + // Calculate current length + int keyTextLength = key.length(); + int valueTextLength = ui->valueText->toPlainText().length(); + + // Update counter value + ui->keyCounter->setText( + QString::number( + keyTextLength + ) + "/" + QString::number( + 255 + ) + ); + + // Update counter palette + QPalette keyCounterPalette = ui->keyCounter->palette(); + + keyCounterPalette.setColor( + QPalette::WindowText, + keyTextLength > MAX_SCRIPT_ELEMENT_SIZE ? Qt::red : Qt::darkGreen + ); + + ui->keyCounter->setPalette( + keyCounterPalette + ); + + // Update button status + bool enabled = keyTextLength > 0 && valueTextLength > 0 && + keyTextLength <= 255 && valueTextLength < MAX_SCRIPT_ELEMENT_SIZE + 1; ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(enabled); } void KevaAddKeyDialog::onValueChanged() { - bool enabled = ui->keyText->text().length() > 0 && ui->valueText->toPlainText().length() > 0 && - ui->keyText->text().length() <= 255 && ui->valueText->toPlainText().length() < MAX_SCRIPT_ELEMENT_SIZE + 1; + // Calculate current length + int keyTextLength = ui->keyText->text().length(); + int valueTextLength = ui->valueText->toPlainText().length(); + + // Update counter value + ui->valueCounter->setText( + QString::number( + valueTextLength + ) + "/" + QString::number( + MAX_SCRIPT_ELEMENT_SIZE + ) + ); + + // Update counter palette + QPalette valueCounterPalette = ui->valueCounter->palette(); + + valueCounterPalette.setColor( + QPalette::WindowText, + valueTextLength > MAX_SCRIPT_ELEMENT_SIZE ? Qt::red : Qt::darkGreen + ); + + ui->valueCounter->setPalette( + valueCounterPalette + ); + + // Update button status + bool enabled = keyTextLength > 0 && valueTextLength > 0 && + keyTextLength <= 255 && valueTextLength < MAX_SCRIPT_ELEMENT_SIZE + 1; ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(enabled); }