From 5a602a1192e2900c7df7c02712b84bbeae2fb553 Mon Sep 17 00:00:00 2001 From: Remisa Yousefvand Date: Sun, 6 Oct 2024 22:33:17 +0330 Subject: [PATCH 1/2] UI completed --- CMakeLists.txt.user | 26 +++++++++++++------------- src/mainwindow.cpp | 23 +++++++++++++++++++++++ src/mainwindow.h | 5 +++++ src/mainwindow.ui | 22 ++++++++++++++++++++-- 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 2c1a4f4..6e800f5 100755 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -102,14 +102,14 @@ 2 false - -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_BUILD_TYPE:STRING=Debug --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} + -DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_GENERATOR:STRING=Ninja /data/Code/Qt/Notepad-- 0 /data/Code/Qt/Notepad--/build/Desktop-Debug @@ -160,14 +160,14 @@ 2 false - -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_BUILD_TYPE:STRING=Release --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} + -DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_GENERATOR:STRING=Ninja /data/Code/Qt/Notepad-- /data/Code/Qt/Notepad--/build/Desktop-Release diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 59cfa22..123def5 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -21,6 +21,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); + QMenu *menuLanguage = ui->menu_Language; + QMenu *menuZ = new QMenu("z", this); + QAction *actionZ80 = new QAction("Z80", this); + menuZ->addAction(actionZ80); + menuLanguage->addMenu(menuZ); + connect(actionZ80, &QAction::triggered, this, &MainWindow::onActionZ80Triggered); + QActionGroup *group = new QActionGroup(this); group->setExclusive(true); // Ensure only one action is checked at a time @@ -305,3 +312,19 @@ void MainWindow::on_action_Word_wrap_triggered() // TODO: Word Wrap } +void MainWindow::onActionZ80Triggered() +{ + qDebug() << "Z80 action triggered!"; +} + +void MainWindow::on_actionAbout_Qt_triggered() +{ + QApplication::aboutQt(); +} + + +void MainWindow::on_action_About_Notepad_triggered() +{ + // TODO: About Remisa Yousefvand +} + diff --git a/src/mainwindow.h b/src/mainwindow.h index 9f69b73..964f13b 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -36,6 +36,7 @@ private slots: void on_actionC_lose_all_triggered(); void on_actionC_3_triggered(); void on_actionPython_triggered(); + void onActionZ80Triggered(); void on_actionSav_e_all_triggered(); @@ -57,6 +58,10 @@ private slots: void on_action_Word_wrap_triggered(); + void on_actionAbout_Qt_triggered(); + + void on_action_About_Notepad_triggered(); + private: Ui::MainWindow *ui; void initialize(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index fb50faf..c844637 100755 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -219,7 +219,6 @@ - @@ -519,6 +518,7 @@ Settin&gs + @@ -834,6 +834,9 @@ true + + + &Word wrap @@ -900,7 +903,7 @@ - Convert to UTF-8 + &Convert to UTF-8 @@ -929,11 +932,23 @@ + + true + + + true + &Show Menubar + + true + + + true + S&how Toolbar @@ -949,6 +964,9 @@ + + + &Open a new window From 927f0e356e4c551e6d23b0e10990609e12331f8f Mon Sep 17 00:00:00 2001 From: Remisa Yousefvand Date: Mon, 7 Oct 2024 16:46:22 +0330 Subject: [PATCH 2/2] apply highlighting fixed --- .github/workflows/cmake-multi-platform.yml | 13 +++++-- CMakeLists.txt.user | 26 ++++++------- src/document.cpp | 44 +++++++++------------- src/document.h | 2 +- src/languages/languagemanager.cpp | 19 +++++++--- 5 files changed, 54 insertions(+), 50 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 6c650e9..2847656 100755 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -35,9 +35,9 @@ jobs: - name: Install dependencies (Ubuntu) if: matrix.os == 'ubuntu-latest' run: | - sudo apt-get update - sudo apt-get install -y libgl1-mesa-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev ninja-build qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools - echo "CMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt5" >> $GITHUB_ENV + sudo apt-get update + sudo apt-get install -y ninja-build qt6-base-dev qt6-base-dev-tools qt6-qmake + echo "CMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt6" >> $GITHUB_ENV # Install dependencies for macOS - name: Install dependencies (macOS) @@ -49,7 +49,12 @@ jobs: # Set up MSVC on Windows - name: Set up MSVC (Windows) if: matrix.os == 'windows-latest' - uses: microsoft/setup-msbuild@v1 # Corrected action + uses: microsoft/setup-msbuild@v1 # Ensure MSVC is set up + - name: Set up VC Environment (Windows) + if: matrix.os == 'windows-latest' + uses: microsoft/setup-vc@v1 + with: + arch: x64 # Set reusable strings - name: Set reusable strings diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 6e800f5..d450ba8 100755 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -102,14 +102,14 @@ 2 false - -DCMAKE_BUILD_TYPE:STRING=Debug --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} + -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Debug -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake /data/Code/Qt/Notepad-- 0 /data/Code/Qt/Notepad--/build/Desktop-Debug @@ -160,14 +160,14 @@ 2 false - -DCMAKE_BUILD_TYPE:STRING=Release --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} + -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Release -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake /data/Code/Qt/Notepad-- /data/Code/Qt/Notepad--/build/Desktop-Release diff --git a/src/document.cpp b/src/document.cpp index c3bbf51..7bef2f2 100755 --- a/src/document.cpp +++ b/src/document.cpp @@ -36,26 +36,17 @@ Document::Document(const QString &filePath, QWidget *parent) m_fileLoaderWorker = new FileLoaderWorker(m_filePath, this); m_fileLoaderWorker->moveToThread(m_workerThread); - // Connect worker signals - connect(m_fileLoaderWorker, &FileLoaderWorker::loadingStarted, this, &Document::onLoadingStarted); - connect(m_fileLoaderWorker, &FileLoaderWorker::errorOccurred, this, &Document::onLoadingError); - connect(m_fileLoaderWorker, &FileLoaderWorker::contentLoaded, this, &Document::onContentLoaded, Qt::UniqueConnection); - connect(m_fileLoaderWorker, &FileLoaderWorker::fileSizeDetermined, this, &Document::onFileSizeDetermined); - - connect(m_fileLoaderWorker, &FileLoaderWorker::savingStarted, this, &Document::onSavingStarted); - connect(m_fileLoaderWorker, &FileLoaderWorker::savingProgress, this, &Document::onSavingProgress); - connect(m_fileLoaderWorker, &FileLoaderWorker::savingFinished, this, &Document::onSavingFinished); - connect(this, &Document::savingProgress, m_progressBar, &QProgressBar::setValue); - - connect(m_fileLoaderWorker, &FileLoaderWorker::loadingProgress, this, &Document::onLoadingProgress, Qt::UniqueConnection); - /* - connect(m_fileLoaderWorker, &FileLoaderWorker::loadingProgress, this, [this](int progress) { - QMetaObject::invokeMethod(m_progressBar, "setValue", Qt::QueuedConnection, Q_ARG(int, progress)); - }); - */ - - connect(m_fileLoaderWorker, &FileLoaderWorker::loadingFinished, this, &Document::onLoadingFinished); - connect(m_fileLoaderWorker, &FileLoaderWorker::savingFinished, this, &Document::onSavingFinished); + connect(m_fileLoaderWorker, &FileLoaderWorker::loadingStarted, this, &Document::onLoadingStarted, Qt::QueuedConnection); + connect(m_fileLoaderWorker, &FileLoaderWorker::errorOccurred, this, &Document::onLoadingError, Qt::QueuedConnection); + connect(m_fileLoaderWorker, &FileLoaderWorker::contentLoaded, this, &Document::onContentLoaded, Qt::QueuedConnection); + connect(m_fileLoaderWorker, &FileLoaderWorker::fileSizeDetermined, this, &Document::onFileSizeDetermined, Qt::QueuedConnection); + connect(m_fileLoaderWorker, &FileLoaderWorker::savingStarted, this, &Document::onSavingStarted, Qt::QueuedConnection); + connect(m_fileLoaderWorker, &FileLoaderWorker::savingProgress, this, &Document::onSavingProgress, Qt::QueuedConnection); + connect(m_fileLoaderWorker, &FileLoaderWorker::savingFinished, this, &Document::onSavingFinished, Qt::QueuedConnection); + connect(m_fileLoaderWorker, &FileLoaderWorker::loadingProgress, this, &Document::onLoadingProgress, Qt::QueuedConnection); + connect(m_fileLoaderWorker, &FileLoaderWorker::loadingFinished, this, &Document::onLoadingFinished, Qt::QueuedConnection); + connect(this, &Document::savingProgress, m_progressBar, &QProgressBar::setValue, Qt::QueuedConnection); + connect(m_fileLoaderWorker, &FileLoaderWorker::savingFinished, this, &Document::onSavingFinished, Qt::QueuedConnection); // Start worker thread m_workerThread->start(); @@ -183,7 +174,9 @@ QString Document::filePath() const { void Document::openFile(const QString &filePath) { m_filePath = filePath; - qDebug() << "Opening file:" << m_filePath; + qDebug() << "Opening file: " << m_filePath; + m_fileExtension = QFileInfo(filePath).suffix(); + qDebug() << "file extension is: " << m_filePath; qDebug() << "About to emit uiReady signal from openFile..."; // Emit the signal to start loading the file in the worker thread @@ -304,15 +297,14 @@ void Document::goToLineNumberInText(QWidget* parent) { void Document::applySyntaxHighlighter(const QString &language) { qDebug() << "Applying syntax highlighter for language:" << language; - if (syntaxHighlighter) { - delete syntaxHighlighter; - syntaxHighlighter = nullptr; - } + // Automatically replaces and deletes the old syntax highlighter if it exists + syntaxHighlighter = nullptr; // Assuming LanguageManager handles creating syntax highlighters for specific languages - syntaxHighlighter = LanguageManager::createHighlighterForExtension(language, editor->document()); + syntaxHighlighter = std::unique_ptr(LanguageManager::createHighlighterForExtension(language, editor->document())); if (syntaxHighlighter) { + qDebug() << "Rehighlighting document..."; syntaxHighlighter->rehighlight(); qDebug() << "Syntax highlighter applied for language:" << language; } else { diff --git a/src/document.h b/src/document.h index 577c395..56b68ed 100755 --- a/src/document.h +++ b/src/document.h @@ -84,7 +84,7 @@ private slots: QString m_fileExtension; QFile m_file; CodeEditor *editor; - QSyntaxHighlighter *syntaxHighlighter; + std::unique_ptr syntaxHighlighter; qint64 m_fileSize; QMap m_changedSegments; QString m_currentText; diff --git a/src/languages/languagemanager.cpp b/src/languages/languagemanager.cpp index 32bb164..e7f3197 100755 --- a/src/languages/languagemanager.cpp +++ b/src/languages/languagemanager.cpp @@ -3,15 +3,22 @@ #include "pythonsyntaxhighlighter.h" QSyntaxHighlighter* LanguageManager::createHighlighterForExtension(const QString &identifier, QTextDocument *document) { - if (identifier == "C++" || identifier == "cpp" || identifier == "cxx" || identifier == "h" || identifier == "hpp") { - return new CppSyntaxHighlighter(document); - } else if (identifier == "Python" || identifier == "py") { - return new PythonSyntaxHighlighter(document); + qDebug() << "Creating highlighter for language:" << identifier << "with document:" << document; + if (document == nullptr) { + qDebug() << "Error: document is nullptr"; + return nullptr; } - // Add more language mappings here as needed + // Create highlighter based on language identifier + if (identifier == "C++") { + auto* highlighter = new CppSyntaxHighlighter(document); + qDebug() << "Created C++ syntax highlighter at:" << highlighter; + return highlighter; + } - return nullptr; // Return nullptr if no matching highlighter is found + // Return nullptr if no matching highlighter is found + qDebug() << "Error: No matching highlighter found for language:" << identifier; + return nullptr; } QString LanguageManager::getLanguageFromExtension(const QString &extension) {