aboutsummaryrefslogtreecommitdiff
path: root/src/MainWindow.cpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-09 00:15:18 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-09 00:15:18 +0530
commit319908623e47b4e73f9af4aa4369cb895bd8df8f (patch)
tree86d40d633bf86b5bc70876c1044ac0e030524e96 /src/MainWindow.cpp
parent6d3ee55638164df6521a60b6392a26f855d5f924 (diff)
downloadnull-browser-319908623e47b4e73f9af4aa4369cb895bd8df8f.tar.gz
null-browser-319908623e47b4e73f9af4aa4369cb895bd8df8f.zip
Fix command input ui to fix to top
Diffstat (limited to '')
-rw-r--r--src/MainWindow.cpp50
1 files changed, 36 insertions, 14 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 660d731..809e5de 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -1,4 +1,5 @@
#include <QKeyEvent>
+#include <QStackedLayout>
#include <QVBoxLayout>
#include <QWebEngineView>
#include <iostream>
@@ -9,23 +10,41 @@
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);
+ auto centralWidget = new QWidget();
+ setCentralWidget(centralWidget);
+
+ auto layout = new QStackedLayout();
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+ centralWidget->setLayout(layout);
+ layout->setStackingMode(QStackedLayout::StackAll);
+
+ // Webengine
+ web = new QWebEngineView();
web->setUrl(QUrl("https://ediblemonad.dev"));
+ layout->addWidget(web);
- urlInputUI = new CommandInput(web->url().toString(), this);
- urlInputUI->setHidden(true);
- connect(urlInputUI, &CommandInput::submitted, this,
+ // Command input
+ commandInput = new CommandInput(web->url().toString());
+ hideInput();
+ commandInput->move(0, 0);
+ connect(commandInput, &CommandInput::submitted, this,
&MainWindow::evaluateCommand);
+ connect(commandInput, &CommandInput::cancelled, this, &MainWindow::hideInput);
+
+ layout->addWidget(commandInput);
+}
+
+void MainWindow::hideInput() {
+ commandInput->setInputFocus(false);
+ commandInput->setHidden(true);
}
void MainWindow::evaluateCommand(QString command) {
- web->setUrl(command);
- urlInputUI->setInputFocus(false);
- urlInputUI->setHidden(true);
+ if (!command.isEmpty())
+ web->setUrl(command);
+ hideInput();
}
void MainWindow::keyPressEvent(QKeyEvent *event) {
@@ -37,8 +56,11 @@ void MainWindow::keyPressEvent(QKeyEvent *event) {
}
void MainWindow::toggleURLInput() {
- auto hidden = urlInputUI->isHidden();
- auto shouldShow = hidden;
- urlInputUI->setHidden(!shouldShow);
- urlInputUI->setInputFocus(shouldShow);
+ auto shouldShow = commandInput->isHidden();
+ if (shouldShow) {
+ commandInput->setInputText(web->url().toString());
+ commandInput->raise();
+ }
+ commandInput->setHidden(!shouldShow);
+ commandInput->setInputFocus(shouldShow);
}