diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-09 19:47:50 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-09 19:47:50 +0530 |
| commit | 61f99089288138989cf244d174882aa5088b738b (patch) | |
| tree | ea1202b098b92e85b16e670d1c3ea1b86fcaef58 /src/MainWindow.cpp | |
| parent | 1e2302be2b47fbeb340db7482ed8476c829a7f66 (diff) | |
| download | null-browser-61f99089288138989cf244d174882aa5088b738b.tar.gz null-browser-61f99089288138989cf244d174882aa5088b738b.zip | |
Refactor directory structure
Diffstat (limited to 'src/MainWindow.cpp')
| -rw-r--r-- | src/MainWindow.cpp | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp deleted file mode 100644 index ee8d128..0000000 --- a/src/MainWindow.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include <QKeyEvent> -#include <QStackedLayout> -#include <QVBoxLayout> -#include <QWebEngineView> - -#include "BrowserManager.hpp" -#include "CommandInput.hpp" -#include "MainWindow.hpp" - -MainWindow::MainWindow() { - setStyleSheet("background-color: #000; color: #fff;"); - setCentralWidget(new QWidget()); - - // Root stacked layout - auto layout = new QStackedLayout(); - layout->setContentsMargins(0, 0, 0, 0); - layout->setSpacing(0); - layout->setStackingMode(QStackedLayout::StackAll); - centralWidget()->setLayout(layout); - - // Web engine - browserManager = new BrowserManager(new QWebEngineProfile("web-browser")); - layout->addWidget(browserManager); - - // Command input - commandInput = new CommandInput(browserManager->currentUrl().toString()); - hideURLInput(); - commandInput->move(0, 0); - connect(commandInput, &CommandInput::submitted, this, - &MainWindow::evaluateCommand); - connect(commandInput, &CommandInput::cancelled, this, - &MainWindow::hideURLInput); - layout->addWidget(commandInput); -} - -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()) - browserManager->setCurrentUrl(command); - hideURLInput(); -} - -void MainWindow::keyPressEvent(QKeyEvent *event) { - auto combo = event->keyCombination(); - 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() { - commandInput->isHidden() ? showURLInput() : hideURLInput(); -} |
