diff --git a/cchapterwindow.cpp b/cchapterwindow.cpp index c73da85..8de5ff6 100644 --- a/cchapterwindow.cpp +++ b/cchapterwindow.cpp @@ -5,7 +5,7 @@ cChapterWindow::cChapterWindow(QWidget *parent) : - QWidget(parent), + cMDISubWindow(parent), ui(new Ui::cChapterWindow), m_lpChapter(0), m_lpSceneList(0) diff --git a/cchapterwindow.h b/cchapterwindow.h index 9340bc0..e2eeff3 100644 --- a/cchapterwindow.h +++ b/cchapterwindow.h @@ -6,6 +6,8 @@ #include "cchapter.h" #include "cscene.h" +#include "cmdisubwindow.h" + #include #include @@ -14,7 +16,7 @@ namespace Ui { class cChapterWindow; } -class cChapterWindow : public QWidget +class cChapterWindow : public cMDISubWindow { Q_OBJECT diff --git a/ccharacterwindow.cpp b/ccharacterwindow.cpp index f66ff43..433cfee 100644 --- a/ccharacterwindow.cpp +++ b/ccharacterwindow.cpp @@ -7,7 +7,7 @@ cCharacterWindow::cCharacterWindow(QWidget *parent) : - QWidget(parent), + cMDISubWindow(parent), ui(new Ui::cCharacterWindow), m_lpCharacter(0) { diff --git a/ccharacterwindow.h b/ccharacterwindow.h index 80cef2c..a27c777 100644 --- a/ccharacterwindow.h +++ b/ccharacterwindow.h @@ -4,6 +4,8 @@ #include "ccharacter.h" +#include "cmdisubwindow.h" + #include #include @@ -12,7 +14,7 @@ namespace Ui { class cCharacterWindow; } -class cCharacterWindow : public QWidget +class cCharacterWindow : public cMDISubWindow { Q_OBJECT diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 560c1ea..4399cef 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -4,9 +4,6 @@ #include "ctextdocument.h" #include "cpartwindow.h" -//#include "cchapterwindow.h" -//#include "cscenewindow.h" -//#include "ccharacterwindow.h" #include "cwidget.h" @@ -414,6 +411,26 @@ void cMainWindow::onMdiAreaSubWindowActivated(QMdiSubWindow *arg1) m_bUpdatingTab = false; } +void cMainWindow::onSubWindowClosed(QWidget* lpSubWindow) +{ + if(m_bUpdatingTab) + return; + + m_bUpdatingTab = true; + + for(int x = 0;x < ui->m_lpMainTab->count();x++) + { + cWidget* lpWidget = (cWidget*)ui->m_lpMainTab->widget(x); + if(lpWidget->widget() == lpSubWindow) + { + ui->m_lpMainTab->removeTab(x); + m_bUpdatingTab = false; + return; + } + } + m_bUpdatingTab = false; +} + void cMainWindow::onOutlineDoubleClicked(const QModelIndex& index) { QStandardItem* lpItem = m_lpOutlineModel->itemFromIndex(index); @@ -487,6 +504,8 @@ void cMainWindow::onShowPartWindow(cPart* lpPart) lpWidget1->setWindow(ui->m_lpMdiArea->addSubWindow(lpPartWindow)); ui->m_lpMainTab->addTab((QWidget*)lpWidget1, lpPartWindow->windowTitle()); + connect(lpPartWindow, SIGNAL(subWindowClosed(QWidget*)), this, SLOT(onSubWindowClosed(QWidget*))); + lpPartWindow->show(); } @@ -514,6 +533,8 @@ void cMainWindow::onShowChapterWindow(cChapter* lpChapter) lpWidget1->setWindow(ui->m_lpMdiArea->addSubWindow(lpChapterWindow)); ui->m_lpMainTab->addTab((QWidget*)lpWidget1, lpChapterWindow->windowTitle()); + connect(lpChapterWindow, SIGNAL(subWindowClosed(QWidget*)), this, SLOT(onSubWindowClosed(QWidget*))); + lpChapterWindow->show(); } @@ -545,6 +566,8 @@ void cMainWindow::onShowSceneWindow(cScene* lpScene) connect(lpSceneWindow, SIGNAL(showPlaceWindow(cPlace*)), this, SLOT(onShowPlaceWindow(cPlace*))); connect(lpSceneWindow, SIGNAL(showObjectWindow(cObject*)), this, SLOT(onShowObjectWindow(cObject*))); + connect(lpSceneWindow, SIGNAL(subWindowClosed(QWidget*)), this, SLOT(onSubWindowClosed(QWidget*))); + lpSceneWindow->show(); } @@ -572,6 +595,8 @@ void cMainWindow::onShowCharacterWindow(cCharacter* lpCharacter) lpWidget1->setWindow(ui->m_lpMdiArea->addSubWindow(lpCharacterWindow)); ui->m_lpMainTab->addTab((QWidget*)lpWidget1, lpCharacterWindow->windowTitle()); + connect(lpCharacterWindow, SIGNAL(subWindowClosed(QWidget*)), this, SLOT(onSubWindowClosed(QWidget*))); + lpCharacterWindow->show(); } @@ -599,6 +624,8 @@ void cMainWindow::onShowPlaceWindow(cPlace* lpPlace) lpWidget1->setWindow(ui->m_lpMdiArea->addSubWindow(lpPlaceWindow)); ui->m_lpMainTab->addTab((QWidget*)lpWidget1, lpPlaceWindow->windowTitle()); + connect(lpPlaceWindow, SIGNAL(subWindowClosed(QWidget*)), this, SLOT(onSubWindowClosed(QWidget*))); + lpPlaceWindow->show(); } @@ -626,6 +653,8 @@ void cMainWindow::onShowObjectWindow(cObject* lpObject) lpWidget1->setWindow(ui->m_lpMdiArea->addSubWindow(lpObjectWindow)); ui->m_lpMainTab->addTab((QWidget*)lpWidget1, lpObjectWindow->windowTitle()); + connect(lpObjectWindow, SIGNAL(subWindowClosed(QWidget*)), this, SLOT(onSubWindowClosed(QWidget*))); + lpObjectWindow->show(); } @@ -657,6 +686,8 @@ void cMainWindow::onShowRechercheWindow(cRecherche* lpRecherche) connect(lpRechercheWindow, SIGNAL(showPlaceWindow(cPlace*)), this, SLOT(onShowPlaceWindow(cPlace*))); connect(lpRechercheWindow, SIGNAL(showObjectWindow(cObject*)), this, SLOT(onShowObjectWindow(cObject*))); + connect(lpRechercheWindow, SIGNAL(subWindowClosed(QWidget*)), this, SLOT(onSubWindowClosed(QWidget*))); + lpRechercheWindow->show(); } diff --git a/cmainwindow.h b/cmainwindow.h index 1aed42d..95f5804 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -34,6 +34,8 @@ private slots: void onMainTabTabCloseRequested(int index); void onMdiAreaSubWindowActivated(QMdiSubWindow *arg1); + void onSubWindowClosed(QWidget* lpSubWindow); + void onOutlineDoubleClicked(const QModelIndex& index); void onCharacterDoubleClicked(const QModelIndex& index); void onPlaceDoubleClicked(const QModelIndex& index); diff --git a/cmdisubwindow.cpp b/cmdisubwindow.cpp new file mode 100644 index 0000000..479644c --- /dev/null +++ b/cmdisubwindow.cpp @@ -0,0 +1,14 @@ +#include "cmdisubwindow.h" + +#include + + +cMDISubWindow::cMDISubWindow(QWidget *parent) : QWidget(parent) +{ +} + +void cMDISubWindow::closeEvent(QCloseEvent* event) +{ + emit subWindowClosed(this); + event->accept(); +} diff --git a/cmdisubwindow.h b/cmdisubwindow.h new file mode 100644 index 0000000..7b4da4e --- /dev/null +++ b/cmdisubwindow.h @@ -0,0 +1,23 @@ +#ifndef CMDISUBWINDOW_H +#define CMDISUBWINDOW_H + + +#include + + +class cMDISubWindow : public QWidget +{ + Q_OBJECT +public: + explicit cMDISubWindow(QWidget *parent = nullptr); + +signals: + void subWindowClosed(QWidget* lpWidget); + +public slots: + +protected: + void closeEvent(QCloseEvent *event); +}; + +#endif // CMDISUBWINDOW_H diff --git a/cobjectwindow.cpp b/cobjectwindow.cpp index c0ccc47..cd722e9 100644 --- a/cobjectwindow.cpp +++ b/cobjectwindow.cpp @@ -7,7 +7,7 @@ cObjectWindow::cObjectWindow(QWidget *parent) : - QWidget(parent), + cMDISubWindow(parent), ui(new Ui::cObjectWindow), m_lpObject(0) { diff --git a/cobjectwindow.h b/cobjectwindow.h index a16a279..41b4b58 100644 --- a/cobjectwindow.h +++ b/cobjectwindow.h @@ -4,6 +4,8 @@ #include "cobject.h" +#include "cmdisubwindow.h" + #include #include @@ -12,7 +14,7 @@ namespace Ui { class cObjectWindow; } -class cObjectWindow : public QWidget +class cObjectWindow : public cMDISubWindow { Q_OBJECT diff --git a/cpartwindow.cpp b/cpartwindow.cpp index 6baf440..9b8ff23 100644 --- a/cpartwindow.cpp +++ b/cpartwindow.cpp @@ -5,7 +5,7 @@ cPartWindow::cPartWindow(QWidget *parent) : - QWidget(parent), + cMDISubWindow(parent), ui(new Ui::cPartWindow), m_lpPart(0), m_lpChapterList(0) diff --git a/cpartwindow.h b/cpartwindow.h index 67d4389..1224107 100644 --- a/cpartwindow.h +++ b/cpartwindow.h @@ -5,6 +5,8 @@ #include "cpart.h" #include "cchapter.h" +#include "cmdisubwindow.h" + #include #include @@ -13,7 +15,7 @@ namespace Ui { class cPartWindow; } -class cPartWindow : public QWidget +class cPartWindow : public cMDISubWindow { Q_OBJECT diff --git a/cplacewindow.cpp b/cplacewindow.cpp index b0736e5..900d611 100644 --- a/cplacewindow.cpp +++ b/cplacewindow.cpp @@ -7,7 +7,7 @@ cPlaceWindow::cPlaceWindow(QWidget *parent) : - QWidget(parent), + cMDISubWindow(parent), ui(new Ui::cPlaceWindow), m_lpPlace(0) { diff --git a/cplacewindow.h b/cplacewindow.h index 40a8722..9af7284 100644 --- a/cplacewindow.h +++ b/cplacewindow.h @@ -4,6 +4,8 @@ #include "cplace.h" +#include "cmdisubwindow.h" + #include #include @@ -12,7 +14,7 @@ namespace Ui { class cPlaceWindow; } -class cPlaceWindow : public QWidget +class cPlaceWindow : public cMDISubWindow { Q_OBJECT diff --git a/crecherchewindow.cpp b/crecherchewindow.cpp index c31633a..b3cbe50 100644 --- a/crecherchewindow.cpp +++ b/crecherchewindow.cpp @@ -8,7 +8,7 @@ cRechercheWindow::cRechercheWindow(QWidget *parent) : - QWidget(parent), + cMDISubWindow(parent), ui(new Ui::cRechercheWindow), m_lpRecherche(0) { diff --git a/crecherchewindow.h b/crecherchewindow.h index 6039adc..f33053b 100644 --- a/crecherchewindow.h +++ b/crecherchewindow.h @@ -4,6 +4,8 @@ #include "crecherche.h" +#include "cmdisubwindow.h" + #include #include @@ -12,7 +14,7 @@ namespace Ui { class cRechercheWindow; } -class cRechercheWindow : public QWidget +class cRechercheWindow : public cMDISubWindow { Q_OBJECT diff --git a/cscenewindow.cpp b/cscenewindow.cpp index c0b7684..763884d 100644 --- a/cscenewindow.cpp +++ b/cscenewindow.cpp @@ -5,7 +5,7 @@ cSceneWindow::cSceneWindow(QWidget *parent) : - QWidget(parent), + cMDISubWindow(parent), ui(new Ui::cSceneWindow), m_lpScene(0) { diff --git a/cscenewindow.h b/cscenewindow.h index 5062cec..7df23f0 100644 --- a/cscenewindow.h +++ b/cscenewindow.h @@ -6,6 +6,8 @@ #include "cchapter.h" #include "cscene.h" +#include "cmdisubwindow.h" + #include #include @@ -14,7 +16,7 @@ namespace Ui { class cSceneWindow; } -class cSceneWindow : public QWidget +class cSceneWindow : public cMDISubWindow { Q_OBJECT diff --git a/qtStoryWriter.pro b/qtStoryWriter.pro index 2f0ff54..f4d485d 100644 --- a/qtStoryWriter.pro +++ b/qtStoryWriter.pro @@ -64,7 +64,8 @@ SOURCES += \ cimagewidget.cpp \ cobjectwindow.cpp \ cplacewindow.cpp \ - crecherchewindow.cpp + crecherchewindow.cpp \ + cmdisubwindow.cpp HEADERS += \ cmainwindow.h \ @@ -90,7 +91,8 @@ HEADERS += \ cimagewidget.h \ cobjectwindow.h \ cplacewindow.h \ - crecherchewindow.h + crecherchewindow.h \ + cmdisubwindow.h FORMS += \ cmainwindow.ui \