From bce34dd73f340a6cdc5ce1db4d1f6917d63faea1 Mon Sep 17 00:00:00 2001 From: Remisa Yousefvand Date: Wed, 4 Dec 2024 01:44:34 +0330 Subject: [PATCH] v0.0.63 --- CHANGELOG.md | 5 +++ CMakeLists.txt.user | 22 ++++++------ src/codeeditor.cpp | 42 +++++++++++++++++++++++ src/codeeditor.h | 2 ++ src/mainwindow.cpp | 14 ++++++++ src/mainwindow.h | 2 ++ src/mainwindow.ui | 11 ++---- src/mainwindow/mainwindowconfigloader.cpp | 5 +++ src/mainwindow/mainwindowconfigloader.h | 1 + 9 files changed, 85 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d9611b..9e7d513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ============ +## 0.0.63 + +- Implemented: +- View Menu -> Show Indent Guide + ## 0.0.62 - Implemented: diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 3192a44..913a54b 100755 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -102,14 +102,14 @@ 2 false - -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DCMAKE_BUILD_TYPE:STRING=Debug --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} + -DCMAKE_GENERATOR:STRING=Ninja -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} /data/Code/Qt/Notepad-- 0 /data/Code/Qt/Notepad--/build/Desktop-Debug @@ -160,14 +160,14 @@ 2 false - -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DCMAKE_BUILD_TYPE:STRING=Release --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} + -DCMAKE_GENERATOR:STRING=Ninja -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} /data/Code/Qt/Notepad-- /data/Code/Qt/Notepad--/build/Desktop-Release diff --git a/src/codeeditor.cpp b/src/codeeditor.cpp index 8eaace1..5d671e0 100755 --- a/src/codeeditor.cpp +++ b/src/codeeditor.cpp @@ -34,6 +34,7 @@ CodeEditor::CodeEditor(QWidget *parent) m_showSpaces = Settings::instance()->loadSetting("View", "ShowSpaces", "false") == "true"; m_showEOL = Settings::instance()->loadSetting("View", "ShowEOL", "false") == "true"; m_showAllCharacters = Settings::instance()->loadSetting("View", "ShowAllCharacters", "false") == "true"; + m_showIndentGuide = Settings::instance()->loadSetting("View", "ShowIndentGuide", "false") == "true"; m_tabWidth = Settings::instance()->loadSetting("View", "TabWidth", "4").toInt(); if (m_showAllCharacters) { @@ -296,6 +297,13 @@ void CodeEditor::setShowAllCharacters(bool enabled) { } } +void CodeEditor::setShowIndentGuide(bool enabled) { + if (m_showIndentGuide != enabled) { + m_showIndentGuide = enabled; + viewport()->update(); + } +} + // TODO: Implement in UI void CodeEditor::setTabWidth(int width = 4) { m_tabWidth = width; @@ -311,6 +319,40 @@ void CodeEditor::paintEvent(QPaintEvent *event) { QTextBlock block = document()->firstBlock(); QFontMetrics metrics(font()); + // Draw indent guides if enabled + if (m_showIndentGuide) { + QTextBlock blockForIndent = document()->firstBlock(); + + while (blockForIndent.isValid()) { + if (blockForIndent.isVisible()) { + QRect blockRect = blockBoundingGeometry(blockForIndent).translated(contentOffset()).toRect(); + + QString blockText = blockForIndent.text(); + int indentWidth = metrics.horizontalAdvance(' ') * 4; // Assuming 4 spaces per indent level + + // Calculate the horizontal offset for the line + int horizontalOffset = 0; + for (const QChar &ch : blockText) { + if (ch == '\t') { + horizontalOffset += indentWidth; // Increment by a full tab width + } else if (ch == ' ') { + horizontalOffset += metrics.horizontalAdvance(' '); // Increment by a space width + } else { + break; // Stop counting after the first non-whitespace character + } + } + + if (horizontalOffset > 0) { + int x = horizontalOffset + contentOffset().x(); // X position for the guide + painter.drawLine(QPoint(x, blockRect.top()), QPoint(x, blockRect.bottom())); + } + } + + blockForIndent = blockForIndent.next(); + } + } + + // Handle Tabs, Spaces, and EOL while (block.isValid()) { QString text = block.text(); int blockStart = block.position(); diff --git a/src/codeeditor.h b/src/codeeditor.h index 844ec7f..5d1ab21 100755 --- a/src/codeeditor.h +++ b/src/codeeditor.h @@ -28,6 +28,7 @@ class CodeEditor : public QPlainTextEdit { void setShowSpaces(bool enabled); void setShowEOL(bool enabled); void setShowAllCharacters(bool enabled); + void setShowIndentGuide(bool enabled); void setTabWidth(int width); protected: @@ -51,6 +52,7 @@ private slots: bool m_showSpaces = false; bool m_showEOL = false; bool m_showAllCharacters = false; + bool m_showIndentGuide = false; int m_tabWidth; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2fcb5fc..8b136e2 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -548,6 +548,20 @@ void MainWindow::on_actionShow_All_Characters_triggered(bool checked) } } +void MainWindow::on_actionShow_Indent_Guide_triggered(bool checked) +{ + Settings::instance()->saveSetting("View", "ShowIndentGuide", checked); + + for (int i = 0; i < ui->documentsTab->count(); ++i) { + Document *doc = qobject_cast(ui->documentsTab->widget(i)); + if (doc) { + doc->editor()->setShowIndentGuide(checked); + } + } +} + + + diff --git a/src/mainwindow.h b/src/mainwindow.h index 5c792b3..2947b2c 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -158,6 +158,8 @@ private slots: void on_actionShow_All_Characters_triggered(bool checked); + void on_actionShow_Indent_Guide_triggered(bool checked); + private: Ui::MainWindow* ui; FileOperations* fileOperations; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index f35d479..0ea0888 100755 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -33,6 +33,9 @@ + + Qt::LayoutDirection::LeftToRight + false @@ -525,13 +528,6 @@ - - - &Run - - - - &Window @@ -552,7 +548,6 @@ - diff --git a/src/mainwindow/mainwindowconfigloader.cpp b/src/mainwindow/mainwindowconfigloader.cpp index 4880590..716d92c 100644 --- a/src/mainwindow/mainwindowconfigloader.cpp +++ b/src/mainwindow/mainwindowconfigloader.cpp @@ -11,6 +11,7 @@ void MainWindowConfigLoader::loadMainWindowConfig() { m_mainWindow->getUi()->actionShow_Spaces->setChecked(showSpaces()); m_mainWindow->getUi()->actionShow_End_of_Lines->setChecked(showEOL()); m_mainWindow->getUi()->actionShow_All_Characters->setChecked(showAllCharacters()); + m_mainWindow->getUi()->actionShow_Indent_Guide->setChecked(showIndentGuide()); } } @@ -30,4 +31,8 @@ bool MainWindowConfigLoader::showAllCharacters() const { return Settings::instance()->loadSetting("View", "ShowAllCharacters", "false") == true; } +bool MainWindowConfigLoader::showIndentGuide() const { + return Settings::instance()->loadSetting("View", "ShowIndentGuide", "false") == true; +} + diff --git a/src/mainwindow/mainwindowconfigloader.h b/src/mainwindow/mainwindowconfigloader.h index 9953031..164f50a 100644 --- a/src/mainwindow/mainwindowconfigloader.h +++ b/src/mainwindow/mainwindowconfigloader.h @@ -15,5 +15,6 @@ class MainWindowConfigLoader bool showSpaces() const; bool showEOL() const; bool showAllCharacters() const; + bool showIndentGuide() const; };