aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-08 18:16:51 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-08 18:16:51 +0530
commitb7ac4dc7a20c624a343c946c5decd1b84eab2b82 (patch)
tree6e7efa381546244da8942ec023d94db634b73948
parentecd3ccde166910e3667b7b1a064e9c6db52d1646 (diff)
downloadnull-browser-b7ac4dc7a20c624a343c946c5decd1b84eab2b82.tar.gz
null-browser-b7ac4dc7a20c624a343c946c5decd1b84eab2b82.zip
Basic single view browser with url input
-rw-r--r--CMakeLists.txt44
-rw-r--r--include/CommandInput.hpp33
-rw-r--r--include/MainWindow.hpp21
-rw-r--r--src/CommandInput.cpp47
-rw-r--r--src/MainWindow.cpp44
-rw-r--r--src/main.cpp43
6 files changed, 190 insertions, 42 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c3c5c33..2a2c531 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,31 +1,43 @@
-cmake_minimum_required(VERSION 3.16)
+cmake_minimum_required(VERSION 3.25)
set(PROJECT "web-browser")
-set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-
project(${PROJECT}
- VERSION 0.0.0)
+ VERSION 0.0.0
+ LANGUAGES CXX)
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
-
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(PkgConfig REQUIRED)
-# set(CEF_PACKAGE_PATH "$ENV{CEF_PACKAGE_PATH}")
-# message(STATUS "CEF path: ${CEF_PACKAGE_PATH}")
-# include_directories(${CEF_PACKAGE_PATH} ${CEF_PACKAGE_PATH}/include)
-# link_directories(${CEF_PACKAGE_PATH}/lib)
+file(GLOB_RECURSE HEADER_FILES include/*.hpp)
+file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
+
+add_executable(${PROJECT})
+target_sources(${PROJECT} PRIVATE ${SOURCE_FILES})
+target_include_directories(${PROJECT} PRIVATE include/)
# Qt
-find_package(Qt6 REQUIRED COMPONENTS Widgets WebEngineWidgets)
+find_package(Qt6 REQUIRED COMPONENTS Core Widgets WebEngineWidgets)
+qt_standard_project_setup()
+qt_wrap_cpp(MOC_SRCS ${HEADER_FILES})
+target_sources(${PROJECT} PRIVATE ${MOC_SRCS})
+set_target_properties(${PROJECT} PROPERTIES AUTOMOC ON)
+target_link_libraries(${PROJECT}
+ Qt6::Core
+ Qt6::Widgets
+ Qt6::WebEngineWidgets)
# LuaJIT
pkg_check_modules(LuaJIT REQUIRED luajit)
include_directories(${LuaJIT_INCLUDE_DIRS})
link_directories(${LuaJIT_LIBRARY_DIRS})
-message(STATUS ":::: Lua path = ${LuaJIT_INCLUDE_DIRS} ${LuaJIT_LINK_LIBRARIES}")
+target_link_libraries(${PROJECT} ${LuaJIT_LINK_LIBRARIES})
-add_executable(${PROJECT} src/main.cpp)
-target_link_libraries(${PROJECT}
- Qt6::Widgets
- Qt6::WebEngineWidgets
- ${LuaJIT_LINK_LIBRARIES})
+# CEF (experiment)
+# set(CEF_PACKAGE_PATH "$ENV{CEF_PACKAGE_PATH}")
+# message(STATUS "CEF path: ${CEF_PACKAGE_PATH}")
+# include_directories(${CEF_PACKAGE_PATH} ${CEF_PACKAGE_PATH}/include)
+# link_directories(${CEF_PACKAGE_PATH}/lib)
+
+install(TARGETS ${PROJECT} RUNTIME DESTINATION bin)
diff --git a/include/CommandInput.hpp b/include/CommandInput.hpp
new file mode 100644
index 0000000..e6dc53d
--- /dev/null
+++ b/include/CommandInput.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <QApplication>
+#include <QDialog>
+#include <QKeyEvent>
+#include <QLabel>
+#include <QLineEdit>
+#include <QObject>
+#include <QVBoxLayout>
+#include <QWebEnginePage>
+#include <QWebEngineView>
+#include <QWidget>
+#include <QWindow>
+#include <lua.hpp>
+
+class CommandInput : public QFrame {
+ Q_OBJECT
+
+public:
+ CommandInput(QString defaultInput = "", QWidget *parentNode = nullptr);
+ void setInputFocus(bool focussed);
+ bool isInputFocussed();
+
+signals:
+ void submitted(QString command);
+
+protected:
+ void keyPressEvent(QKeyEvent *event) override;
+
+private:
+ QBoxLayout *layout;
+ QLineEdit *input;
+};
diff --git a/include/MainWindow.hpp b/include/MainWindow.hpp
new file mode 100644
index 0000000..20e07c0
--- /dev/null
+++ b/include/MainWindow.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <QMainWindow>
+#include <QObject>
+#include <QWebEngineView>
+
+#include "CommandInput.hpp"
+
+class MainWindow : public QMainWindow {
+public:
+ MainWindow();
+
+protected:
+ void keyPressEvent(QKeyEvent *event) override;
+ void toggleURLInput();
+ void evaluateCommand(QString command);
+
+private:
+ QWebEngineView *web;
+ CommandInput *urlInputUI;
+};
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);