diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-09 18:15:12 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-09 19:42:39 +0530 |
| commit | 1e2302be2b47fbeb340db7482ed8476c829a7f66 (patch) | |
| tree | d71091727c79de4c800355c68c98107ba5237040 /src/MainWindow.cpp | |
| parent | 0e276c49adc1ef38993f1a90b0f87c732331598c (diff) | |
| download | null-browser-1e2302be2b47fbeb340db7482ed8476c829a7f66.tar.gz null-browser-1e2302be2b47fbeb340db7482ed8476c829a7f66.zip | |
Add browser manager + add multitab management (next/prev/close/new)
Diffstat (limited to '')
| -rw-r--r-- | src/MainWindow.cpp | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 809e5de..ee8d128 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -2,49 +2,53 @@ #include <QStackedLayout> #include <QVBoxLayout> #include <QWebEngineView> -#include <iostream> -#include <lua.hpp> +#include "BrowserManager.hpp" #include "CommandInput.hpp" #include "MainWindow.hpp" MainWindow::MainWindow() { setStyleSheet("background-color: #000; color: #fff;"); + setCentralWidget(new QWidget()); - auto centralWidget = new QWidget(); - setCentralWidget(centralWidget); - + // Root stacked layout auto layout = new QStackedLayout(); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); - centralWidget->setLayout(layout); layout->setStackingMode(QStackedLayout::StackAll); + centralWidget()->setLayout(layout); - // Webengine - web = new QWebEngineView(); - web->setUrl(QUrl("https://ediblemonad.dev")); - layout->addWidget(web); + // Web engine + browserManager = new BrowserManager(new QWebEngineProfile("web-browser")); + layout->addWidget(browserManager); // Command input - commandInput = new CommandInput(web->url().toString()); - hideInput(); + commandInput = new CommandInput(browserManager->currentUrl().toString()); + hideURLInput(); commandInput->move(0, 0); connect(commandInput, &CommandInput::submitted, this, &MainWindow::evaluateCommand); - connect(commandInput, &CommandInput::cancelled, this, &MainWindow::hideInput); - + connect(commandInput, &CommandInput::cancelled, this, + &MainWindow::hideURLInput); layout->addWidget(commandInput); } -void MainWindow::hideInput() { +void MainWindow::hideURLInput() { commandInput->setInputFocus(false); commandInput->setHidden(true); } +void MainWindow::showURLInput() { + commandInput->setInputText(browserManager->currentUrl().toString()); + commandInput->raise(); + commandInput->setHidden(false); + commandInput->setInputFocus(true); +} + void MainWindow::evaluateCommand(QString command) { if (!command.isEmpty()) - web->setUrl(command); - hideInput(); + browserManager->setCurrentUrl(command); + hideURLInput(); } void MainWindow::keyPressEvent(QKeyEvent *event) { @@ -52,15 +56,21 @@ void MainWindow::keyPressEvent(QKeyEvent *event) { if (combo.key() == Qt::Key_L && combo.keyboardModifiers().testFlag(Qt::ControlModifier)) { toggleURLInput(); + } else if (combo.key() == Qt::Key_T && + combo.keyboardModifiers().testFlag(Qt::ControlModifier)) { + browserManager->createNewWebView(QUrl("https://duckduckgo.com"), true); + } else if (combo.key() == Qt::Key_J && + combo.keyboardModifiers().testFlag(Qt::ControlModifier)) { + browserManager->nextWebView(); + } else if (combo.key() == Qt::Key_K && + combo.keyboardModifiers().testFlag(Qt::ControlModifier)) { + browserManager->previousWebView(); + } else if (combo.key() == Qt::Key_W && + combo.keyboardModifiers().testFlag(Qt::ControlModifier)) { + browserManager->closeCurrentWebView(); } } void MainWindow::toggleURLInput() { - auto shouldShow = commandInput->isHidden(); - if (shouldShow) { - commandInput->setInputText(web->url().toString()); - commandInput->raise(); - } - commandInput->setHidden(!shouldShow); - commandInput->setInputFocus(shouldShow); + commandInput->isHidden() ? showURLInput() : hideURLInput(); } |
