summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorSiddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com>2025-03-25 12:41:38 -0400
committerGitHub <noreply@github.com>2025-03-25 12:41:38 -0400
commit7ad79d8430ee22b0180e7077fe727153333e47f6 (patch)
tree8d2d9df8054214d4c019ace03e33f74e6ba571d0 /gui
parent877aa98855fad77ef93a8c9f5a5e8191fbb9e699 (diff)
parent895b5ddd6fe4db906720ecbf0de0cab5acdb35ec (diff)
Merge pull request #33 from bdunahu/dev-sid
Initial GUI Commit
Diffstat (limited to 'gui')
-rw-r--r--gui/CMakeLists.txt30
-rw-r--r--gui/gui.cc39
-rw-r--r--gui/gui.h26
-rw-r--r--gui/gui.ui55
-rw-r--r--gui/main.cc89
-rw-r--r--gui/resources.qrc6
-rw-r--r--gui/resources/input.txt1
7 files changed, 246 insertions, 0 deletions
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
new file mode 100644
index 0000000..6b5eb22
--- /dev/null
+++ b/gui/CMakeLists.txt
@@ -0,0 +1,30 @@
+cmake_minimum_required(VERSION 3.5)
+set(CMAKE_CXX_COMPILER "g++")
+
+add_compile_options(-Wall -lstdc++)
+add_compile_options(-Wextra -Wpedantic)
+
+# cpp standard
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+# find QT components
+find_package(Qt6 COMPONENTS Widgets REQUIRED)
+qt_standard_project_setup()
+
+file(GLOB SRCS
+ "*.h"
+ "*.cc"
+ "*.ui"
+)
+
+# gather gui source files
+qt_add_resources(GUI_RESOURCES "resources.qrc")
+
+add_executable(risc_vector ${SRCS} ${GUI_RESOURCES})
+target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib Qt6::Widgets)
+
+set_target_properties(risc_vector PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
+)
+
diff --git a/gui/gui.cc b/gui/gui.cc
new file mode 100644
index 0000000..9f2405d
--- /dev/null
+++ b/gui/gui.cc
@@ -0,0 +1,39 @@
+#include "gui.h"
+#include "ui_gui.h"
+#include <QFile>
+#include <QTextStream>
+
+Gui::Gui(QWidget *parent)
+ : QWidget(parent)
+ , ui(new Ui::gui)
+{
+ ui->setupUi(this);
+ loadTxtFile();
+}
+
+Gui::~Gui()
+{
+ delete ui;
+}
+
+void Gui::loadTxtFile(){
+ QFile inputFile(":/resources/input.txt");
+ inputFile.open(QIODevice::ReadOnly);
+
+ QTextStream in(&inputFile);
+ QString line = in.readAll();
+ inputFile.close();
+
+ ui->textEdit->setPlainText(line);
+ QTextCursor cursor = ui->textEdit->textCursor();
+ cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
+}
+
+void Gui::on_pushButton_clicked()
+{
+ QString searchString = ui->lineEdit->text();
+ ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
+}
+
+
+
diff --git a/gui/gui.h b/gui/gui.h
new file mode 100644
index 0000000..668fafa
--- /dev/null
+++ b/gui/gui.h
@@ -0,0 +1,26 @@
+#ifndef GUI_H
+#define GUI_H
+#include <QWidget>
+
+namespace Ui
+{
+class gui;
+}
+QT_END_NAMESPACE
+
+class Gui : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ Gui(QWidget *parent = nullptr);
+ ~Gui();
+
+ private slots:
+ void on_pushButton_clicked();
+
+ private:
+ Ui::gui *ui;
+ void loadTxtFile();
+};
+#endif // GUI_H
diff --git a/gui/gui.ui b/gui/gui.ui
new file mode 100644
index 0000000..5f71c91
--- /dev/null
+++ b/gui/gui.ui
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>gui</class>
+ <widget class="QWidget" name="gui">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>gui</string>
+ </property>
+ <widget class="QWidget" name="">
+ <property name="geometry">
+ <rect>
+ <x>60</x>
+ <y>30</y>
+ <width>317</width>
+ <height>232</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>keyword</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEdit"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButton">
+ <property name="text">
+ <string>find</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="textEdit"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/gui/main.cc b/gui/main.cc
new file mode 100644
index 0000000..4c14fbe
--- /dev/null
+++ b/gui/main.cc
@@ -0,0 +1,89 @@
+#include "cli.h"
+#include "definitions.h"
+#include "gui.h"
+#include "logger.h"
+#include <QApplication>
+#include <getopt.h>
+#include <iostream>
+
+static Logger *global_log = Logger::getInstance();
+
+static std::string version_number = "v0.1";
+static std::string banner =
+ " _/_/_/ _/_/_/ _/_/_/ _/_/_/ \n"
+ " _/ _/ _/ _/ _/ \n"
+ " _/_/_/ _/ _/_/ _/ \n"
+ " _/ _/ _/ _/ _/ \n"
+ "_/ _/ _/_/_/ _/_/_/ _/_/_/ \n"
+ " \n"
+ " \n"
+ " _/_/ _/_/ \n"
+ " _/ _/ _/ _/_/_/_/ _/_/_/ _/_/_/_/_/ _/_/ _/_/_/ _/ \n"
+ " _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ \n"
+ "_/ _/ _/ _/_/_/ _/ _/ _/ _/ _/_/_/ _/ \n"
+ " _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ \n"
+ " _/ _/ _/_/_/_/ _/_/_/ _/ _/_/ _/ _/ _/ \n"
+ " _/_/ _/_/ ";
+static void print_version_number()
+{
+ std::cout << banner << version_number << '\n';
+}
+
+static void err()
+{
+ std::cerr << "Usage:\n\trisc_vector [OPTIONS]\nOptions:\n\t--debug,\t-d: "
+ "turn on verbose output\n\t--memory-only,\t-m: run the memory "
+ "simulator only, without a GUI.\n\t--version,\t-v: print the "
+ "version information and exit\n"
+ << std::endl;
+}
+
+static void parseArguments(int argc, char **argv, bool &memory_only)
+{
+ struct option long_options[] = {
+ {"debug", no_argument, 0, 'd'},
+ {"memory-only", no_argument, 0, 'm'},
+ {0, 0, 0, 0}};
+
+ int opt;
+
+ while ((opt = getopt_long(argc, argv, "d:m", long_options, NULL)) != -1) {
+ switch (opt) {
+ case 'd':
+ global_log->setLevel(DEBUG);
+ global_log->log(DEBUG, "DEBUG output enabled.");
+ break;
+ case 'm':
+ global_log->log(INFO, "Starting the storage CLI interface...");
+ memory_only = true;
+ break;
+ default:
+ err();
+ exit(EXIT_FAILURE);
+ }
+ }
+}
+
+int main(int argc, char **argv)
+{
+ print_version_number();
+ global_log->log(INFO, "Initializing...");
+
+ bool memory_only = false;
+ parseArguments(argc, argv, memory_only);
+
+ if (memory_only) {
+ Cli cli;
+ cli.run();
+ } else {
+ global_log->log(INFO, "Starting QT...");
+ QApplication a(argc, argv);
+ Gui w;
+ w.show();
+ a.exec();
+ }
+
+ global_log->log(INFO, "Cleaning up...");
+ global_log->log(INFO, "Goodbye!");
+ return EXIT_SUCCESS;
+}
diff --git a/gui/resources.qrc b/gui/resources.qrc
new file mode 100644
index 0000000..8bfd4e7
--- /dev/null
+++ b/gui/resources.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC>
+<RCC version="1.0">
+ <qresource prefix="/resources">
+ <file alias="input.txt">resources/input.txt</file>
+ </qresource>
+</RCC>
diff --git a/gui/resources/input.txt b/gui/resources/input.txt
new file mode 100644
index 0000000..fc1c3cf
--- /dev/null
+++ b/gui/resources/input.txt
@@ -0,0 +1 @@
+Lorem Ipsum \ No newline at end of file