From 319908623e47b4e73f9af4aa4369cb895bd8df8f Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 9 Mar 2025 00:15:18 +0530 Subject: Fix command input ui to fix to top --- src/CommandInput.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/CommandInput.cpp') diff --git a/src/CommandInput.cpp b/src/CommandInput.cpp index cf7346c..d553d19 100644 --- a/src/CommandInput.cpp +++ b/src/CommandInput.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,29 +9,36 @@ #include "CommandInput.hpp" CommandInput::CommandInput(QString defaultInput, QWidget *parentNode) - : QFrame(parentNode) { + : QWidget(parentNode) { setContentsMargins(0, 0, 0, 0); - // setFrameRect(QRect(0, 0, parentWidget()->width(), 50)); - setFixedWidth(parentWidget()->width()); - setFrameShadow(QFrame::Shadow::Raised); - setFrameShape(QFrame::Box); - setStyleSheet("background-color: #333; color: #fff;"); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + setStyleSheet("background-color: #000; color: #fff; border-radius: 0;"); auto layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); input = new QLineEdit(defaultInput, this); - input->setContentsMargins(0, 0, 0, 0); input->setFocusPolicy(Qt::StrongFocus); layout->addWidget(input); + setFixedHeight(input->sizeHint().height()); } +void CommandInput::emitSubmit() { emit submitted(getInputCommand()); } + void CommandInput::keyPressEvent(QKeyEvent *event) { auto combo = event->keyCombination(); - if (combo.key() == Qt::Key_Return) { - emit submitted(getInputCommand()); - } + auto ctrlL = combo.key() == Qt::Key_L && + combo.keyboardModifiers().testFlag(Qt::ControlModifier); + auto esc = combo.key() == Qt::Key_Escape; + auto enter = combo.key() == Qt::Key_Return || combo.key() == Qt::Key_Enter; + + if (esc || ctrlL) + emit cancelled(); + else if (enter) + emitSubmit(); } +void CommandInput::setInputText(QString text) { input->setText(text); } + bool CommandInput::isInputFocussed() { return input->hasFocus(); } void CommandInput::setInputFocus(bool focussed) { -- cgit v1.3.1