From 3d00a241b4cb8f50f0fc126af2ee8b345c6485fc Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Thu, 19 Jan 2023 13:48:25 -0800 Subject: [PATCH] initial commit --- CMakeLists.txt | 61 +++++++ CMakeLists.txt.user | 406 ++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 11 ++ mainwindow.cpp | 83 +++++++++ mainwindow.h | 50 ++++++ mainwindow.ui | 119 +++++++++++++ 6 files changed, 730 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 CMakeLists.txt.user create mode 100644 main.cpp create mode 100644 mainwindow.cpp create mode 100644 mainwindow.h create mode 100644 mainwindow.ui diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..17bf03e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,61 @@ +cmake_minimum_required(VERSION 3.5) + +project(NotepadApp VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) + +set(PROJECT_SOURCES + main.cpp + mainwindow.cpp + mainwindow.h + mainwindow.ui +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(NotepadApp + MANUAL_FINALIZATION + ${PROJECT_SOURCES} + ) +# Define target properties for Android with Qt 6 as: +# set_property(TARGET NotepadApp APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/android) +# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation +else() + if(ANDROID) + add_library(NotepadApp SHARED + ${PROJECT_SOURCES} + ) +# Define properties for Android with Qt 5 after find_package() calls as: +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") + else() + add_executable(NotepadApp + ${PROJECT_SOURCES} + ) + endif() +endif() + +target_link_libraries(NotepadApp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) + +set_target_properties(NotepadApp PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE +) + +install(TARGETS NotepadApp + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(NotepadApp) +endif() diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 0000000..4fae448 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,406 @@ + + + + + + EnvironmentId + {e0d4a5b2-a91b-4b98-af77-d66702cdf9f8} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.4.2 GCC 64bit + Desktop Qt 6.4.2 GCC 64bit + qt.qt6.642.gcc_64_kit + 0 + 0 + 0 + + Debug + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + 0 + /home/flami/Desktop/Projects/NotepadApp/../build-NotepadApp-Desktop_Qt_6_4_2_GCC_64bit-Debug + + + + + all + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + Release + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Release +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + /home/flami/Desktop/Projects/NotepadApp/../build-NotepadApp-Desktop_Qt_6_4_2_GCC_64bit-Release + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + /home/flami/Desktop/Projects/NotepadApp/../build-NotepadApp-Desktop_Qt_6_4_2_GCC_64bit-RelWithDebInfo + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + 0 + /home/flami/Desktop/Projects/NotepadApp/../build-NotepadApp-Desktop_Qt_6_4_2_GCC_64bit-Profile + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=MinSizeRel +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + /home/flami/Desktop/Projects/NotepadApp/../build-NotepadApp-Desktop_Qt_6_4_2_GCC_64bit-MinSizeRel + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 5 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + NotepadApp + CMakeProjectManager.CMakeRunConfiguration.NotepadApp + NotepadApp + false + true + true + false + true + /home/flami/Desktop/Projects/build-NotepadApp-Desktop_Qt_6_4_2_GCC_64bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..9dc8a69 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,83 @@ +#include "mainwindow.h" +#include "./ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + this->setCentralWidget(ui->textEdit); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_actionNew_triggered() +{ + currentFile.clear(); + ui->textEdit->setText(QString()); +} + +void MainWindow::on_actionOpen_triggered() +{ + QString filename = QFileDialog::getOpenFileName(this, "Open the file"); + QFile file(filename); + currentFile = filename; + if (!file.open(QIODevice::ReadOnly | QFile::Text)) { + QMessageBox::warning(this, "Warning", "Cannot open file : " + file.errorString()); + return; + } + setWindowTitle(filename); + QTextStream in(&file); + QString text = in.readAll(); + ui->textEdit->setText(text); + file.close(); +} + +void MainWindow::on_actionSave_as_triggered() +{ + QString filename = QFileDialog::getSaveFileName(this, "Save as"); + QFile file(filename); + if (!file.open(QFile::WriteOnly | QFile::Text)) { + QMessageBox::warning(this, "Warning", "Cannot save file : " + file.errorString()); + return; + } + currentFile = filename; + setWindowTitle(filename); + QTextStream out(&file); + QString text = ui->textEdit->toPlainText(); + out << text; + file.close(); +} + +void MainWindow::on_actionExit_triggered() +{ + QApplication::quit(); +} + +void MainWindow::on_actionCopy_triggered() +{ + ui->textEdit->copy(); +} + +void MainWindow::on_actionPaste_triggered() +{ + ui->textEdit->paste(); +} + +void MainWindow::on_actionCut_triggered() +{ + ui->textEdit->cut(); +} + +void MainWindow::on_actionUndo_triggered() +{ + ui->textEdit->undo(); +} + +void MainWindow::on_actionRedo_triggered() +{ + ui->textEdit->redo(); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..156b923 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,50 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + void on_actionNew_triggered(); + + void on_actionOpen_triggered(); + + void on_actionSave_as_triggered(); + + void on_actionExit_triggered(); + + void on_actionExit_2_triggered(); + + void on_actionCopy_triggered(); + + void on_actionPaste_triggered(); + + void on_actionCut_triggered(); + + void on_actionUndo_triggered(); + + void on_actionRedo_triggered(); + +private: + Ui::MainWindow *ui; + QString currentFile = ""; +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..8f87d2d --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,119 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 10 + 10 + 771 + 531 + + + + + + + + + + + + + 0 + 0 + 800 + 22 + + + + + File + + + + + + + + + + Edit + + + + + + + + + + + + + + New + + + + + Open + + + + + Save as + + + + + Print + + + + + Exit + + + + + Copy + + + + + Paste + + + + + Cut + + + + + Undo + + + + + Redo + + + + + +