From 971854bfefad4c644ac3d5f5d6003f24d551bf1d Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Mon, 10 Mar 2025 22:04:24 +0530 Subject: Add completer + simplify command parsing + class generator --- src/widgets/CommandInput.cpp | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'src/widgets/CommandInput.cpp') diff --git a/src/widgets/CommandInput.cpp b/src/widgets/CommandInput.cpp index 464065a..3ea0f38 100644 --- a/src/widgets/CommandInput.cpp +++ b/src/widgets/CommandInput.cpp @@ -1,23 +1,57 @@ +#include #include #include +#include #include +#include #include #include +#include #include +#include +#include +#include +#include "completion/CommandsModel.hpp" +#include "completion/Completer.hpp" #include "widgets/CommandInput.hpp" +const char *rootStyles = R"( + background-color: #000; + color: #fff; + border-radius: 0; +)"; + CommandInput::CommandInput(QString defaultInput, QWidget *parentNode) : QWidget(parentNode) { setContentsMargins(0, 0, 0, 0); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - setStyleSheet("background-color: #000; color: #fff; border-radius: 0;"); + setStyleSheet(rootStyles); auto layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); - input = new QLineEdit(defaultInput, this); + + auto listModel = new CommandsModel(); + auto completer = new Completer(this); + completer->setModel(listModel); + + auto cmdLineBox = new QWidget(); + layout->addWidget(cmdLineBox); + auto cmdLineLayout = new QHBoxLayout(); + cmdLineBox->setLayout(cmdLineLayout); + cmdLineBox->layout()->setContentsMargins(0, 0, 0, 0); + cmdLineLayout->setSpacing(0); + + auto promptPrefix = new QLabel(tr(":")); + promptPrefix->setContentsMargins(0, 0, 0, 0); + input = new QLineEdit(defaultInput); input->setFocusPolicy(Qt::StrongFocus); - layout->addWidget(input); + input->setCompleter(completer); + // input->installEventFilter(completer); + + cmdLineLayout->addWidget(promptPrefix); + cmdLineLayout->addWidget(input); + setFixedHeight(input->sizeHint().height()); } -- cgit v1.3.1