diff options
Diffstat (limited to '')
| -rw-r--r-- | src/CommandInput.cpp | 28 | ||||
| -rw-r--r-- | src/MainWindow.cpp | 50 | ||||
| -rw-r--r-- | src/main.cpp | 1 | ||||
| -rw-r--r-- | src/play.cpp.old | 62 |
4 files changed, 55 insertions, 86 deletions
diff --git a/src/CommandInput.cpp b/src/CommandInput.cpp index cf7346c..d553d19 100644 --- a/src/CommandInput.cpp +++ b/src/CommandInput.cpp @@ -1,3 +1,4 @@ +#include <QHBoxLayout> #include <QKeyEvent> #include <QLineEdit> #include <QVBoxLayout> @@ -8,29 +9,36 @@ #include "CommandInput.hpp" CommandInput::CommandInput(QString defaultInput, QWidget *parentNode) - : QFrame(parentNode) { + : QWidget(parentNode) { setContentsMargins(0, 0, 0, 0); - // setFrameRect(QRect(0, 0, parentWidget()->width(), 50)); - setFixedWidth(parentWidget()->width()); - setFrameShadow(QFrame::Shadow::Raised); - setFrameShape(QFrame::Box); - setStyleSheet("background-color: #333; color: #fff;"); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + setStyleSheet("background-color: #000; color: #fff; border-radius: 0;"); auto layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); input = new QLineEdit(defaultInput, this); - input->setContentsMargins(0, 0, 0, 0); input->setFocusPolicy(Qt::StrongFocus); layout->addWidget(input); + setFixedHeight(input->sizeHint().height()); } +void CommandInput::emitSubmit() { emit submitted(getInputCommand()); } + void CommandInput::keyPressEvent(QKeyEvent *event) { auto combo = event->keyCombination(); - if (combo.key() == Qt::Key_Return) { - emit submitted(getInputCommand()); - } + auto ctrlL = combo.key() == Qt::Key_L && + combo.keyboardModifiers().testFlag(Qt::ControlModifier); + auto esc = combo.key() == Qt::Key_Escape; + auto enter = combo.key() == Qt::Key_Return || combo.key() == Qt::Key_Enter; + + if (esc || ctrlL) + emit cancelled(); + else if (enter) + emitSubmit(); } +void CommandInput::setInputText(QString text) { input->setText(text); } + bool CommandInput::isInputFocussed() { return input->hasFocus(); } void CommandInput::setInputFocus(bool focussed) { 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); } diff --git a/src/main.cpp b/src/main.cpp index 4f23e38..91e605e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "MainWindow.hpp" int main(int argc, char *argv[]) { + // QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); QApplication app(argc, argv); MainWindow mainWindow; diff --git a/src/play.cpp.old b/src/play.cpp.old deleted file mode 100644 index 4a61043..0000000 --- a/src/play.cpp.old +++ /dev/null @@ -1,62 +0,0 @@ -#include <QApplication> -#include <QVBoxLayout> -#include <QWidget> -#include <cef_app.h> -#include <cef_browser.h> -#include <cef_client.h> -#include <internal/cef_string.h> -#include <iostream> -#include <ostream> - -class CEFWidget : public QWidget { -public: - explicit CEFWidget(QWidget *parent = nullptr) : QWidget(parent) { - setFixedSize(400, 400); - - // TODO: Args - char *argv[] = {}; - int argc = 0; - - std::cout << "ficlk" << std::endl; - - // Create browser - CefWindowInfo window_info; - CefBrowserSettings browser_settings; - window_info.SetAsChild(winId(), {0, 0, 400, 400}); - CefBrowserHost::CreateBrowser(window_info, nullptr, "https://www.qt.io", - browser_settings, nullptr, nullptr); - } - - ~CEFWidget() { CefShutdown(); } -}; - -int main(int argc, char *argv[]) { - CefMainArgs main_args(argc, argv); - CefRefPtr<CefApp> cefApp; - int exit_code = CefExecuteProcess(main_args, cefApp, nullptr); - if (exit_code >= 0) { - return exit_code; - } - - CefMainArgs args(argc, argv); - CefSettings settings; - CefString(&settings.resources_dir_path) - .FromWString(L"/home/imsohexy/dev/projects/web-browser/build/lib/"); - CefString(&settings.locales_dir_path) - .FromWString( - L"/home/imsohexy/dev/projects/web-browser/build/lib/locales/"); - CefString(&settings.root_cache_path) - .FromWString(L"/home/imsohexy/dev/projects/web-browser/.cache/cef"); - settings.no_sandbox = true; - settings.pack_loading_disabled = true; - CefInitialize(args, settings, nullptr, nullptr); - - QApplication app(argc, argv); - QWidget mainWindow; - mainWindow.setWindowTitle("web-browser"); - QVBoxLayout layout(&mainWindow); - // CEFWidget cefWidget(&mainWindow); - // layout.addWidget(&cefWidget); - mainWindow.show(); - return app.exec(); -} |
