From b7ac4dc7a20c624a343c946c5decd1b84eab2b82 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 8 Mar 2025 18:16:51 +0530 Subject: Basic single view browser with url input --- src/MainWindow.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/MainWindow.cpp (limited to 'src/MainWindow.cpp') diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp new file mode 100644 index 0000000..660d731 --- /dev/null +++ b/src/MainWindow.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "CommandInput.hpp" +#include "MainWindow.hpp" + +MainWindow::MainWindow() { + setStyleSheet("background-color: #000; color: #fff;"); + // layout = new QVBoxLayout(this); + // layout->setContentsMargins(0, 0, 0, 0); + + web = new QWebEngineView(this); + web->setGeometry(200, 10, 500, 500); + web->setUrl(QUrl("https://ediblemonad.dev")); + + urlInputUI = new CommandInput(web->url().toString(), this); + urlInputUI->setHidden(true); + connect(urlInputUI, &CommandInput::submitted, this, + &MainWindow::evaluateCommand); +} + +void MainWindow::evaluateCommand(QString command) { + web->setUrl(command); + urlInputUI->setInputFocus(false); + urlInputUI->setHidden(true); +} + +void MainWindow::keyPressEvent(QKeyEvent *event) { + auto combo = event->keyCombination(); + if (combo.key() == Qt::Key_L && + combo.keyboardModifiers().testFlag(Qt::ControlModifier)) { + toggleURLInput(); + } +} + +void MainWindow::toggleURLInput() { + auto hidden = urlInputUI->isHidden(); + auto shouldShow = hidden; + urlInputUI->setHidden(!shouldShow); + urlInputUI->setInputFocus(shouldShow); +} -- cgit v1.3.1