diff options
Diffstat (limited to '')
| -rw-r--r-- | src/CommandInput.cpp | 47 | ||||
| -rw-r--r-- | src/MainWindow.cpp | 44 | ||||
| -rw-r--r-- | src/main.cpp | 43 |
3 files changed, 108 insertions, 26 deletions
diff --git a/src/CommandInput.cpp b/src/CommandInput.cpp new file mode 100644 index 0000000..b168536 --- /dev/null +++ b/src/CommandInput.cpp @@ -0,0 +1,47 @@ +#include <QApplication> +#include <QDialog> +#include <QKeyEvent> +#include <QLabel> +#include <QLineEdit> +#include <QObject> +#include <QVBoxLayout> +#include <QWebEnginePage> +#include <QWebEngineView> +#include <QWidget> +#include <QWindow> +#include <iostream> +#include <lua.hpp> + +#include "CommandInput.hpp" + +CommandInput::CommandInput(QString defaultInput, QWidget *parentNode) + : QFrame(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;"); + + auto layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + input = new QLineEdit(defaultInput, this); + input->setContentsMargins(0, 0, 0, 0); + layout->addWidget(input); +} + +void CommandInput::keyPressEvent(QKeyEvent *event) { + auto combo = event->keyCombination(); + if (combo.key() == Qt::Key_Return) { + emit submitted(input->text()); + } +} + +bool CommandInput::isInputFocussed() { return input->hasFocus(); } + +void CommandInput::setInputFocus(bool focussed) { + if (focussed) + input->setFocus(); + else + input->clearFocus(); +} diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp new file mode 100644 index 0000000..660d731 --- /dev/null +++ b/src/MainWindow.cpp @@ -0,0 +1,44 @@ +#include <QKeyEvent> +#include <QVBoxLayout> +#include <QWebEngineView> +#include <iostream> +#include <lua.hpp> + +#include "CommandInput.hpp" +#include "MainWindow.hpp" + +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); + web->setUrl(QUrl("https://ediblemonad.dev")); + + urlInputUI = new CommandInput(web->url().toString(), this); + urlInputUI->setHidden(true); + connect(urlInputUI, &CommandInput::submitted, this, + &MainWindow::evaluateCommand); +} + +void MainWindow::evaluateCommand(QString command) { + web->setUrl(command); + urlInputUI->setInputFocus(false); + urlInputUI->setHidden(true); +} + +void MainWindow::keyPressEvent(QKeyEvent *event) { + auto combo = event->keyCombination(); + if (combo.key() == Qt::Key_L && + combo.keyboardModifiers().testFlag(Qt::ControlModifier)) { + toggleURLInput(); + } +} + +void MainWindow::toggleURLInput() { + auto hidden = urlInputUI->isHidden(); + auto shouldShow = hidden; + urlInputUI->setHidden(!shouldShow); + urlInputUI->setInputFocus(shouldShow); +} diff --git a/src/main.cpp b/src/main.cpp index 8fbfee1..4f23e38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,36 +1,27 @@ #include <QApplication> -#include <QVBoxLayout> -#include <QWebEngineView> -#include <QWidget> +#include <QMainWindow> #include <lua.hpp> -int main(int argc, char *argv[]) { - auto L = luaL_newstate(); - - luaL_openlibs(L); /* Load Lua libraries */ - - /* Load the file containing the script we are going to run */ - auto status = luaL_dostring(L, "print(500 + 10 * 3)"); - if (status) { - /* If something went wrong, error message is at the top of */ - /* the stack */ - fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1)); - exit(1); - } - lua_close(L); - exit(0); +#include "MainWindow.hpp" +int main(int argc, char *argv[]) { QApplication app(argc, argv); - QWidget mainWindow; - mainWindow.setWindowTitle("web-browser"); - - auto layout = new QVBoxLayout(&mainWindow); - auto view = new QWebEngineView(); - view->setFixedSize(400, 400); - view->setUrl(QUrl("https://ediblemonad.dev")); - layout->addWidget(view); + MainWindow mainWindow; + mainWindow.setWindowTitle("web-browser"); mainWindow.show(); return app.exec(); } + +// auto L = luaL_newstate(); +// +// luaL_openlibs(L); +// +// auto status = luaL_dostring(L, "print(500 + 10 * 3)"); +// if (status) { +// fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1)); +// exit(1); +// } +// lua_close(L); +// exit(0); |
