Skip to content

Commit

Permalink
v0.0.63
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Dec 3, 2024
1 parent 938d44b commit bce34dd
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

============

## 0.0.63

- Implemented:
- View Menu -> Show Indent Guide

## 0.0.62

- Implemented:
Expand Down
22 changes: 11 additions & 11 deletions CMakeLists.txt.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 14.0.2, 2024-12-03T15:01:52. -->
<!-- Written by QtCreator 14.0.2, 2024-12-04T01:38:52. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -102,14 +102,14 @@
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-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}
<value type="QString" key="CMake.Initial.Parameters">-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</value>
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}</value>
<value type="QString" key="CMake.Source.Directory">/data/Code/Qt/Notepad--</value>
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/data/Code/Qt/Notepad--/build/Desktop-Debug</value>
Expand Down Expand Up @@ -160,14 +160,14 @@
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-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}
<value type="QString" key="CMake.Initial.Parameters">-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</value>
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}</value>
<value type="QString" key="CMake.Source.Directory">/data/Code/Qt/Notepad--</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/data/Code/Qt/Notepad--/build/Desktop-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
Expand Down
42 changes: 42 additions & 0 deletions src/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
};

Expand Down
14 changes: 14 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Document *>(ui->documentsTab->widget(i));
if (doc) {
doc->editor()->setShowIndentGuide(checked);
}
}
}






Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 3 additions & 8 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTextEdit" name="textEdit">
<property name="layoutDirection">
<enum>Qt::LayoutDirection::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
Expand Down Expand Up @@ -525,13 +528,6 @@
<addaction name="action_Show_menu_bar"/>
<addaction name="actionS_how_Toolbar"/>
</widget>
<widget class="QMenu" name="menu_Run">
<property name="title">
<string>&amp;Run</string>
</property>
<addaction name="actionRun"/>
<addaction name="actionModify_run_commands"/>
</widget>
<widget class="QMenu" name="menu_Window">
<property name="title">
<string>&amp;Window</string>
Expand All @@ -552,7 +548,6 @@
<addaction name="menuEn_coding"/>
<addaction name="menu_Language"/>
<addaction name="menuSettin_gs"/>
<addaction name="menu_Run"/>
<addaction name="menu_Window"/>
<addaction name="menuAbo_ut"/>
</widget>
Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow/mainwindowconfigloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand All @@ -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;
}


1 change: 1 addition & 0 deletions src/mainwindow/mainwindowconfigloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class MainWindowConfigLoader
bool showSpaces() const;
bool showEOL() const;
bool showAllCharacters() const;
bool showIndentGuide() const;
};

0 comments on commit bce34dd

Please sign in to comment.