diff options
Diffstat (limited to 'src/MainWindow.cpp')
| -rw-r--r-- | src/MainWindow.cpp | 50 |
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); } |
