From cab5816d26f81339c728ed1d8cc5f7fb5c17779d Mon Sep 17 00:00:00 2001 From: Remisa Yousefvand Date: Thu, 5 Dec 2024 12:36:33 +0330 Subject: [PATCH] v0.0.67 --- CHANGELOG.md | 5 +++ CMakeLists.txt | 2 + CMakeLists.txt.user | 26 ++++++------- src/aboutdialog.ui | 42 ++++++++++++++++----- src/mainwindow.cpp | 30 +++++++++++++++ src/mainwindow.h | 4 ++ src/view/movetonewview.cpp | 76 ++++++++++++++++++++++++++++++++++++++ src/view/movetonewview.h | 20 ++++++++++ 8 files changed, 183 insertions(+), 22 deletions(-) create mode 100644 src/view/movetonewview.cpp create mode 100644 src/view/movetonewview.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c06f0..6b70c36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ============ +## 0.0.67 + +- Implemented: +- View Menu -> Move to a New View + ## 0.0.66 - Implemented: diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e43503..f00fc2b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,8 @@ set(PROJECT_SOURCES src/aboutdialog.h src/view/movetootherview.cpp src/view/movetootherview.h + src/view/movetonewview.cpp + src/view/movetonewview.h ${PROJECT_UI} ) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index fd7c9c9..11b4903 100755 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -102,14 +102,14 @@ 2 false - -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_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=Debug --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_GENERATOR:STRING=Ninja /data/Code/Qt/Notepad-- 0 /data/Code/Qt/Notepad--/build/Desktop-Debug @@ -160,14 +160,14 @@ 2 false - -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_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=Release --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_GENERATOR:STRING=Ninja /data/Code/Qt/Notepad-- /data/Code/Qt/Notepad--/build/Desktop-Release diff --git a/src/aboutdialog.ui b/src/aboutdialog.ui index c55c7c9..3e1c45a 100644 --- a/src/aboutdialog.ui +++ b/src/aboutdialog.ui @@ -7,7 +7,7 @@ 0 0 222 - 198 + 241 @@ -52,9 +52,9 @@ - 16 - 90 - 191 + 30 + 140 + 171 31 @@ -64,14 +64,14 @@ - By: Remisa Yousefvand + - Remisa Yousefvand 70 - 160 + 200 80 25 @@ -83,8 +83,8 @@ - 14 - 123 + 16 + 83 191 31 @@ -95,7 +95,31 @@ - https://github.com/yousefvand + <a href="https://github.com/yousefvand">https://github.com/yousefvand</a> + + + true + + + Qt::TextInteractionFlag::TextBrowserInteraction + + + + + + 20 + 110 + 111 + 31 + + + + + 12 + + + + Contributors: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3088114..d10b862 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -21,6 +21,7 @@ #include "systemfind/systemfinddialog.h" #include "systemreplace/systemreplacedialog.h" #include "view/movetootherview.h" +#include "view/movetonewview.h" #include "aboutdialog.h" MainWindow::MainWindow(QWidget* parent) @@ -77,6 +78,7 @@ MainWindow::~MainWindow() { delete m_systemReplaceDialog; delete m_mainWindowConfigLoader; delete m_moveToOtherView; + delete m_moveToNewView; } Ui::MainWindow* MainWindow::getUi() const { @@ -619,6 +621,34 @@ void MainWindow::on_action_Move_to_Other_View_triggered() } } +void MainWindow::on_actionMove_to_a_New_View_triggered() +{ + if (!ui->documentsTab) { + qDebug() << "documentsTab is null!"; + return; + } + + if (m_moveToNewView) { + m_moveToNewView->execute(); + } else { + MoveToNewView* m_moveToNewView = new MoveToNewView(ui->documentsTab, this); + m_moveToNewView->execute(); + } +} + + + + + + + + + + + + + + diff --git a/src/mainwindow.h b/src/mainwindow.h index 5229a04..d3551d0 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -16,6 +16,7 @@ #include "systemreplace/systemreplacedialog.h" #include "systemsearchresultdialog.h" #include "view/movetootherview.h" +#include "view/movetonewview.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -171,6 +172,8 @@ private slots: void on_action_Move_to_Other_View_triggered(); + void on_actionMove_to_a_New_View_triggered(); + private: Ui::MainWindow* ui; FileOperations* fileOperations; @@ -202,4 +205,5 @@ private slots: Find* m_find = nullptr; MainWindowConfigLoader* m_mainWindowConfigLoader; MoveToOtherView* m_moveToOtherView = nullptr; + MoveToNewView* m_moveToNewView = nullptr; }; diff --git a/src/view/movetonewview.cpp b/src/view/movetonewview.cpp new file mode 100644 index 0000000..308f147 --- /dev/null +++ b/src/view/movetonewview.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include "../codeeditor.h" +#include "movetonewview.h" +#include "../document.h" + +MoveToNewView::MoveToNewView(QTabWidget *tabWidget, QWidget *parent) + : QWidget(parent), m_tabWidget(tabWidget) {} + +void MoveToNewView::execute() { + // Get the index of the current tab + int currentIndex = m_tabWidget->currentIndex(); + if (currentIndex < 0) { + qDebug() << "No active tab found in the documentsTab."; + return; + } + + // Get the current tab widget + QWidget* currentWidget = m_tabWidget->widget(currentIndex); + if (!currentWidget) { + qDebug() << "No widget found in the current tab."; + return; + } + + qDebug() << "Current widget type:" << currentWidget->metaObject()->className(); + + // Locate the editor in the current widget (Document) + QString currentContent; + if (Document* currentDocument = qobject_cast(currentWidget)) { + // Assuming CodeEditor is a child of Document + if (CodeEditor* editor = currentDocument->findChild()) { + currentContent = editor->toPlainText(); + qDebug() << "Content retrieved from CodeEditor:" << currentContent; + } else { + qDebug() << "The Document does not contain a CodeEditor."; + } + } else if (QTextEdit* editor = qobject_cast(currentWidget)) { + currentContent = editor->toPlainText(); + qDebug() << "Content retrieved directly from QTextEdit tab:" << currentContent; + } else { + qDebug() << "Current tab does not contain a known editor type."; + } + + // Shift all tabs on the right of the current tab by one + int tabCount = m_tabWidget->count(); + for (int i = tabCount - 1; i > currentIndex; --i) { + QWidget* tab = m_tabWidget->widget(i); + QString tabText = m_tabWidget->tabText(i); + QIcon tabIcon = m_tabWidget->tabIcon(i); + + m_tabWidget->removeTab(i); + m_tabWidget->insertTab(i + 1, tab, tabIcon, tabText); + } + + // Create a new tab + Document* newDocument = new Document("", m_tabWidget); // Assuming Document is your tab widget class + if (!currentContent.isEmpty()) { + if (CodeEditor* newEditor = newDocument->findChild()) { + newEditor->setPlainText(currentContent); + qDebug() << "Content set for the new tab."; + } else { + qDebug() << "No editor found in the new Document to set content."; + } + } else { + qDebug() << "No content to set for the new tab."; + } + + // Insert the new tab + m_tabWidget->insertTab(currentIndex + 1, newDocument, QIcon(), "New View"); + + // Set focus to the new tab + m_tabWidget->setCurrentIndex(currentIndex + 1); + + qDebug() << "Shifted tabs, created a new tab, and set its content at index:" << currentIndex + 1; +} diff --git a/src/view/movetonewview.h b/src/view/movetonewview.h new file mode 100644 index 0000000..8e9fd92 --- /dev/null +++ b/src/view/movetonewview.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include +#include +#include + +class MoveToNewView : public QWidget { + Q_OBJECT + +public: + explicit MoveToNewView(QTabWidget *tabWidget, QWidget *parent = nullptr); + + void execute(); + +private: + QTabWidget *m_tabWidget; +}; +