Skip to content

Commit

Permalink
v0.0.70
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Dec 14, 2024
1 parent 872c912 commit aa80b74
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 449 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.70

- Implemented:
- View Menu -> Toggle to Former Tab

## 0.0.69

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

Expand Down
189 changes: 166 additions & 23 deletions CMakeLists.txt.user
100755 → 100644

Large diffs are not rendered by default.

425 changes: 0 additions & 425 deletions CMakeLists.txt.user.5653f27

This file was deleted.

6 changes: 6 additions & 0 deletions src/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CodeEditor::CodeEditor(QWidget *parent)
m_showIndentGuide = Settings::instance()->loadSetting("View", "ShowIndentGuide", "false") == "true";
m_showWrapSymbol = Settings::instance()->loadSetting("View", "ShowWrapSymbol", "false") == "true";
m_tabWidth = Settings::instance()->loadSetting("View", "TabWidth", "4").toInt();
m_showMathRendering = Settings::instance()->loadSetting("View", "MathRendering", "false") == "true";

if (m_showAllCharacters) {
m_showTabs = true;
Expand Down Expand Up @@ -318,6 +319,11 @@ void CodeEditor::setTabWidth(int width = 4) {
viewport()->update(); // Trigger a repaint to apply the new width
}

void CodeEditor::setShowMathRendering(bool enabled) {
Q_UNUSED(enabled);
// TODO: Implement
}

void CodeEditor::paintTabs(QPainter& painter, const QTextBlock& block, int top) {
QTextLayout* layout = block.layout();
if (!layout) return;
Expand Down
2 changes: 2 additions & 0 deletions src/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CodeEditor : public QPlainTextEdit {
void zoomIn();
void zoomOut();
void defaultZoom();
void setShowMathRendering(bool enabled);

protected:
void resizeEvent(QResizeEvent *event) override;
Expand All @@ -59,6 +60,7 @@ private slots:
bool m_showIndentGuide = false;
bool m_showWrapSymbol = false;
int m_tabWidth;
bool m_showMathRendering = false;

void paintTabs(QPainter& painter, const QTextBlock& block, int top);
void paintSpaces(QPainter& painter, const QTextBlock& block, int top);
Expand Down
55 changes: 54 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
#include "view/openinnewwindow.h"
#include "view/wordwrap.h"
#include "aboutdialog.h"
#include "view/toggletoformertab.h"

MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent),
ui(new Ui::MainWindow),
indentationManager(new IndentationManager(this)),
findDialog(new FindDialog(this)),
replaceDialog(new ReplaceDialog(this))
replaceDialog(new ReplaceDialog(this)),
m_currentTabIndex(-1),
m_formerTabIndex(-1)
{

ui->setupUi(this); // Ensure the UI is set up before using it
Expand Down Expand Up @@ -66,6 +69,11 @@ MainWindow::MainWindow(QWidget* parent)
m_mainWindowConfigLoader = new MainWindowConfigLoader(this);
m_mainWindowConfigLoader->loadMainWindowConfig();

connect(ui->documentsTab, &QTabWidget::currentChanged, this, &MainWindow::onTabChanged);
if (ui->documentsTab->count() > 0) {
m_currentTabIndex = ui->documentsTab->currentIndex();
}

qDebug() << "MainWindow initialized...";
}

Expand Down Expand Up @@ -682,6 +690,51 @@ void MainWindow::toggleWordWrap() {
}
}

void MainWindow::onTabChanged(int currentIndex)
{
// Skip updates if the change was triggered by toggling
if (currentIndex == m_formerTabIndex) {
return; // Do nothing; indices are already updated in the toggle logic
}

// Update former and current tab indices
m_formerTabIndex = m_currentTabIndex;
m_currentTabIndex = currentIndex;
}

void MainWindow::on_actionMath_Rendering_triggered(bool checked)
{
Helpers::notImplemented(this);
Settings::instance()->saveSetting("View", "MathRendering", checked);

for (int i = 0; i < ui->documentsTab->count(); ++i) {
Document *doc = qobject_cast<Document *>(ui->documentsTab->widget(i));
if (doc) {
doc->editor()->setShowMathRendering(checked);
}
}
}

void MainWindow::on_actionToggle_to_Former_Tab_triggered()
{
// Ensure a valid former tab exists
if (m_formerTabIndex != -1) {
// Temporarily disconnect the currentChanged signal to avoid overwriting indices
disconnect(ui->documentsTab, &QTabWidget::currentChanged, this, &MainWindow::onTabChanged);

// Swap the tabs
ui->documentsTab->setCurrentIndex(m_formerTabIndex);

// Update indices after the toggle
std::swap(m_currentTabIndex, m_formerTabIndex);

// Reconnect the currentChanged signal
connect(ui->documentsTab, &QTabWidget::currentChanged, this, &MainWindow::onTabChanged);
}
}






Expand Down
7 changes: 7 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private slots:
void on_action_Save_triggered();
void onActionZ80Triggered();
void toggleWordWrap();
void onTabChanged(int currentIndex);

void on_actionOpen_Folder_triggered();

Expand Down Expand Up @@ -181,6 +182,10 @@ private slots:

void on_action_Word_wrap_triggered();

void on_actionToggle_to_Former_Tab_triggered();

void on_actionMath_Rendering_triggered(bool checked);

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

Expand Down Expand Up @@ -45,6 +46,10 @@ bool MainWindowConfigLoader::wordWrap() const {
return Settings::instance()->loadSetting("View", "WordWrap", "false") == true;
}

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




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

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

ToggleToFormerTab::ToggleToFormerTab(QTabWidget* tabWidget)
: m_tabWidget(tabWidget),
m_currentTabIndex(-1),
m_formerTabIndex(-1),
m_isToggleToFormerTabActive(false) {
if (m_tabWidget && m_tabWidget->count() > 0) {
m_currentTabIndex = m_tabWidget->currentIndex();
}
}

void ToggleToFormerTab::updateTabIndex(int currentIndex) {
if (currentIndex == m_currentTabIndex)
return;

m_formerTabIndex = m_currentTabIndex;
m_currentTabIndex = currentIndex;
}

void ToggleToFormerTab::setToggleActive(bool active) {
m_isToggleToFormerTabActive = active;
if (m_isToggleToFormerTabActive) {
toggle();
}
}

void ToggleToFormerTab::toggle() {
if (!m_tabWidget || m_formerTabIndex == -1) {
return; // No former tab to toggle to
}

// Swap current and former indices and activate the former tab
std::swap(m_currentTabIndex, m_formerTabIndex);
m_tabWidget->setCurrentIndex(m_currentTabIndex);
}
18 changes: 18 additions & 0 deletions src/view/toggletoformertab.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <QTabWidget>

class ToggleToFormerTab {
public:
explicit ToggleToFormerTab(QTabWidget* tabWidget);

void toggle(); // Perform the toggle operation
void updateTabIndex(int currentIndex); // Update tab indices
void setToggleActive(bool active); // Set toggle state

private:
QTabWidget* m_tabWidget;
int m_currentTabIndex;
int m_formerTabIndex;
bool m_isToggleToFormerTabActive; // Toggle active state
};

0 comments on commit aa80b74

Please sign in to comment.