Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #21

Merged
merged 2 commits into from
Dec 3, 2024
Merged

Dev #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Change Log

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

## 0.0.61

- Implemented:
- View Menu -> Show End of Line

## 0.0.60

- Implemented:
- View Menu -> Show Space

## 0.0.59

- Default Tab Fixed
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ set(PROJECT_UI
src/systemfind/systemfinddialog.ui
src/systemreplace/systemreplacedialog.ui
src/systemsearchresultdialog.ui
src/aboutdialog.ui
)

set(CMAKE_AUTOUIC_SEARCH_PATHS src)

set(PROJECT_SOURCES
src/main.cpp
src/mainwindow.cpp
Expand Down Expand Up @@ -100,6 +103,10 @@ set(PROJECT_SOURCES
src/systemsearchresultdialog.h
src/systemtextdelegate.cpp
src/systemtextdelegate.h
src/mainwindow/mainwindowconfigloader.cpp
src/mainwindow/mainwindowconfigloader.h
src/aboutdialog.cpp
src/aboutdialog.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-03T13:29:33. -->
<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_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_BUILD_TYPE:STRING=Debug</value>
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}</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_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_BUILD_TYPE:STRING=Release</value>
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_BUILD_TYPE:STRING=Release
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}</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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
![gui](assets/lgplv3.png)

A simple light text editor.
Notepadqq was my choice editor. Unfortunately it doesn't maintain anymore. I tried to help but there was old PRs and plenty of unanswered issues. The project was a mix of C++/Qt/Javascript/HTML,CSS,Python...
It is a while I didn't code in C++ and my knowledge of Qt is a little. All that said this is a **toy** project, at least for a while. The -- (minus minus) indicates that this is a minimalistic project. I will design GUI just like Notepadqq so there is no new GUI learning. For now I just release for Linux which has Qt6 installed (dynamic compile) and C++ 20.
Notepadqq was my choice editor. Unfortunately it doesn't maintain anymore. I tried to help but there was old PRs and plenty of unanswered issues. The project was a mix of C++/Qt/Javascript/HTML,CSS,Python... . Notepad-- is a pure C++ project.
It is a while I didn't code in C++ and my knowledge of Qt is little. All that said this is a **toy** project, at least for a while. The -- (minus minus) indicates that this is a minimalistic project. I will design GUI just like Notepadqq so there is no new GUI learning. For now I release for Ubuntu-latest, macOS-latest and Windows-latest but you need Qt6 and C++ 20 installed since for now I compile dynamic.

Any contribution is welcome.

In a world without walls and fences, who needs **windows** and **gates**?
![gui](assets/gui.png)
![gui](assets/replace-system.png)
32 changes: 32 additions & 0 deletions assets/generate_random_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Function to convert human-readable sizes to bytes
convert_to_bytes() {
local size=$1
local multiplier=1

case "${size: -2}" in
KB|kb) multiplier=1024; size=${size%??} ;;
MB|mb) multiplier=$((1024 * 1024)); size=${size%??} ;;
GB|gb) multiplier=$((1024 * 1024 * 1024)); size=${size%??} ;;
B|b) multiplier=1; size=${size%?} ;;
*) echo "Invalid size format: $size"; exit 1 ;;
esac

echo $((size * multiplier))
}

# Check if file size is provided
if [ -z "$1" ]; then
echo "Usage: $0 <file size> (e.g., 2MB, 30KB, 1GB)"
exit 1
fi

# Convert human-readable size to bytes
FILE_SIZE_BYTES=$(convert_to_bytes "$1")
OUTPUT_FILE="random_file.txt"

# Generate random characters
LC_ALL=C tr -dc 'a-zA-Z0-9 \n' </dev/urandom | head -c "$FILE_SIZE_BYTES" > "$OUTPUT_FILE"

echo "Generated random file: $OUTPUT_FILE with size: $1 ($FILE_SIZE_BYTES bytes)"
Binary file added assets/replace-system.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/aboutdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "aboutdialog.h"
#include "ui_aboutdialog.h"

AboutDialog::AboutDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::AboutDialog)
{
ui->setupUi(this);

connect(ui->closeButton, &QPushButton::clicked, this, &QDialog::accept);
}

AboutDialog::~AboutDialog()
{
delete ui;
}


20 changes: 20 additions & 0 deletions src/aboutdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <QDialog>

namespace Ui {
class AboutDialog;
}

class AboutDialog : public QDialog
{
Q_OBJECT

public:
explicit AboutDialog(QWidget *parent = nullptr);
~AboutDialog();

private:
Ui::AboutDialog *ui;
};

104 changes: 104 additions & 0 deletions src/aboutdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AboutDialog</class>
<widget class="QDialog" name="AboutDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>222</width>
<height>198</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>40</x>
<y>10</y>
<width>171</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="text">
<string>Notepad--</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>111</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Version: 0.1.0</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>16</x>
<y>90</y>
<width>191</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>By: Remisa Yousefvand</string>
</property>
</widget>
<widget class="QPushButton" name="closeButton">
<property name="geometry">
<rect>
<x>70</x>
<y>160</y>
<width>80</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>14</x>
<y>123</y>
<width>191</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>https://github.com/yousefvand</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
56 changes: 51 additions & 5 deletions src/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ 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_showEOL = Settings::instance()->loadSetting("View", "ShowEOL", "false") == "true";
m_tabWidth = Settings::instance()->loadSetting("View", "TabWidth", "4").toInt();
}

Expand Down Expand Up @@ -263,10 +265,29 @@ void CodeEditor::setShowTabs(bool enabled) {
}
}

void CodeEditor::setShowSpaces(bool enabled) {
if (m_showSpaces != enabled) {
m_showSpaces = enabled;
viewport()->update();
}
}

void CodeEditor::setShowEOL(bool enabled) {
if (m_showEOL != enabled) {
m_showEOL = enabled;
viewport()->update();
}
}

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,8 +296,6 @@ void CodeEditor::setTabWidth(int width = 4) {
void CodeEditor::paintEvent(QPaintEvent *event) {
QPlainTextEdit::paintEvent(event);

if (!m_showTabs) return;

QPainter painter(viewport());
painter.setPen(Qt::gray);

Expand All @@ -288,23 +307,50 @@ void CodeEditor::paintEvent(QPaintEvent *event) {
int blockStart = block.position();
QTextCursor blockCursor(block);

// Iterate over characters in the block
// Handle Tabs and Spaces in the line
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, ".");
}
}

// Add the EOL character if enabled
if (m_showEOL) {
blockCursor.setPosition(blockStart + text.length()); // Move to the end of the line
QRect rect = cursorRect(blockCursor);

// Position for the EOL character
QPoint position(rect.left() + metrics.horizontalAdvance(' '), rect.top() + metrics.ascent());

// Draw the EOL character (e.g., "↵")
painter.drawText(position, "↵");
}

block = block.next();
}
}
Loading
Loading