From 56cf5b7b17cd87f4a23bd45ae661762ce1fda5d1 Mon Sep 17 00:00:00 2001
From: Zach Hilman <zachhilman@gmail.com>
Date: Sat, 17 Nov 2018 14:44:16 -0500
Subject: [PATCH] software_keyboard: Add max and current length display to
 dialog

---
 src/yuzu/applets/software_keyboard.cpp | 11 ++++++++++-
 src/yuzu/applets/software_keyboard.h   |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/yuzu/applets/software_keyboard.cpp b/src/yuzu/applets/software_keyboard.cpp
index 83b9c320b..efefb1f99 100644
--- a/src/yuzu/applets/software_keyboard.cpp
+++ b/src/yuzu/applets/software_keyboard.cpp
@@ -47,7 +47,7 @@ QtSoftwareKeyboardDialog::QtSoftwareKeyboardDialog(
     layout = new QVBoxLayout;
 
     header_label = new QLabel(QString::fromStdU16String(parameters.header_text));
-    header_label->setFont({header_label->font().family(), 12, QFont::Bold});
+    header_label->setFont({header_label->font().family(), 11, QFont::Bold});
     if (header_label->text().isEmpty())
         header_label->setText(tr("Enter text:"));
 
@@ -59,6 +59,10 @@ QtSoftwareKeyboardDialog::QtSoftwareKeyboardDialog(
     guide_label = new QLabel(QString::fromStdU16String(parameters.guide_text));
     guide_label->setHidden(parameters.guide_text.empty());
 
+    length_label = new QLabel(QStringLiteral("0/%1").arg(parameters.max_length));
+    length_label->setAlignment(Qt::AlignRight);
+    length_label->setFont({length_label->font().family(), 8});
+
     line_edit = new QLineEdit;
     line_edit->setValidator(new QtSoftwareKeyboardValidator(parameters));
     line_edit->setMaxLength(static_cast<int>(parameters.max_length));
@@ -67,6 +71,10 @@ QtSoftwareKeyboardDialog::QtSoftwareKeyboardDialog(
         parameters.cursor_at_beginning ? 0 : static_cast<int>(parameters.initial_text.size()));
     line_edit->setEchoMode(parameters.password ? QLineEdit::Password : QLineEdit::Normal);
 
+    connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) {
+        length_label->setText(QStringLiteral("%1/%2").arg(text.size()).arg(parameters.max_length));
+    });
+
     buttons = new QDialogButtonBox;
     buttons->addButton(tr("Cancel"), QDialogButtonBox::RejectRole);
     buttons->addButton(parameters.submit_text.empty()
@@ -79,6 +87,7 @@ QtSoftwareKeyboardDialog::QtSoftwareKeyboardDialog(
     layout->addWidget(header_label);
     layout->addWidget(sub_label);
     layout->addWidget(guide_label);
+    layout->addWidget(length_label);
     layout->addWidget(line_edit);
     layout->addWidget(buttons);
     setLayout(layout);
diff --git a/src/yuzu/applets/software_keyboard.h b/src/yuzu/applets/software_keyboard.h
index 8d56f5db2..73f56714f 100644
--- a/src/yuzu/applets/software_keyboard.h
+++ b/src/yuzu/applets/software_keyboard.h
@@ -47,6 +47,7 @@ private:
     QLabel* header_label;
     QLabel* sub_label;
     QLabel* guide_label;
+    QLabel* length_label;
     QLineEdit* line_edit;
     QVBoxLayout* layout;