From dee70a542bb70a2a16551151cab50da5e7abdabb Mon Sep 17 00:00:00 2001 From: Remisa Yousefvand Date: Tue, 3 Dec 2024 01:08:16 +0330 Subject: [PATCH] v0.0.60 --- CHANGELOG.md | 8 +++++- CMakeLists.txt | 4 +++ CMakeLists.txt.user | 26 +++++++++--------- src/codeeditor.cpp | 33 ++++++++++++++++++++--- src/codeeditor.h | 3 +++ src/mainwindow.cpp | 27 +++++++++++++++++-- src/mainwindow.h | 4 +++ src/mainwindow/mainwindowconfigloader.cpp | 23 ++++++++++++++++ src/mainwindow/mainwindowconfigloader.h | 17 ++++++++++++ 9 files changed, 126 insertions(+), 19 deletions(-) create mode 100644 src/mainwindow/mainwindowconfigloader.cpp create mode 100644 src/mainwindow/mainwindowconfigloader.h diff --git a/CHANGELOG.md b/CHANGELOG.md index df20279..4bcd9b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log -======= +============ + +## 0.0.60 + +- Implemented: +- View Menu -> Show Space + ## 0.0.59 - Default Tab Fixed diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ece581..b5f0e49 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,8 @@ set(PROJECT_UI src/systemsearchresultdialog.ui ) +set(CMAKE_AUTOUIC_SEARCH_PATHS src) + set(PROJECT_SOURCES src/main.cpp src/mainwindow.cpp @@ -100,6 +102,8 @@ set(PROJECT_SOURCES src/systemsearchresultdialog.h src/systemtextdelegate.cpp src/systemtextdelegate.h + src/mainwindow/mainwindowconfigloader.cpp + src/mainwindow/mainwindowconfigloader.h ${PROJECT_UI} ) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 8c9f9f7..a1e8596 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} --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake + -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} /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} --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake + -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} /data/Code/Qt/Notepad-- /data/Code/Qt/Notepad--/build/Desktop-Release diff --git a/src/codeeditor.cpp b/src/codeeditor.cpp index de48379..ccef56e 100755 --- a/src/codeeditor.cpp +++ b/src/codeeditor.cpp @@ -31,6 +31,7 @@ CodeEditor::CodeEditor(QWidget *parent) m_useTabs = Settings::instance()->loadSetting("Indentation", "Option", "Tabs") == "Tabs"; m_indentationWidth = Settings::instance()->loadSetting("Indentation", "Size", "1").toInt(); m_showTabs = Settings::instance()->loadSetting("View", "ShowTabs", "false") == "true"; + m_showSpaces = Settings::instance()->loadSetting("View", "ShowSpaces", "false") == "true"; m_tabWidth = Settings::instance()->loadSetting("View", "TabWidth", "4").toInt(); } @@ -263,10 +264,22 @@ void CodeEditor::setShowTabs(bool enabled) { } } +void CodeEditor::setShowSpaces(bool enabled) { + if (m_showSpaces != enabled) { + m_showSpaces = enabled; + viewport()->update(); // Redraw the editor to show or hide tab symbols + } +} + bool CodeEditor::showTabs() const { return m_showTabs; } +bool CodeEditor::showSpaces() const { + return m_showSpaces; +} + +// TODO: Implement in UI void CodeEditor::setTabWidth(int width = 4) { m_tabWidth = width; viewport()->update(); // Trigger a repaint to apply the new width @@ -275,7 +288,7 @@ void CodeEditor::setTabWidth(int width = 4) { void CodeEditor::paintEvent(QPaintEvent *event) { QPlainTextEdit::paintEvent(event); - if (!m_showTabs) return; + if (!m_showTabs && !m_showSpaces) return; QPainter painter(viewport()); painter.setPen(Qt::gray); @@ -290,7 +303,7 @@ void CodeEditor::paintEvent(QPaintEvent *event) { // Iterate over characters in the block for (int i = 0; i < text.length(); ++i) { - if (text[i] == '\t') { + if (text[i] == '\t' && m_showTabs) { // Move the cursor to the tab character blockCursor.setPosition(blockStart + i); @@ -298,11 +311,25 @@ void CodeEditor::paintEvent(QPaintEvent *event) { QRect rect = cursorRect(blockCursor); // Adjust the position for the tab symbol - //QPoint position(rect.left(), rect.top() + metrics.ascent()); QPoint position(rect.left() + metrics.ascent(), rect.top() + metrics.ascent()); // Draw the tab symbol painter.drawText(position, "→"); + } else if (text[i] == ' ' && m_showSpaces) { + // Move the cursor to the space character + blockCursor.setPosition(blockStart + i); + + // Get the rectangle of the cursor position + QRect rect = cursorRect(blockCursor); + + // Adjust the position for the space dot + QPoint position( + rect.left() + metrics.horizontalAdvance(' ') / 4, // Push right slightly + rect.top() + metrics.ascent() / 2 + metrics.height() / 3 // Vertically center the dot lower + ); + + // Draw the space as a dot + painter.drawText(position, "."); } } block = block.next(); diff --git a/src/codeeditor.h b/src/codeeditor.h index a8a5360..8f2606a 100755 --- a/src/codeeditor.h +++ b/src/codeeditor.h @@ -25,7 +25,9 @@ class CodeEditor : public QPlainTextEdit { void goToLineInText(int lineNumber); void gotoLineInEditor(int lineNumber); void setShowTabs(bool enabled); + void setShowSpaces(bool enabled); bool showTabs() const; + bool showSpaces() const; void setTabWidth(int width); protected: @@ -46,6 +48,7 @@ private slots: bool m_useTabs; int m_indentationWidth; bool m_showTabs = false; + bool m_showSpaces = false; int m_tabWidth; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6e9ae35..d04981c 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -9,6 +9,7 @@ #include "mainwindow.h" #include "codeeditor.h" #include "settings.h" +#include "mainwindow/mainwindowconfigloader.h" #include "mainwindow/textoperations.h" #include "mainwindow/recentfiles.h" #include "mainwindow/session.h" @@ -56,6 +57,9 @@ MainWindow::MainWindow(QWidget* parent) fileOperations->newDocument(); Helpers::zMenu(ui->menu_Language, this); + m_mainWindowConfigLoader = new MainWindowConfigLoader(this); + m_mainWindowConfigLoader->loadMainWindowConfig(); + qDebug() << "MainWindow initialized..."; } @@ -69,6 +73,7 @@ MainWindow::~MainWindow() { delete textOperations; delete m_systemFindDialog; delete m_systemReplaceDialog; + delete m_mainWindowConfigLoader; } Ui::MainWindow* MainWindow::getUi() const { @@ -496,7 +501,6 @@ void MainWindow::on_action_Find_triggered() { void MainWindow::on_action_Show_Tabs_triggered(bool checked) { - qDebug() << "Show Tabs is: " << checked; Settings::instance()->saveSetting("View", "ShowTabs", checked ? "true" : "false"); for (int i = 0; i < ui->documentsTab->count(); ++i) { @@ -507,6 +511,26 @@ void MainWindow::on_action_Show_Tabs_triggered(bool checked) } } +void MainWindow::on_actionShow_Spaces_triggered(bool checked) +{ + Settings::instance()->saveSetting("View", "ShowSpaces", checked ? "true" : "false"); + + for (int i = 0; i < ui->documentsTab->count(); ++i) { + Document *doc = qobject_cast(ui->documentsTab->widget(i)); + if (doc) { + doc->editor()->setShowSpaces(checked); + } + } +} + + + + + + + + + @@ -650,4 +674,3 @@ void MainWindow::setActiveDocumentEditorInReplaceDialog() { } - diff --git a/src/mainwindow.h b/src/mainwindow.h index be9e7f0..cc974a5 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -24,6 +24,7 @@ class Session; class Settings; class RecentFiles; class FileOperations; +class MainWindowConfigLoader; class MainWindow : public QMainWindow { Q_OBJECT @@ -147,6 +148,8 @@ private slots: void on_action_Show_Tabs_triggered(bool checked); + void on_actionShow_Spaces_triggered(bool checked); + private: Ui::MainWindow* ui; FileOperations* fileOperations; @@ -176,4 +179,5 @@ private slots: ReplaceDialog* replaceDialog; SearchOptions* m_searchOptions; Find* m_find = nullptr; + MainWindowConfigLoader* m_mainWindowConfigLoader; }; diff --git a/src/mainwindow/mainwindowconfigloader.cpp b/src/mainwindow/mainwindowconfigloader.cpp new file mode 100644 index 0000000..695d982 --- /dev/null +++ b/src/mainwindow/mainwindowconfigloader.cpp @@ -0,0 +1,23 @@ +#include "../settings.h" +#include "../mainwindow.h" +#include "../ui_mainwindow.h" +#include "src/ui_mainwindow.h" +#include "mainwindowconfigloader.h" + +MainWindowConfigLoader::MainWindowConfigLoader(MainWindow *mainWindow) : m_mainWindow(mainWindow) {} + +void MainWindowConfigLoader::loadMainWindowConfig() { + if (m_mainWindow && m_mainWindow->getUi()) { + m_mainWindow->getUi()->action_Show_Tabs->setChecked(showTabs()); + m_mainWindow->getUi()->actionShow_Spaces->setChecked(showSpaces()); + } +} + +bool MainWindowConfigLoader::showTabs() const { + return Settings::instance()->loadSetting("View", "ShowTabs", "false") == true; +} + +bool MainWindowConfigLoader::showSpaces() const { + return Settings::instance()->loadSetting("View", "ShowSpaces", "false") == true; +} + diff --git a/src/mainwindow/mainwindowconfigloader.h b/src/mainwindow/mainwindowconfigloader.h new file mode 100644 index 0000000..c27b0de --- /dev/null +++ b/src/mainwindow/mainwindowconfigloader.h @@ -0,0 +1,17 @@ +#pragma once + +#include "../mainwindow.h" + +class MainWindowConfigLoader +{ +public: + explicit MainWindowConfigLoader(MainWindow *mainWindow); + void loadMainWindowConfig(); + +private: + MainWindow* m_mainWindow; + + bool showTabs() const; + bool showSpaces() const; +}; +