Skip to content

Commit

Permalink
v0.0.60
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Dec 2, 2024
1 parent c441bc6 commit dee70a5
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 19 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log

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

## 0.0.60

- Implemented:
- View Menu -> Show Space

## 0.0.59

- Default Tab Fixed
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
)

Expand Down
26 changes: 13 additions & 13 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-11-29T21:48:08. -->
<!-- Written by QtCreator 14.0.2, 2024-12-03T01:02:58. -->
<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_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
<value type="QString" key="CMake.Initial.Parameters">-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</value>
-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}</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_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
<value type="QString" key="CMake.Initial.Parameters">-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</value>
-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}</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
33 changes: 30 additions & 3 deletions src/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -290,19 +303,33 @@ 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);

// Get the rectangle of the cursor position
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();
Expand Down
3 changes: 3 additions & 0 deletions src/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -46,6 +48,7 @@ private slots:
bool m_useTabs;
int m_indentationWidth;
bool m_showTabs = false;
bool m_showSpaces = false;
int m_tabWidth;
};

Expand Down
27 changes: 25 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...";
}

Expand All @@ -69,6 +73,7 @@ MainWindow::~MainWindow() {
delete textOperations;
delete m_systemFindDialog;
delete m_systemReplaceDialog;
delete m_mainWindowConfigLoader;
}

Ui::MainWindow* MainWindow::getUi() const {
Expand Down Expand Up @@ -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) {
Expand All @@ -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<Document *>(ui->documentsTab->widget(i));
if (doc) {
doc->editor()->setShowSpaces(checked);
}
}
}












Expand Down Expand Up @@ -650,4 +674,3 @@ void MainWindow::setActiveDocumentEditorInReplaceDialog() {
}



4 changes: 4 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Session;
class Settings;
class RecentFiles;
class FileOperations;
class MainWindowConfigLoader;

class MainWindow : public QMainWindow {
Q_OBJECT
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -176,4 +179,5 @@ private slots:
ReplaceDialog* replaceDialog;
SearchOptions* m_searchOptions;
Find* m_find = nullptr;
MainWindowConfigLoader* m_mainWindowConfigLoader;
};
23 changes: 23 additions & 0 deletions src/mainwindow/mainwindowconfigloader.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

17 changes: 17 additions & 0 deletions src/mainwindow/mainwindowconfigloader.h
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit dee70a5

Please sign in to comment.