Skip to content

Commit

Permalink
v0.0.69
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Dec 5, 2024
1 parent 5a6ce16 commit 872c912
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 7 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.69

- Implemented:
- View Menu -> Word Wrap

## 0.0.68

- Implemented:
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ set(PROJECT_SOURCES
src/view/movetonewview.h
src/view/openinnewwindow.cpp
src/view/openinnewwindow.h
src/view/wordwrap.cpp
src/view/wordwrap.h
${PROJECT_UI}
)

Expand Down
14 changes: 7 additions & 7 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-05T13:56:55. -->
<!-- Written by QtCreator 14.0.2, 2024-12-05T17:33:58. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -104,12 +104,12 @@
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_BUILD_TYPE:STRING=Debug
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}</value>
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake</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 @@ -162,12 +162,12 @@
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_BUILD_TYPE:STRING=Release
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}</value>
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake</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
32 changes: 32 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "view/movetootherview.h"
#include "view/movetonewview.h"
#include "view/openinnewwindow.h"
#include "view/wordwrap.h"
#include "aboutdialog.h"

MainWindow::MainWindow(QWidget* parent)
Expand Down Expand Up @@ -60,6 +61,7 @@ MainWindow::MainWindow(QWidget* parent)
Helpers::RemoveMe(ui->documentsTab);
fileOperations->newDocument();
Helpers::zMenu(ui->menu_Language, this);
m_wordWrap = new WordWrap(this);

m_mainWindowConfigLoader = new MainWindowConfigLoader(this);
m_mainWindowConfigLoader->loadMainWindowConfig();
Expand Down Expand Up @@ -653,6 +655,36 @@ void MainWindow::on_action_Open_in_a_New_Window_triggered()
delete m_openInNewWindow;
}

void MainWindow::on_action_Word_wrap_triggered()
{
if (QPlainTextEdit* currentEditor = qobject_cast<QPlainTextEdit*>(ui->documentsTab->currentWidget())) {
m_wordWrap->toggle(currentEditor);
bool checked = m_wordWrap->isWordWrapEnabled(currentEditor);
ui->action_Word_wrap->setChecked(checked);
Settings::instance()->saveSetting("View", "WordWrap", checked);
} else {
qDebug() << "No active text editor found to toggle word wrap.";
}
}
// FIXME: Setting doesn't save
void MainWindow::toggleWordWrap() {
// Get the current text editor
if (QPlainTextEdit* currentEditor = qobject_cast<QPlainTextEdit*>(ui->documentsTab->currentWidget())) {
// Use the WordWrap instance to toggle word wrap
m_wordWrap->toggle(currentEditor);

// Optionally update the UI action's checked state
bool checked = m_wordWrap->isWordWrapEnabled(currentEditor);
ui->action_Word_wrap->setChecked(checked);
Settings::instance()->saveSetting("View", "WordWrap", checked);
} else {
qDebug() << "No active text editor found to toggle word wrap.";
}
}







Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "view/movetootherview.h"
#include "view/movetonewview.h"
#include "view/openinnewwindow.h"
#include "view/wordwrap.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
Expand Down Expand Up @@ -54,6 +55,7 @@ private slots:
void on_action_Open_triggered();
void on_action_Save_triggered();
void onActionZ80Triggered();
void toggleWordWrap();

void on_actionOpen_Folder_triggered();

Expand Down Expand Up @@ -177,6 +179,8 @@ private slots:

void on_action_Open_in_a_New_Window_triggered();

void on_action_Word_wrap_triggered();

private:
Ui::MainWindow* ui;
FileOperations* fileOperations;
Expand Down Expand Up @@ -210,4 +214,5 @@ private slots:
MoveToOtherView* m_moveToOtherView = nullptr;
MoveToNewView* m_moveToNewView = nullptr;
OpenInNewWindow* m_openInNewWindow = nullptr;
WordWrap* m_wordWrap = nullptr;
};
5 changes: 5 additions & 0 deletions src/mainwindow/mainwindowconfigloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void MainWindowConfigLoader::loadMainWindowConfig() {
m_mainWindow->getUi()->actionShow_All_Characters->setChecked(showAllCharacters());
m_mainWindow->getUi()->actionShow_Indent_Guide->setChecked(showIndentGuide());
m_mainWindow->getUi()->actionShow_Wrap_Symbol->setChecked(showWrapSymbol());
m_mainWindow->getUi()->action_Word_wrap->setChecked(wordWrap());
}
}

Expand Down Expand Up @@ -40,6 +41,10 @@ bool MainWindowConfigLoader::showWrapSymbol() const {
return Settings::instance()->loadSetting("View", "ShowWrapSymbol", "false") == true;
}

bool MainWindowConfigLoader::wordWrap() const {
return Settings::instance()->loadSetting("View", "WordWrap", "false") == true;
}




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

22 changes: 22 additions & 0 deletions src/view/wordwrap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "wordwrap.h"

WordWrap::WordWrap(QObject* parent)
: QObject(parent) {}

void WordWrap::toggle(QPlainTextEdit* editor) {
if (!editor) return;

QTextOption option = editor->document()->defaultTextOption();
if (option.wrapMode() == QTextOption::NoWrap) {
option.setWrapMode(QTextOption::WordWrap);
} else {
option.setWrapMode(QTextOption::NoWrap);
}
editor->document()->setDefaultTextOption(option);
}

bool WordWrap::isWordWrapEnabled(QPlainTextEdit* editor) const {
if (!editor) return false;

return editor->document()->defaultTextOption().wrapMode() == QTextOption::WordWrap;
}
19 changes: 19 additions & 0 deletions src/view/wordwrap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <QObject>
#include <QPlainTextEdit>
#include <QTextOption>

class WordWrap : public QObject {
Q_OBJECT

public:
explicit WordWrap(QObject* parent = nullptr);

// Toggle word wrap for a given editor
void toggle(QPlainTextEdit* editor);

// Check if word wrap is enabled
bool isWordWrapEnabled(QPlainTextEdit* editor) const;
};

0 comments on commit 872c912

Please sign in to comment.